我有點新使用反應原生,我試圖實現Facebook登錄與我的應用程序使用反應原生fbsdk。反應本機FBSDK onLoginFinished推到新屏幕
我已經知道它會向用戶的Facebook配置文件請求權限,然後返回到應用並顯示成功提醒消息。我不想在登錄已完成時顯示警報,而是想推入新的屏幕。
這是在主類的構造函數我的登錄按鈕代碼:
constructor(props){
super(props);
this.goToNewPage = this.goToNewPage.bind(this);
const infoRequest = new GraphRequest(
'/me',
{parameters: {
fields: {
string: 'email,first_name,last_name,id,gender' // what you want to get
}
}},
this._responseInfoCallback,
);
Login = React.createClass({
render: function() {
return (
<View >
<LoginButton
navigator={this.props.navigator}
style = {{marginLeft:55, marginRight:55, height:50, width:300}}
onLoginFinished={
(error, result) => {
if (error) {
alert("Login failed with error: " + result.error);
} else if (result.isCancelled) {
alert("Login was cancelled");
} else {
alert("Login was successful with permissions: " + result.grantedPermissions)
new GraphRequestManager().addRequest(infoRequest).start();
this.goToNewPage;
}
}
}
onLogoutFinished={() => alert("User logged out")}
/>
</View>
);
}
});
} //closes constructor
_responseInfoCallback(error: ?Object, result: ?Object) {
if (error) {
alert('Error fetching data: ' + error.toString());
} else {
alert('Success fetching data: ' + result.toString());
console.log(result);
}
}
goToNewPage(){
console.log("Hello from go to new page function");
this.props.navigator.push({
id: 'newPage',
name: 'Going To New Page',
});
}
但都顯示成功後的警報,並沒有推到了新的一頁。似乎this.props.navigator在我的Login類中不被識別,我不知道爲什麼。任何幫助都將不勝感激
我在你的app上做的和你一樣,區別在於我調用另一個綁定到組件的方法。我沒有在這裏試過,但如果你創建另一個方法並將它綁定到組件,然後調用導航器,它可能會工作。 –