简体   繁体   English

反应本机元素检测

[英]react-native Native element detection

I want in my react-native app detect if user have a touch ID sensor or not and then if he have I want to display button with native element action instead of just normal action button. 我想在我的本机应用程序中检测用户是否有触摸ID传感器,然后如果他有,我想显示具有本机元素操作的按钮,而不仅仅是普通操作按钮。 When I created if statement it shows me an error. 当我创建if语句时,它显示了一个错误。 I'm using 'create-react-native-app' with expo client SDK. 我在博览会客户端SDK中使用“ create-react-native-app”。

error message 错误信息

在此处输入图片说明

Code

class LoginButton extends React.Component {
    state = {
        waiting: false,
    };

    render() {
        let authFunction;
        if (NativeModules.ExponentFingerprint.hasHardwareAsync() === true) {
            if (Platform.OS === 'android') {
                authFunction = async () => {
                    this.setState({waiting: true});
                    try {
                        let result = await NativeModules.ExponentFingerprint.authenticateAsync();
                        if (result.success) {
                            alert('Udało Ci się zalogować')
                        } else {
                            alert('Logowanie nie udane')
                        }
                    }
                    finally {
                        this.setState({waiting: false})
                    }
                };
            } else if (Platform.OS === 'ios') {
                authFunction = async () => {
                    let result = await NativeModules.ExponentFingerprint.authenticateAsync(
                        'Zaloguj się przy użyciu TouchID'
                    );
                    if (result.success) {
                        alert('Udało Ci się zalogować')
                    } else {
                        alert('Logowanie nie udane')
                    }
                };
            }
            return (
                <Button onPress={authFunction} title="Zaloguj się przy użyciu odcisku palca" style={styles.buttonStyle}>
                    {this.state.waiting
                        ? 'Czekam na TouchID...'
                        : 'Zalogowano przy użyciu TouchID'}
                </Button>
            )

        } else if (NativeModules.ExponentFingerprint.hasHardwareAsync() === false) {
            return (
                <Button onPress={} title="Zaloguj się" style={styles.buttonStyle}/>
            )
        }
    }
}

The issue is here 问题在这里

<Button
  onPress={} <--- here
  title="Zaloguj się" 
  style={styles.buttonStyle}
/>

React doesn't allow you to assign empty expressions to JSX attributes. React不允许您将空表达式分配给JSX属性。

In order to fix it, just remove it 为了修复它,只需将其删除

<Button title="Zaloguj się" style={styles.buttonStyle}/>

or assign it, for example, to authFunction which will be null. 或将其分配给例如authFunction ,它将为null。

<Button onPress={authFunction} title="Zaloguj się" style={styles.buttonStyle}/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM