Template version: v0.2.2
react-native-simple-toast
[!TIP] Github address
Find the matching version information in the release address of a third-party library: @react-native-oh-tpl/react-native-simple-toast Releases.For older versions that are not published to npm, please refer to the installation guide to install the tgz package.
Go to the project directory and execute the following instruction:
npm install @react-native-oh-tpl/react-native-simple-toast
yarn add @react-native-oh-tpl/react-native-simple-toast
The following code shows the basic use scenario of the repository:
[!WARNING] The name of the imported repository remains unchanged.
import * as React from 'react';
import {
StyleSheet,
View,
Button,
Alert,
TextInput,
ScrollView,
Pressable,
Modal,
Text,
} from 'react-native';
import Toast from 'react-native-simple-toast';
import { useState } from 'react';
const ToastTest = () => {
const [modalVisible, setModalVisible] = useState(false);
return (
<>
<Modal
animationType="slide"
transparent={true}
visible={modalVisible}
onRequestClose={() => {
Alert.alert('Modal has been closed.');
setModalVisible(!modalVisible);
}}
>
<View style={styles.centeredView}>
<View style={styles.modalView}>
<Text style={styles.modalText}>Hello World!</Text>
<Pressable
style={[styles.button, styles.buttonClose]}
onPress={() => setModalVisible(!modalVisible)}
>
<Text style={styles.textStyle}>Hide Modal</Text>
</Pressable>
</View>
</View>
</Modal>
<ScrollView
contentContainerStyle={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}
keyboardDismissMode={'on-drag'}
keyboardShouldPersistTaps={'always'}
automaticallyAdjustKeyboardInsets
style={{ backgroundColor: 'white' }}
>
<View style={styles.container}>
<Button
title={'simple toast'}
color={'#2196F3'}
onPress={() => {
Toast.show('This is a toast.', Toast.SHORT);
}}
/>
<View style={{ height: 20 }} />
<Button
title={'tap to dismiss toast'}
color={'#f44336'}
onPress={() => {
Toast.show('Tap to dismiss toast.', Toast.LONG, {
tapToDismissEnabled: true,
});
}}
/>
</View>
</ScrollView>
</>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
padding: 16,
backgroundColor: '#fff',
},
centeredView: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'rgba(0,0,0,0.3)',
},
modalView: {
margin: 20,
backgroundColor: 'white',
borderRadius: 8,
padding: 32,
alignItems: 'center',
shadowColor: '#000',
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.25,
shadowRadius: 4,
elevation: 5,
},
modalText: {
marginBottom: 16,
textAlign: 'center',
fontSize: 18,
color: '#333',
},
button: {
borderRadius: 8,
paddingVertical: 10,
paddingHorizontal: 20,
elevation: 2,
backgroundColor: '#2196F3',
},
buttonClose: {
backgroundColor: '#f44336',
marginTop: 12,
},
textStyle: {
color: 'white',
fontWeight: 'bold',
textAlign: 'center',
},
});
export default ToastTest;
To use this repository, you need to use the correct React-Native and RNOH versions. In addition, you need to use DevEco Studio and the ROM on your phone.
This document is verified based on the following versions:
[!TIP] The Platform column indicates the platform where the properties are supported in the original third-party library.
[!TIP] If the value of HarmonyOS Support is yes, it means that the HarmonyOS platform supports this property; no means the opposite; partially means some capabilities of this property are supported. The usage method is the same on different platforms and the effect is the same as that of iOS or Android.
Name | Description | Required | Platform | HarmonyOS Support |
---|---|---|---|---|
show(message, duration, options) | show toast | No | All | partially |
showWithGravity(message, duration, gravity, options) | Toast that can be set to top, bottom, and center positions. | No | All | No |
showWithGravityAndOffset(message,duration,gravity,xOffset,yOffset,options,); | Toast that can be set with x-axis and y-axis offsets. | No | All | No |
[!TIP] The Platform column indicates the platform where the properties are supported in the original third-party library.
[!TIP] If the value of HarmonyOS Support is yes, it means that the HarmonyOS platform supports this property; no means the opposite; partially means some capabilities of this property are supported. The usage method is the same on different platforms and the effect is the same as that of iOS or Android.
Name | Description | Type | Required | HarmonyOS Support |
---|---|---|---|---|
LONG | Toast Display Duration: LONG | number | / | yes |
SHORT | Toast Display Duration: SHORT | number | / | yes |
TOP | Toast Display Position:TOP | number | / | no |
BOTTOM | Toast Display Position: BOTTOM | number | / | no |
CENTER | Toast Display Position: CENTER | number | / | no |
This project is licensed under The MIT License (MIT).
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。