2017-09-16 6 views
0

내 앱에 스플래시 화면이 있으므로 기본 페이지에서 Android back button을 클릭하면 앱을 종료하고 싶습니다 (스플래시로 돌아 가지 않음). 화면). 따라서이 메소드를 반응식 자습서에서 구현하려고합니다.React Native - Android BackHandler - 구현 방법 this.OnMainScreen and this.goBack

if (!this.onMainScreen()) { 
    this.goBack(); 
    return true; 
} 
return false; 

아무도 나를 onMainScreen() 및 goBack() 함수를 구현하는 방법을 도울 수 있습니까? 도움 주셔서 감사합니다.

답변

1

이 기능을

function getCurrentRouteFromState(navigationState): NavigationRouteConfigMap { 
    const route = navigationState.routes[navigationState.index]; 
    // dive into nested navigators 
    if (route.routes) { 
    return getCurrentRouteFromState(route); 
    } 
    return route; 
} 

패스 그것을 탐색 상태를 사용하고 결과 객체에 routeName 멤버에 액세스 할 수 있어야합니다 :

let screenName = getCurrentRouteFromState(state).routeName은 다음 메인 화면으로 화면 이름을 비교할 수 있습니다 이름을 정하고 무엇을할지 결정하십시오.

+0

제 경우에는 처럼 보입니다. const currentRouteName = router.getPathAndParamsForState (state) .path.split ('/'). reverse() [0]' – stereodenis