Closed PManager1 closed 6 years ago
Provide more information please.
Also, usually prefer StackOverflow if you have question related to usage rather than bug/issues.
I don't think this has a option to show the toast if a button is pressed, judging by the source code:
componentWillMount () {
this.showToast()
}
componentWillReceiveProps (nextProps) {
if (this.props.id !== nextProps.id) {
this.showToast()
}
}
showToast () {
const animatedValue = new Animated.Value(0)
this.setState({ animatedValue })
Animated
.timing(animatedValue, { toValue: 1, duration: 350 })
.start()
const { duration, onShow } = this.props
const timeoutId = setTimeout(() => this.hideToast(), duration + 350)
this.setState({ timeoutId }, onShow)
}
It seems like it is set to show on component mount. This looks great but there is no npm installation info or clear instructions on usage.
If you want a toast message to show when you press a button you use your click handler to set some state that'll pass a new message prop to the component.
Something like this:
import React, { Component } from 'react'
import { View, Text } from 'react-native'
import Toaster from 'react-native-toaster'
class App extends Component {
state = { message: null }
onButtonPress = () => this.setState({ message: { text: 'Hello World!' } })
render () {
return (
<View>
<View onPress={this.onButtonPress}>
<Text>Make toast</Text>
</View>
<Toaster message={this.state.message} />
</View>
)
}
}
}