Installations
npm install react-native-root-toast
Releases
Unable to fetch releases
Developer
magicismight
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
Yes
Node Version
NPM Version
Statistics
2,102 Stars
104 Commits
403 Forks
30 Watching
1 Branches
24 Contributors
Updated on 26 Nov 2024
Languages
JavaScript (80.06%)
Objective-C (16.52%)
Java (3.42%)
Total Downloads
Cumulative downloads
Total Downloads
6,368,384
Last day
-4.9%
7,067
Compared to previous day
Last week
-3.2%
35,912
Compared to previous week
Last month
5.1%
161,441
Compared to previous month
Last year
14.2%
1,757,938
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
1
react-native-root-toast
Features
- Pure javascript solution.
- Support both Android and iOS.
- Lots of custom options for Toast.
- You can show/hide Toast by calling api or using Component inside render.
Install
npm install react-native-root-toast
react-native-root-toast >= 2.1.0 only supports react-native >= 0.47.0 , for lower version choose 2.0.0 or below.
In react native >= 0.62, the new LogBox component would impact this component's initialization. To make it work we have to explicitly insert a mount point in your app like this:
1// in your entry file like `App.js` 2 3// In theory you don't have to install `react-native-root-siblings` because it's a dep of root-toast 4// But you can install it explicitly if your editor complains about it. 5import { RootSiblingParent } from 'react-native-root-siblings'; 6 7// in your render function 8return ( 9 <RootSiblingParent> // <- use RootSiblingParent to wrap your root component 10 <App /> 11 </RootSiblingParent> 12); 13
You can skip this step if your react-native is lower than 0.62. And actually you can inject RootSiblingParent into anywhere like a react portal, for example if you have multiple rootviews you can choose where to display the root toast.
Read more about react-native-root-siblings
which powers react-native-root-toast
.
Usage
There are two different ways to manage a Toast.
Calling api
1import Toast from 'react-native-root-toast'; 2 3 4// Add a Toast on screen. 5let toast = Toast.show('This is a message', { 6 duration: Toast.durations.LONG, 7 position: Toast.positions.BOTTOM, 8 shadow: true, 9 animation: true, 10 hideOnPress: true, 11 delay: 0, 12 onShow: () => { 13 // calls on toast\`s appear animation start 14 }, 15 onShown: () => { 16 // calls on toast\`s appear animation end. 17 }, 18 onHide: () => { 19 // calls on toast\`s hide animation start. 20 }, 21 onHidden: () => { 22 // calls on toast\`s hide animation end. 23 } 24}); 25 26// You can manually hide the Toast, or it will automatically disappear after a `duration` ms timeout. 27setTimeout(function () { 28 Toast.hide(toast); 29}, 500); 30
Using a Component
NOTE:
Showing a toast by using a Component inside render, The toast will be automatically disappeared when the <Toast />
is unmounted.
1import React, {Component} from 'react-native'; 2import Toast from 'react-native-root-toast'; 3 4class Example extends Component{ 5 constructor() { 6 super(...arguments); 7 this.state = { 8 visible: false 9 }; 10 } 11 12 componentDidMount() { 13 setTimeout(() => this.setState({ 14 visible: true 15 }), 2000); // show toast after 2s 16 17 setTimeout(() => this.setState({ 18 visible: false 19 }), 5000); // hide toast after 5s 20 }; 21 22 render() { 23 return <Toast 24 visible={this.state.visible} 25 position={50} 26 shadow={false} 27 animation={false} 28 hideOnPress={true} 29 >This is a message</Toast>; 30 } 31} 32
Reference
Props
Name | Default | Type | Description |
---|---|---|---|
duration | Toast.durations.SHORT | Number | The duration of the toast. (Only for api calling method) |
visible | false | Bool | The visibility of toast. (Only for Toast Component) |
position | Toast.positions.BOTTOM | Number | The position of toast showing on screen (A negative number represents the distance from the bottom of screen. A positive number represents the distance form the top of screen. 0 will position the toast to the middle of screen.) |
animation | true | Bool | Should preform an animation on toast appearing or disappearing. |
shadow | true | Bool | Should drop shadow around Toast element. |
backgroundColor | null | String | The background color of the toast. |
shadowColor | null | String | The shadow color of the toast. |
textColor | null | String | The text color of the toast. |
delay | 0 | Number | The delay duration before toast start appearing on screen. |
hideOnPress | true | Bool | Should hide toast that appears by pressing on the toast. |
opacity | 0.8 | Number | The Toast opacity. |
onShow | null | Function | Callback for toast`s appear animation start |
onShown | null | Function | Callback for toast`s appear animation end |
onHide | null | Function | Callback for toast`s hide animation start |
onHidden | null | Function | Callback for toast`s hide animation end |
Constants
Toast.durations
presets of duration of the toast.
-
Toast.durations.SHORT (equals to 2000)
-
Toast.durations.LONG (equals to 3500)
Toast.positions
presets of position of toast.
-
Toast.positions.TOP (equals to 20)
-
Toast.positions.BOTTOM (equals to -20)
-
Toast.positions.CENTER (equals to 0)
No vulnerabilities found.
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE.txt:0
- Info: FSF or OSI recognized license: MIT License: LICENSE.txt:0
Reason
binaries present in source code
Details
- Warn: binary detected: Example/android/gradle/wrapper/gradle-wrapper.jar:1
Reason
Found 10/22 approved changesets -- score normalized to 4
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 18 are checked with a SAST tool
Score
3.4
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to react-native-root-toast
react-native-toast-message
Toast message component for React Native
toastify-react-native
🎉 toastify-react-native allows you to add notifications to your react-native app (ios, android) with ease. No more nonsense!
react-native-toast-notifications
[![Version][version-badge]][package] [![MIT License][license-badge]][license]
react-native-simple-toast
Cross-platform Toast experience for React Native