Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
react-native-fast-toast
Advanced tools
[![Version][version-badge]][package] [![MIT License][license-badge]][license]
Readme
Toast component for React Native, supports Android, IOS and Web
Open a Terminal in the project root and run:
yarn add react-native-fast-toast
Wrap your app in the ToastProvider
, which provides context for the Toast hook.
import { ToastProvider } from 'react-native-fast-toast'
export default function App() {
return (
<ToastProvider>
<RestOfYourApp />
<ToastProvider/>
);
}
Then use hook like this everywhere in your app:
import { useToast } from 'react-native-fast-toast'
const Component = () => {
const toast = useToast()
useEffect(() => {
toast.show("Hello World")
}, [])
}
toast.show("Task finished successfully", {
type: 'normal | success | warning | danger | custom',
position: 'top | bottom',
duration: 4000,
offset: 30,
animationType: 'slide-in | zoom-in'
});
let id = Math.random().toString()
toast.show("Loading...", {id})
toast.update(id, "Loading compeleted");
let id = Math.random().toString()
toast.show("Loading...", {id})
toast.hide(id);
// or
toast.hideAll()
ToastContainer
propsThere are lots of props to customize your toast or your can use renderToast to implement your own component.
<ToastContainer
placement="bottom | top"
duration={5000}
animationType='slide-in | zoom-in'
animationDuration={250}
successColor="green"
dangerColor="red"
warningColor="orange"
normalColor="gray"
icon={<Icon />}
successIcon={<SuccessIcon />}
dangerIcon={<DangerIcon />}
warningIcon={<WarningIcon />}
textStyle={{ fontSize: 20 }}
offset={50}
renderToast={(toastOptions) => JSX.Element} implement custom toast component.
/>
You can implement your own custom types or overwrite the existing ones
<ToastContainer
renderType={{
custom_type: (toast) => (
<View style={{padding: 15, backgroundColor: 'grey'}}>
<Text>{toast.message}</Text>
</View>
)
}}
/>
// You can pass other data to your custom toast using data property in show method.
toast.show("Show custom toast", {data: { title: 'Toast title' }})
To call toasts everywhere (even outside of React components like in redux actions), do this in root component of your app (index.js or App.js)
import Toast from "react-native-fast-toast";
export default function App() {
return (
<>
<RestOfYourApp />
<Toast ref={(ref) => global['toast'] = ref} />
</>
);
Now you can call toast.show()
everywhere on app. similar to alert
.
TypeScript Note: add index.d.ts to your project root.
The Modal component is a native view that sits on top of the rest of react-native application. The only way to put something above it is to put something in the modal itself, or alternately to use a JS only implementation of a Modal.
As a workaround you can put toast inside modal like this:
import Toast from "react-native-fast-toast";
export Component = () => {
const toastRef = useRef();
return (
<Modal>
.....
<Toast ref={toastRef} />
</Modal>
}
Pull request are welcome.
While developing, you can run the example app to test your changes.
If this project helped you reduce time to develop, you can buy me a cup of coffee :)
Looking for a React/React-Native Expert? Email at alirezarzna@gmail.com
MIT
FAQs
[![Version][version-badge]][package] [![MIT License][license-badge]][license]
The npm package react-native-fast-toast receives a total of 3,172 weekly downloads. As such, react-native-fast-toast popularity was classified as popular.
We found that react-native-fast-toast demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.