How can I return to the last activity in responsive mode for Android?

How can I go back to the last action in action-native for Android?

My thinking:

1 set _navigate to index.android.js

// ่ฎพ็ฝฎๅ›ž้€€็š„ๅ †ๆ ˆ var _navigator; BackAndroid.addEventListener('hardwareBackPress', function() { if (_navigator && _navigator.getCurrentRoutes().length > 1) { _navigator.pop(); return true; } return false; }); 

2 pass navigator in RouteMapping:

 RouteMapper: function(route, navigationOperations, onComponentRef) { _navigator = navigationOperations; if (route.name === 'detail') { // ้—ฎ้ข˜่ฏฆๆƒ…้กตreturn ( <DetailScreen navigator={navigationOperations} question={route.question} /> ); } else if (route.name == 'front') { // ้ฆ–้กตreturn( <FrontScreen navigator={navigationOperations} /> ); } }, 

3 set the list view

 gotoDetail: function(question: Object) { this.props.navigator.push({ id: question.question_id, name: 'detail', question: question }) 

But that does not work. When I click the back button in Android, does it jump out of the app?

How can i do this?

Or can someone give an example?

+5
source share
1 answer

You need to add the following code to <your project> / android / app / src / main / java / com / <your project> /MainActivity.java:

 @Override public void onBackPressed() { if (mReactInstanceManager != null) { mReactInstanceManager.onBackPressed(); } else { super.onBackPressed(); } } 

Projects created using React Native 0.12 will behave correctly.

For more information, see this issue on Github https://github.com/facebook/react-native/issues/3223 .

+3
source

Source: https://habr.com/ru/post/1232680/


All Articles