【搭建react-native项目框架】6.Toast吐司,消息提示

在移动端,Toast方式提示消息更为普遍。


1.安装插件react-native-easy-toast

github地址:https://github.com/crazycodeboy/react-native-easy-toast

中文文档:https://github.com/crazycodeboy/react-native-easy-toast/blob/master/README.zh.md

$ npm install react-native-easy-toast --save
2.引入react-native-easy-toast
import Toast from 'react-native-easy-toast';
3.在最外层View底部渲染Toast
            <View style={[{flex: 1}]}>
                {/*<Router sceneStyle={[styles.router]}>*/}
                    {/*......*/}
                {/*</Router>*/}
                {/*<PlayButton />*/}
                <Toast ref="toast" opacity={0.8}/>
                {/*<Loading ref={r=>{this.Loading = r}} hide = {true} />*/}
            </View>
4.定义全局toast方法
let self; //将App组件中的this赋给全局的self

global.toast = false; //所有子页面均可直接调用global.toast("")来吐司提示消息
5.给全局方法赋值
    componentDidMount() {
        self = this;
        global.toast = function(message) {
            self.refs.toast.show(message);
        };
    }
6.调用
global.toast('这是消息提示');


猜你喜欢

转载自blog.csdn.net/danding_ge/article/details/80493780
今日推荐