react-native-easy-toast icon indicating copy to clipboard operation
react-native-easy-toast copied to clipboard

简便 使用方法

Open StarksJohn opened this issue 9 years ago • 1 comments

如果 您 不想 在 每次 都在要 显示 toast 的控件 的 render 方法里 画 控件, 可 把 这句 画在 你的 根控件的 render方法里 ,比如

  <View style={styles.container}>
                <StatusBar translucent={false} backgroundColor={Colors.blue}/>
                <Navigator
                    ref={component => this.navigator = component}
                    initialRoute={
                    {
                        component: RootPagesContainer
                    }
                    }
                    configureScene={this.handlerConfigureScene}
                    renderScene={this.renderScene}
                />
                <Toast ref="toastWithStyle" style={{backgroundColor: Colors.appUnifiedBackColor /*, opacity: 0.8*/ }}
                       textStyle={{
                           fontSize: 20,
                           color: Colors.white,fontWeight:'bold'
                       }} position={'center'}/>
            </View>

然后 在这个根控件监听 一个 showToast事件, 如

componentDidMount() {
this.listener = DeviceEventEmitter.addListener('showToast', (text) => {
this.refs.toastWithStyle.show(text, DURATION.LENGTH_LONG);
});
}

componentWillUnmount() {
    if (this.listener) {
        this.listener.remove();
    }
}

这样在任何地方 都可以调 DeviceEventEmitter.emit('showToast', showMsg);发一个 通知,根控件上就会画这个 toast 控件了

StarksJohn avatar Nov 18 '16 09:11 StarksJohn

这个有点牛逼呀

jiekesiji avatar Jul 30 '17 09:07 jiekesiji