react-native-toaster
Simple top-pop toast feedback messages for React Native.
Example
{ superprops thisstate = message: null const messages =
text: 'FYI' text: 'Hooray!' styles: ToastStylessuccess text: 'Eek' styles: ToastStyleswarning text: 'Oh noe!' styles: ToastStyleserror // Send each message 1 second apart messages } { return <View> <Toaster message=thisstatemessage /> </View> }
Default Description Properties
object
/
array
The current toast message to display (
see below
). Multiple messages are shown one at a time after each other.
onShow
Callback called when a message is shown, passed the message as the first parameter
onHide
Callback called when a message is hidden, passed the message as the first parameter
onPress
Callback called when the user press a message, passed the message as the first parameter
message
Default
Description
The
text
property can be either a simple string or a custom element to be rendered. If a string is passed, it is wrapped in a container
View
and
Text
element:
text = <View> <Text>text</Text> </View>
Both the container
View
and
Text
element can be styled using the
styles
property.
styles
An object used to style the container
View
and
Text
elements when
message.text
is a
string
. Defaults to
ToastStyles.info
if not set and should look like this:
container: backgroundColor: '#2487DB' paddingTop: 25 paddingRight: 15 paddingBottom: 15 paddingLeft: 15 text: color: '#ffffff' fontWeight: 'bold'
Example with Redux
App.jsx
{ return <View> <Toaster message=thispropstoastMessage /> <LoginForm /> </View> } const mapStateToProps = toastMessage mapStateToPropsApp
LoginForm.jsx
state = email: '' password: '' this this { const email password = thisstate // TODO: Send to server, on response call addToast: thisprops
// --- or --- thisprops } { return <View> <TextInput onChangeText=thisonEmailChange value=thisstateemail placeholder='Email' /> <TextInput onChangeText=thisonPasswordChange value=thisstatepassword placeholder='Password' /> <TouchableHighlight onPress=thisonLoginButtonPress> <Text>Login</Text> </TouchableHighlight> </View> } const mapDispatchToProps = addToast null mapDispatchToPropsLoginForm
redux/actions.js
const ADD_TOAST = 'ADD_TOAST' { return type: ADD_TOAST message }
redux/reducers.js
{ } appState toastMessage state
Contribute
Feel free to dive in! Open an issue or submit PRs.
License
ISC © TABLEFLIP