react-native-easy-toast

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

安裝

1.在終端運(yùn)行 npm i react-native-easy-toast --save
2.在要使用Toast的js文件中添加import Toast, {DURATION} from 'react-native-easy-toast'

Demo

Examples

Screenshots
如何使用?

第一步:

在你的js文件中導(dǎo)入 react-native-easy-toast:

import Toast, {DURATION} from 'react-native-easy-toast'

第二步:

將下面代碼插入到render()方法中:

render() {
return (
<View style={styles.container}>
...
<Toast ref="toast"/>
</View>
);
}

注意: 請(qǐng)將<Toast ref="toast"/> 放在最外層View的底部.

第三步:

使用:

this.refs.toast.show('hello world!');

在需要彈出提示框時(shí)使用上面代碼即可。
用例

render() {
        return (
            <View style={styles.container}>
                <TouchableHighlight
                    style={{padding: 10}}
                    onPress={()=>{
                        this.refs.toast.show('hello world!');
                    }}>
                    <Text>Press me</Text>
                </TouchableHighlight>
                <Toast ref="toast"/>
            </View>
        );
    }

自定義 Toast

render() {
        return (
            <View style={styles.container}>
                <TouchableHighlight
                    style={{padding: 10}}
                    onPress={()=>{
                        this.refs.toast.show('hello world!',DURATION.LENGTH_LONG);
                    }}>
                    <Text>Press me</Text>
                </TouchableHighlight>
                <Toast
                    ref="toast"
                    style={{backgroundColor:'red'}}
                    position='top'
                    positionValue={200}
                    fadeInDuration={750}
                    fadeOutDuration={1000}
                    opacity={0.8}
                    textStyle={{color:'red'}}
                />
            </View>
        );
    }

componentDidMount(){
        this.refs.toast.show('網(wǎng)絡(luò)加載中...');
    }
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容