我使用Facebook SDK創建了一個登錄按鈕。用戶登錄後,該應用將導航到第二個屏幕(NavigatorIOS)。從第二個屏幕中,用戶可以使用導航(後退按鈕)返回到登錄屏幕。反應本機 - 防止用戶回到登錄屏幕
如何防止用戶返回到登錄屏幕(如果他已經登錄)?
index.ios.js
import React, { Component } from 'react'
import {
AppRegistry,
StyleSheet,
NavigatorIOS
} from 'react-native'
import LoginView from './src/login-view'
class MyApp extends Component {
render() {
return (
<Provider store={store}>
<NavigatorIOS
initialRoute={{
component: LoginView,
title: 'MyApp',
index: 0
}}
/>
</Provider>
);
}
}
AppRegistry.registerComponent('MyApp',() => MyApp);
LoginView
import React, {Component} from 'react'
import {
View,
Text,
StyleSheet,
TouchableHighlight,
} from 'react-native'
import CategoryView from './category-view'
import {LoginButton, AccessToken, GraphRequest, GraphRequestManager} from 'react-native-fbsdk'
class LoginView extends Component {
goToCategoryView =() =>
this.props.navigator.push({
title: 'Categories',
component: CategoryView,
})
render(){
return(
<View style={styles.container}>
<LoginButton
readPermissions={['public_profile','email']}
onLoginFinished={
(error, result) => {
if (error) {
console.log('login has error: ', result.error)
} else if (result.isCancelled) {
console.log('login is cancelled.')
} else {
AccessToken.getCurrentAccessToken().then((data) => {
this.goToCategoryView()
})
}
}
}
onLogoutFinished={() => {console.log('logged out')}} />
</View>
)
}
}
export default LoginView
感謝您的回覆。好戲,試過了。它工作正常。 – John
很高興爲您服務!你願意投票嗎?謝謝 –
關於該主題的最後一個問題 - 一旦用戶登錄,如果我刷新模擬器,它將返回到顯示Facebook繼續按鈕的登錄屏幕。是否可以防止刷新/重新加載時返回到該屏幕? – John