Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kaique292 more customization #12

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 33 additions & 20 deletions components/ToastManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { View, Text, Animated, Dimensions, TouchableOpacity } from 'react-native

import defaultProps from '../utils/defaultProps'
import { Colors } from '../config/theme'
import styles from './styles'
import { styles, customContentStyles } from './styles'

const { height } = Dimensions.get('window')

Expand Down Expand Up @@ -40,23 +40,27 @@ class ToastManager extends Component {
},
}

static info = (text, position) => {
ToastManager.__singletonRef.show(text, Colors.info, 'ios-information-circle', position)
static info = ({ text: text, position: position, icon: icon = 'ios-information-circle', iconColor = Colors.info, textColor: textColor = '#000000', background: background = '#FFFFFF' }) => {
ToastManager.__singletonRef.show(text, iconColor, icon, position, background, textColor)
}

static success = (text, position) => {
ToastManager.__singletonRef.show(text, Colors.success, 'checkmark-circle', position)
static success = ({ text: text, position: position, icon: icon = 'checkmark-circle', iconColor = Colors.success, textColor: textColor = '#000000', background: background = '#FFFFFF' }) => {
ToastManager.__singletonRef.show(text, iconColor, icon, position, background, textColor)
}

static warn = (text, position) => {
ToastManager.__singletonRef.show(text, Colors.warn, 'warning', position)
static warn = ({ text: text, position: position, icon: icon = 'warning', iconColor = Colors.warn, textColor: textColor = '#000000', background: background = '#FFFFFF' }) => {
ToastManager.__singletonRef.show(text, iconColor, icon, position, background, textColor)
}

static error = (text, position) => {
ToastManager.__singletonRef.show(text, Colors.error, 'alert-circle', position)
static error = ({ text: text, position: position, icon: icon = 'alert-circle', iconColor = Colors.error, textColor: textColor = '#000000', background: background = '#FFFFFF' }) => {
ToastManager.__singletonRef.show(text, iconColor, icon, position, background, textColor)
}

show = (text = '', barColor = Colors.default, icon, position) => {
static custom = ({ text: text, position: position, icon: icon = 'alert-circle', iconColor: iconColor = Colors.error, textColor: textColor = '#000000', background: background = '#FFFFFF' }) => {
ToastManager.__singletonRef.show(text, iconColor, icon, position, background, textColor)
}

show = (text = '', barColor = Colors.default, icon, position, background, textColor) => {
const { duration } = this.props
this.state.barWidth.setValue(this.props.width)
this.setState({
Expand All @@ -65,6 +69,8 @@ class ToastManager extends Component {
text,
barColor,
icon,
background,
textColor
})
if (position) this.setState({ position })
this.isShow = true
Expand Down Expand Up @@ -135,16 +141,22 @@ class ToastManager extends Component {
width,
height,
style,
contentStyle,
testID,
theme,
} = this.props

const allContentStyles = { ...customContentStyles, ...contentStyle }

const {
isShow,
animationStyle: stateAnimationStyle,
barColor,
icon,
text,
barWidth,
background,
textColor
} = this.state

return (
Expand All @@ -165,30 +177,31 @@ class ToastManager extends Component {
backdropColor={backdropColor}
backdropOpacity={backdropOpacity}
hasBackdrop={hasBackdrop}
style={styles.modalContainer}
style={[styles.modalContainer, allContentStyles?.modalContainer]}
>
<View
style={[
styles.mainContainer,
allContentStyles?.mainContainer,
{
width,
height,
backgroundColor: Colors[theme].back,
backgroundColor: background,
top: this.position(),
...style,
},
]}
>
<TouchableOpacity onPress={this.hideToast} activeOpacity={0.9} style={styles.hideButton}>
<Icon name='ios-close-outline' size={22} color={Colors[theme].text} />
<TouchableOpacity onPress={this.hideToast} activeOpacity={0.9} style={[styles.hideButton, allContentStyles?.hideButton]}>
<Icon name='ios-close-outline' size={22} color={textColor} />
</TouchableOpacity>
<View style={styles.content}>
<Icon name={icon} size={22} color={barColor} style={styles.iconWrapper} />
<Text style={[styles.textStyle, { color: Colors[theme].text }]}>{text}</Text>
<View style={[styles.content, allContentStyles?.content]}>
<Icon name={icon} size={22} color={barColor} style={[styles.iconWrapper, allContentStyles?.iconWrapper]} />
<Text style={[styles.textStyle, allContentStyles?.textStyle, { color: textColor }]} testID={testID}>{text}</Text>
</View>
<View style={styles.progressBarContainer}>
<View style={[styles.progressBarContainer, allContentStyles?.progressBarContainer]}>
<Animated.View
style={[styles.progressBar, { width: barWidth, backgroundColor: barColor }]}
style={[styles.progressBar, allContentStyles?.progressBar, { width: barWidth, backgroundColor: barColor }]}
/>
</View>
</View>
Expand All @@ -199,4 +212,4 @@ class ToastManager extends Component {

ToastManager.defaultProps = defaultProps

export default ToastManager
export default ToastManager
15 changes: 14 additions & 1 deletion components/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,17 @@ const styles = StyleSheet.create({
}
})

export default styles
const customContentStyles = {
modalContainer: {},
mainContainer: {},
hideButton: {},
textStyle: {},
progressBarContainer: {},
content: {},
iconWrapper: {},
}

export {
styles,
customContentStyles
}