推荐一款React Native轻松实现吐司提示的神器——react-native-easy-toast
    		       		warning:
    		            这篇文章距离上次修改已过444天,其中的内容可能已经有所变动。
    		        
        		                
                
import React, { Component } from 'react';
import { View, Text, StyleSheet } from 'react-native';
import Toast, {DURATION} from 'react-native-easy-toast';
 
export default class App extends Component {
  render() {
    return (
      <View style={styles.container}>
        <Toast ref="toast" position='center' />
        <Text onPress={this.showToast} style={styles.welcome}>
          点击我显示提示
        </Text>
      </View>
    );
  }
 
  showToast = () => {
    this.refs.toast.show('这是一个弹窗提示', DURATION.LENGTH_SHORT);
  }
}
 
const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
});这段代码展示了如何在React Native应用中使用react-native-easy-toast库来添加中间位置的弹窗提示。通过给一个<Text>组件添加onPress事件处理函数,在点击时调用showToast方法来显示Toast。
评论已关闭