Facebook登录后导航

时间:2017-12-28 18:01:20

标签: ios facebook react-native react-navigation

Facebook login window

我想知道在按下"继续"之后如何导航到下一页。 (查看图片)。我目前正在使用下面的代码,但它给了我一个错误"无法读取属性'导航'未定义"

  fbAuth() {
        LoginManager.logInWithReadPermissions(['public_profile']).then(function(result){
          if (result.isCancelled){
            console.log('Login Cancelled')
          } else {
            this.props.navigation.navigate('Home')
          }
        }, function(error){
          console.log('Error occurred' + error);
        })
      }

我的渲染功能是下面的代码(带图像的TouchableHighlight" Button.png"是登录窗口弹出的Facebook登录按钮)

render() {
    return (
      <View style={styles.container}>
        <StatusBar
          barStyle="light-content"/>
        <TouchableHighlight onPress={this.fbAuth}
          underlayColor="white">
          <Image style={{width: 218, height: 37}}
            source={require('../../images/Button.png')}/>
        </TouchableHighlight>
        <Image style={styles.orLine}
          source={require('../../images/OrLine.png')}/>
        <TouchableHighlight onPress={() => this.props.navigation.navigate('Signin')}
          underlayColor="white">
          <Image style={{width: 60, height: 20}}
            source={require('../../images/SignInButton.png')}/>
        </TouchableHighlight>
        <Image style={styles.toolBar}
          source={require('../../images/ToolBar.png')}/>
        <TouchableHighlight onPress={() => this.props.navigation.navigate('Signup')} underlayColor="white"
          style={styles.signUpButton}>
        <Image style={styles.signUpButton}
          source={require('../../images/SignUpButton.png')}/>
        </TouchableHighlight>
      </View>
    );
  }
}

当弹出登录窗口时,如何更改状态栏barStyle? (这样当窗口关闭时,它会变回原来的barStyle)。 非常感谢你。

1 个答案:

答案 0 :(得分:0)

关闭您发布的错误消息,问题是正确的“this”对象未被传递到您的第一个“TouchableHighlight”组件中的“fbAuth”函数。将函数直接作为输入传递给“onPress”或其他事件处理程序时会发生这种情况。要传递正确的“this”对象,您可以使用箭头表示法使用匿名函数,就像您在其他“onPress”函数中所做的那样。

相关代码块是:

    <TouchableHighlight onPress={() => this.fbAuth()}
      underlayColor="white">
      <Image style={{width: 218, height: 37}}
        source={require('../../images/Button.png')}/>
    </TouchableHighlight>

要回答您的其他问题,您必须在应用状态中包含statusBar的颜色,然后在弹出登录窗口时更新状态。

相关问题