加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ReactNative开发——系统弹出框

发布时间:2020-12-15 07:19:07 所属栏目:百科 来源:网络整理
导读:ReactNative开发——系统弹出框 导入Alter组件 import {Alert} from 'react-native' 使用Alert Alert.alert( "弹出框标题提示语" , "弹出框正文提示语" ,[ {text: 'ask me later' },{text: '取消' ,onPress: this .userCanceled},{text: '确定' ,onPress: th

ReactNative开发——系统弹出框

导入Alter组件

import {Alert} from 'react-native'

使用Alert

Alert.alert(
    "弹出框标题提示语","弹出框正文提示语",[
        {text: 'ask me later'},{text: '取消',onPress: this.userCanceled},{text: '确定',onPress: this.userConfirmed}
    ],{cancelable: true}
);

相信大家可以直接看懂,其中 this.userCanceled 和 this.userCanceled 是我当前组件定义的方法。

userConfirmed() {
    this.setState((state) => {
        return {needToConfirm: false};
    });

    //跳转页面
    this.props.navigation.navigate('Waiting',{
        phoneNumber: this.state.inputedNum,userPw: this.state.inputedPW,});
}

userCanceled() {
    this.setState((state) => {
        return {needToConfirm: false};
    });
}

注意

如果我们的对调方法,有调用 this.setState 来更新自身的话,可能会有错,因为调用时候的 this,已经不指向我们的组件。所以我们最好在自己组件的构造方法中bind 一下自身的this。

例如:

export default class Register extends Component {

    static navigationOptions = {
        title: '注册页面'
    }

    constructor(props) {
        super(props);
        this.userConfirmed = this.userConfirmed.bind(this);
        this.userCanceled = this.userCanceled.bind(this);
    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读