【发布时间】:2019-09-17 06:41:14
【问题描述】:
我是本机反应的新手,我正在构建一个应用程序,该应用程序将使用指纹对用户进行身份验证,如果成功,将通过警报消息上显示的按钮导航到下一个屏幕。但我无法导航。 我收到警报消息弹出窗口以及弹出窗口上的按钮。但是按钮功能 (Alert.alert('Authenticated Successfully','', [{text: 'Proceed', onPress:() => this.props.navigation.navigate('Main')} ] )) 没有按预期工作。
这里是特定屏幕的代码sn-p:-
import React, { Component } from 'react';
import { View, Text, StyleSheet, TouchableOpacity, ImageBackground, Alert } from 'react-native';
import TouchID from 'react-native-touch-id';
export default class FingerPrintScreen extends React.Component {
render() {
return (
<ImageBackground style={{ flex: 1, width: null, height: null, resizeMode: 'cover'}} source={{ uri: 'https://jooinn.com/images/white-clouds-25.jpg' }}>
<View style={stylesLogin.LoginScreenView}>
<Text style={{ textAlign: 'center', top: '10%', fontFamily: 'Arial', fontSize: 30, color: '#0143B8', fontWeight: 'bold'}}>Authenticate using Fingerprint.</Text>
<TouchableOpacity activeOpacity={0.55} style={ stylesLogin.HomeButton } onPress={() => this.props.navigation.popToTop('Home')}>
<Text style={{ textAlign:'center', fontFamily: 'Arial', fontSize: 30, color: '#FFFFFF', fontWeight: 'bold'}}>Go to Home</Text>
</TouchableOpacity>
<TouchableOpacity activeOpacity={0.55} style={stylesLogin.FingerPrintButton} onPress={this.clickHandler}>
<Text style={{ textAlign: 'center', fontFamily: 'Arial', fontSize: 30, color: '#FFFFFF', fontWeight: 'bold' }}>Click Here to Authenticate using Fingerprint</Text>
</TouchableOpacity>
</View>
</ImageBackground>
);
}
clickHandler() {
TouchID.isSupported()
.then( authenticate() )
.catch( error => {
Alert.alert( 'Biometric not supported' )
})
}
}
function authenticate() {
return TouchID.authenticate()
.then( success => {
Alert.alert('Authenticated Successfully',' Click Proceed to Continue', [{text: 'Proceed', onPress:() => this.props.navigation.navigate('Main')}] )
})
.catch(error => {
Alert.alert(error.message);
})
}
我无法这样做,因为身份验证功能位于组件之外。 谢谢你
【问题讨论】:
标签: react-native authentication alert touch-id