나는 사용자가 응용 프로그램 시작시 로그인 한 경우 감지 로그인하지 않은 경우 로그인 화면에 그를 리디렉션하려고에서 로그인보기로 리디렉션하는가 기본 반작용 -. 어떻게 componentWillReceiveProps
import * as AuthView from '../modules/auth/AuthView';
const AppView = React.createClass({
propTypes: {
isReady: PropTypes.bool.isRequired,
isLoggedIn: PropTypes.bool.isRequired,
dispatch: PropTypes.func.isRequired
},
componentDidMount() {
snapshotUtil.resetSnapshot()
.then(snapshot => {
const {dispatch} = this.props;
if (snapshot) {
dispatch(SessionStateActions.resetSessionStateFromSnapshot(snapshot));
} else {
dispatch(SessionStateActions.initializeSessionState());
}
store.subscribe(() => {
snapshotUtil.saveSnapshot(store.getState());
});
});
},
componentWillReceiveProps({isReady, isLoggedIn}) {
if (!this.props.isReady) {
if (isReady && !isLoggedIn) {
console.warn("Not logged in, trying to show login screen here...");
AuthView.showLoginView();
}
}
},
render() {
if (!this.props.isReady) {
return (
<View>
<ActivityIndicator style={styles.centered}/>
</View>
);
}
return (
<View style={{flex: 1}}>
<NavigationViewContainer />
</View>
);
}
});
그리고 내 AuthView 모양 :
export function showLoginView() {
var loginView = <View>
<Text>
This is a Login View
</Text>
</View>;
return loginView;
}
출력이 비어 있습니다. http://i.imgur.com/6CgvOGW.png
경고 메시지 (console.warn)가 표시되고 "ActivityIndicator"가 표시됩니다. 하지만 로그인 패널이 아닙니다.
내 질문은 showLoginView() 함수를 수정하여 전체 화면 로그인보기를 표시하는 방법입니다.
나는 거의 같은 결론에 도달했습니다! 확인을 위해 고맙습니다. 나는 그것을 할 다른 방법이 있는지 기다릴 것입니다. btw, 내가 붙여 넣은 코드는 페퍼로니 앱 키트의 일부로 이해하려고 노력하고 있습니다. 비슷한 일을하고 있습니다 : https://github.com/futurice/pepperoni-app-kit/blob/master/src/modules/AppView.js#L36. 그러나, 그 라인에서 로그인을 렌더링하기 위해 네이티브 모듈을 사용하는 것처럼 보입니다. –