Skip to content

Commit aa64f22

Browse files
committed
allow using react component passed on props (then ignores message)
1 parent c2c5fe7 commit aa64f22

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

lib/Toast.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,7 @@ class Toast extends Component {
1414
static durations = durations;
1515

1616
static show = (message, options = {position: positions.BOTTOM, duration: durations.SHORT}) => {
17-
return new RootSiblings(<ToastContainer
18-
{...options}
19-
visible={true}
20-
>
21-
{message}
22-
</ToastContainer>);
17+
return new RootSiblings(<ToastContainer message={message} {...options} visible={true} />);
2318
};
2419

2520
static hide = toast => {

lib/ToastContainer.js

+15-11
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class ToastContainer extends Component {
6464
static propTypes = {
6565
...ViewPropTypes,
6666
containerStyle: ViewPropTypes.style,
67+
message: PropTypes.string,
68+
component: PropTypes.element,
6769
duration: PropTypes.number,
6870
visible: PropTypes.bool,
6971
position: PropTypes.number,
@@ -236,24 +238,26 @@ class ToastContainer extends Component {
236238
style={[
237239
styles.containerStyle,
238240
{ marginHorizontal: windowWidth * ((1 - TOAST_MAX_WIDTH) / 2) },
239-
props.containerStyle,
240241
props.backgroundColor && {backgroundColor: props.backgroundColor},
241-
{
242-
opacity: this.state.opacity
243-
},
242+
props.containerStyle,
243+
{ opacity: this.state.opacity },
244244
props.shadow && styles.shadowStyle,
245245
props.shadowColor && {shadowColor: props.shadowColor}
246246
]}
247247
pointerEvents="none"
248248
ref={ele => this._root = ele}
249249
>
250-
<Text style={[
251-
styles.textStyle,
252-
props.textStyle,
253-
props.textColor && {color: props.textColor}
254-
]}>
255-
{this.props.children}
256-
</Text>
250+
{this.props.component ? (
251+
this.props.component
252+
) : (
253+
<Text style={[
254+
styles.textStyle,
255+
props.textStyle,
256+
props.textColor && {color: props.textColor}
257+
]}>
258+
{this.props.message}
259+
</Text>
260+
)}
257261
</Animated.View>
258262
</TouchableWithoutFeedback>
259263
</View> : null;

0 commit comments

Comments
 (0)