0.4.2 ā€¢ Published 2 months ago

react-native-toastable v0.4.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

react-native-toastable

npm npm bundle size HitCount

šŸž Blazingly fast and fully customizable Toaster component for React Native

  • Supports queuinge, so you can display multiple toasts in succession without having to worry about them overlapping or interfering with each other
  • Fully typed, using TypeScript
  • Supports swipe to dismiss multiple directions (left, right, up)
  • Performant, using native animations and avoiding unnecessary re-renders
  • Zero external dependencies
  • Highly customizable, allowing you to tailor it to fit your specific needs

https://user-images.githubusercontent.com/43743872/230865010-6c1c7890-2eec-47c1-bbe4-44c6c6379037.mp4

Installation

yarn add react-native-toastable

or

npm install react-native-toastable

Usage

Place Toastable component at the root of your app, and import showToastable function anywhere in your app to show or hideToastable to hide toast.

Note: If you need to use top inset of the device, Toastable must be child of SafeAreaProvider, otherwise you can use any value for offset prop, default is 56.

import { View } from 'react-native';
import { useSafeAreaInsets, SafeAreaProvider } from 'react-native-safe-area-context';
import Toastable from 'react-native-toastable';

export default function App() {
    return (
        <SafeAreaProvider>
            <RootNavigation />
        </SafeAreaProvider>
    );
}

export default function RootNavigation() {
    const { top } = useSafeAreaInsets();

    return (
        <View style={{ flex:1 }}>
            <NavigationContainer />
            <Toastable
                statusMap={{
                    success: 'red'
                    danger: 'yellow'
                    warning: 'green'
                    info: 'blue'
                }}
                offset={top}
            />
        </View>
    );
}

import { View, Button } from 'react-native';
import { hideToastable, showToastable } from 'react-native-toastable';

export default function HomeScreen() {
    return (
        <View style={{flex:1}}>
            <Button
                title="Show Toastable"
                onPress={() => showToastable({ message: 'React Native Heroes is awesome! šŸš€', status:'success' })}
            />
            <Button
                title="Hide Toastable"
                onPress={() => hideToastable()}
            />
        </View>
    );
}

Props

Inherit all other props from ToastableBodyParams interface. Except backgroundColor, status, message, onPress, contentStyle props.

PropertyTypeDescriptionDefault
statusMapStatusMapStatus map, used to determine background color based on statussuccess: '#00BFA6', danger: '#FF5252', warning: '#FFD600', info: '#2962FF'
onToastableHideFuncCallback when toast is dismissedundefined
containerStyleViewProps['style']Container style for toast containerundefined
position'top' \| 'center'Toast position.'top'
offsetnumberToast offset.56

ToastableBodyParams

ParamsTypeDescriptionDefault
renderContent(props: ToastableBodyParams) => React.ReactNodeRender custom content, if this is set, message will be ignored.undefined
contentStyleViewProps['style']Custom content style.undefined
backgroundColorColorValueCustom background color, if this is set, status will be ignored.undefined
statusToastableMessageStatusMessage status, this will be used to determine background color based on statusMap prop.'info'
messageTextProps['children']Message to be displayed.undefined
onPressFuncOn press callback.undefined
durationnumberDuration in milliseconds.3000
alwaysVisiblebooleanMake toast always visible, even when there is a new toast.false
animationOutTimingnumberAnimation timing for toast out in milliseconds.300
animationInTimingnumberAnimation timing for toast in in milliseconds.300
swipeDirection'up' \| 'left' \| 'right' \| Array<'up' \| 'left' \| 'right'>Swipe direction to dismiss toast.'up'
titleColorColorValueCustom title color, if this is set.'#FFFFFF'
messageColorColorValueCustom message color, if this is set.'#FFFFFF'
titleStyleTextStyleCustom title style.undefined
messageStyleTextStyleCustom message style.undefined
position'top' \| 'bottom'\| 'center'Toast position.'top'
offsetnumberToast offset.56

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

Roadmap

  • Add more examples
  • Support animationIn and animationOut props
  • Support stackable toasts
  • Support custom animations
  • Add custom status support

Inspiration

License

MIT


Made with create-react-native-library

0.4.2

2 months ago

0.4.1

4 months ago

0.4.0

5 months ago

0.3.0

5 months ago

0.2.1

1 year ago

0.2.0

1 year ago