2017-09-16 223 views
0

我的應用程序有閃屏,所以我想退出應用程序,當我們從主頁面點擊android後退按鈕(不回去飛濺屏幕)。所以我想從react-native教程中實現這個方法。React Native - Android BackHandler - 如何實現this.OnMainScreen和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

相關問題