Skip to content

Commit

Permalink
allow using react component passed on props (then ignores message)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivnnv committed Oct 24, 2019
1 parent c2c5fe7 commit aa64f22
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
7 changes: 1 addition & 6 deletions lib/Toast.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ class Toast extends Component {
static durations = durations;

static show = (message, options = {position: positions.BOTTOM, duration: durations.SHORT}) => {
return new RootSiblings(<ToastContainer
{...options}
visible={true}
>
{message}
</ToastContainer>);
return new RootSiblings(<ToastContainer message={message} {...options} visible={true} />);
};

static hide = toast => {
Expand Down
26 changes: 15 additions & 11 deletions lib/ToastContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class ToastContainer extends Component {
static propTypes = {
...ViewPropTypes,
containerStyle: ViewPropTypes.style,
message: PropTypes.string,
component: PropTypes.element,
duration: PropTypes.number,
visible: PropTypes.bool,
position: PropTypes.number,
Expand Down Expand Up @@ -236,24 +238,26 @@ class ToastContainer extends Component {
style={[
styles.containerStyle,
{ marginHorizontal: windowWidth * ((1 - TOAST_MAX_WIDTH) / 2) },
props.containerStyle,
props.backgroundColor && {backgroundColor: props.backgroundColor},
{
opacity: this.state.opacity
},
props.containerStyle,
{ opacity: this.state.opacity },
props.shadow && styles.shadowStyle,
props.shadowColor && {shadowColor: props.shadowColor}
]}
pointerEvents="none"
ref={ele => this._root = ele}
>
<Text style={[
styles.textStyle,
props.textStyle,
props.textColor && {color: props.textColor}
]}>
{this.props.children}
</Text>
{this.props.component ? (
this.props.component
) : (
<Text style={[
styles.textStyle,
props.textStyle,
props.textColor && {color: props.textColor}
]}>
{this.props.message}
</Text>
)}
</Animated.View>
</TouchableWithoutFeedback>
</View> : null;
Expand Down

0 comments on commit aa64f22

Please sign in to comment.