Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/439.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在警报不工作时对本机导航器作出反应_Javascript_Android_Reactjs_React Native - Fatal编程技术网

Javascript 在警报不工作时对本机导航器作出反应

Javascript 在警报不工作时对本机导航器作出反应,javascript,android,reactjs,react-native,Javascript,Android,Reactjs,React Native,我正在尝试构建一个测试登录页面。在此页面中,如果用户按“登录”按钮 按钮,则应用程序应显示警报对话框。如果用户仅在对话框中选择“是”,则应用程序应导航到下一页 问题 当我在点击'YES'按钮的事件时调用navigator,则什么都没有发生。我在分享我的课程我错过了什么?然而,如果我从按钮点击调用它,它可以正常工作,没有任何问题 代码片段 import Style from '../Style'; import React, { Component } from 'react'; import {

我正在尝试构建一个测试登录页面。在此页面中,如果用户按“登录”按钮 按钮,则应用程序应显示警报对话框。如果用户仅在对话框中选择“是”,则应用程序应导航到下一页

问题

当我在点击
'YES'
按钮的事件时调用navigator,则什么都没有发生。我在分享我的课程我错过了什么?然而,如果我从按钮点击调用它,它可以正常工作,没有任何问题

代码片段

import Style from '../Style';
import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,TextInput,Alert,
  Navigator,
  TouchableOpacity,
  View,Linking ,ToastAndroid,
  ScrollView
} from 'react-native';

export default class Login extends Component {

  constructor(props) {
   super(props);
   this.state = { text: 'Search Movies' };
   this.goToHome = this.goToHome.bind(this);
 }

    goToHome() {
    ToastAndroid.show('A pikachu appeared nearby !', ToastAndroid.SHORT);
     this.props.navigator.push({
        name: 'Home',
        title: 'Home',
        openMenu: this.openMenu
     });
  }

  showConfirmationDialog(){
          Alert.alert(
                'FingerPrint Authentication',
                'Would you like to authenticate using fingerprint ?',
                [
                  {text: 'Yes', onPress: () => {ToastAndroid.showWithGravity('Ticket Booked :D',ToastAndroid.SHORT, ToastAndroid.CENTER);}},
                  {text: 'No', onPress: () => { this.goToHome}},
                  {text: 'Cancel', onPress: () =>console.log('Cancelled'), style: 'cancel'},
                ],
                  { cancelable: false }
                  )
                }

  render() {

    return (

      <View style={Style.container}>
      <ScrollView style={Style.plot}>

              <Text style={Style.welcome}>
                 Sign In
                </Text>

               <View style={Style.settings}/>

               <Text style={Style.label}>
              User Name
               </Text>

              <TextInput
                 style={Style.input}
                 onChangeText={(text) => this.setState({text})}
                 value={this.state.text}
               />

               <Text style={Style.label}>
              Password
               </Text>

              <TextInput
                 style={Style.input}
                 onChangeText={(text) => this.setState({text})}
                 value={this.state.text}
               />

       <View style={Style.buttonContainer}>
         <TouchableOpacity
           onPress= { this.showConfirmationDialog}
           activeOpacity={0.7}
           style={Style.buttonClose}>
           <Text style={Style.buttonText}>Login</Text>
         </TouchableOpacity>
       </View>

    </ScrollView>
    </View>
    );
  }
}

AppRegistry.registerComponent('Login', () => Login);
从“../Style”导入样式;
从“React”导入React,{Component};
进口{
评估学,
样式表,
文本,文本输入,警报,
领航员,
可触摸不透明度,
视图、链接、ToastAndroid、,
卷轴视图
}从“反应本机”;
导出默认类登录扩展组件{
建造师(道具){
超级(道具);
this.state={text:'搜索电影'};
this.goToHome=this.goToHome.bind(this);
}
goToHome(){
ToastAndroid.show(‘附近出现了一个皮卡丘!’,ToastAndroid.SHORT);
这个是.props.navigator.push({
姓名:'家',
标题:"家",,
openMenu:this.openMenu
});
}
显示确认对话框(){
警惕,警惕(
“指纹认证”,
'是否要使用指纹进行身份验证?',
[
{文本:'Yes',按:()=>{ToastAndroid.show with gravity('订票:D',ToastAndroid.SHORT,ToastAndroid.CENTER);},
{text:'No',onPress:()=>{this.goToHome}},
{text:'Cancel',onPress:()=>console.log('Cancelled'),style:'Cancel'},
],
{可取消:false}
)
}
render(){
返回(
登录
用户名
this.setState({text})}
值={this.state.text}
/>
密码
this.setState({text})}
值={this.state.text}
/>
登录
);
}
}
注册表组件('Login',()=>Login);

如果我在登录按钮中将
onPress={this.showConfirmationDialog}
更改为
onPress={this.goToHome}
,它可以工作,但不能在对话框的OK按钮上工作。

绑定showConfirmationDialog有帮助吗?在“否”文本中,按下按钮是否有效。?绑定showConfirmationDialog没有帮助;“否”按钮显示祝酒词,但“是”按钮上没有任何动作。好的,然后你必须尝试将“是”按钮代码放入函数中,然后在“是”按钮上调用函数,这可能会帮你从错误中解脱出来。