xxxxxxxxxx
import {ToastAndroid} from 'react-native' ;
.
ToastAndroid.showWithGravity(
"All Your Base Are Belong To Us",
ToastAndroid.SHORT,
ToastAndroid.CENTER
);
.
xxxxxxxxxx
import { ToastAndroid, Platform, AlertIOS} from 'react-native';
function notifyMessage(msg: string) {
if (Platform.OS === 'android') {
ToastAndroid.show(msg, ToastAndroid.SHORT)
} else {
AlertIOS.alert(msg);
}
}
xxxxxxxxxx
import React from 'react';
import { View, StyleSheet, ToastAndroid, Button, StatusBar } from 'react-native';
export default function App() {
function showToast() {
ToastAndroid.show('Request sent successfully!', ToastAndroid.SHORT);
}
return (
<View style={styles.container}>
<Button title="Show Toast" onPress={showToast} />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
paddingTop: StatusBar.currentHeight,
backgroundColor: '#6638f0',
padding: 8,
},
});
xxxxxxxxxx
import Toast, {BaseToast, ErrorToast} from 'react-native-toast-message';
export const showToast = (text1: string, text2: string, type: boolean) => {
Toast.show({text1: text1, text2: text2, type: type ? 'success' : 'error'});
};
Usage
showToast('Error', 'The post no longer exists.', true);
xxxxxxxxxx
npm install react-native-simple-toast --save
react-native link react-native-simple-toast // only RN < 0.60
cd ios && pod install