NativeBase Toast can be used to display quick warning or error messages.
For Toast to work, you need to wrap your topmost component inside <Root> from native-base.
Replacing Component: React Native View.
Contents:
Syntax
{% codetabs name="React Native", type="js" -%} import { Root } from "native-base"; import { StackNavigator } from "react-navigation"; const AppNavigator = StackNavigator( { Page: { screen: Page }, } ); export default () => ; {%- language name="Vue Native", type="vue" -%}
<script> import { Root } from "native-base"; import { StackNavigator } from "vue-native-router"; const AppNavigation = StackNavigator( { Page: { screen: Page }, } ); export default { components: { Root, AppNavigation } }; </script>{%- endcodetabs %}
{% codetabs name="React Native", type="js" -%} import React, { Component } from 'react'; import { Container, Header, Content, Toast, Button, Text } from 'native-base'; export default class ToastExample extends Component { render() { return (
<Button onPress={()=> Toast.show({ text: 'Wrong password!', buttonText: 'Okay' })}> Toast ); } } {%- language name="Vue Native", type="vue" -%} Toast <script> import React from "react"; import { Toast } from "native-base"; export default { methods: { handleBtnPress: function() { Toast.show({ text: "Wrong password!", buttonText: "Okay" }); } } }; </script>{%- endcodetabs %}
Configuration
| Key | Value | Option | Description |
|---|---|---|---|
| text | - | string | Text content to be shown in the toast |
| textStyle | - | - | Style text content for toast |
| buttonText | - | string, blank | Text to be displayed inside the button |
| buttonTextStyle | - | - | Style button text for toast |
| buttonStyle | - | - | Style button for toast |
| position | bottom | top, bottom | Sets position for the toast |
| type | - | danger, success, warning | Sets context to the Toast |
| duration | 1500 | user defined (integer) | Milliseconds after which Toast disappears |
| onClose(reason) | - | function | Called just before the toast hides. reason can be "user" when the user click on the button; "timeout" when timeout. |
| show() | - | function | Displays the Toast |
| hide() | - | function | Hides the Toast |
| style | - | style object | Style for the Toast |

