Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Toast alert in Android & IOS creat react native expo

I am creating an APP using managed expo react native.

And want to implement Toast alerts, react-native provides Toast only for Android not for IOS.

I googled it and found the couple of modules which works on Android and ios but they required some config change in Native code. But as I said I am working on Managed expo app. So, I don't have access for that.

Now let me know how I can implement Toast on this?

Thanks.

like image 658
Saurabh Sharma Avatar asked May 16 '20 18:05

Saurabh Sharma


2 Answers

As toast is a native feature in android, for ios try snakbar.

import {
    ToastAndroid,
    Platform
} from "react-native";
import Snackbar from 'react-native-snackbar';

notify = (message) => {
    if (Platform.OS != 'android') {
        Snackbar.show({
            text: message,
            duration: Snackbar.LENGTH_SHORT,
        });
    } else {
        ToastAndroid.show(message, ToastAndroid.SHORT);
    }
}

** If you are on expo https://snack.expo.io/@mainak/snackbar

like image 100
mainak Avatar answered Nov 15 '22 12:11

mainak


You can use third-party library native-base available for both react-native-cli and expo

[Native-Base] https://docs.nativebase.io/docs/GetStarted.html

[Toast Component] https://docs.nativebase.io/Components.html#toast-def-headref

like image 23
Awais Rana Avatar answered Nov 15 '22 10:11

Awais Rana