2017-07-27 29 views
0

我想在我的react-native应用程序中检测用户是否有触摸ID传感器,然后如果他有我想用本地元素操作而不是仅显示正常操作按钮显示按钮。当我创建if语句时,它向我显示一个错误。我正在使用expo客户端SDK的'create-react-native-app'。react-native本机元素检测

错误信息

enter image description here

代码

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}/> 
      ) 
     } 
    } 
} 

回答

1

的问题是在这里

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

阵营不允许您将空表达式分配给JSX属性。

为了解决它,只是将其删除

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

或将其指定,例如,到authFunction这将是空的。

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