From 580134af92a48db02ce793975a5aea00e3fa3c4f Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Fri, 15 Jan 2021 13:42:09 -0300 Subject: [PATCH 1/4] Make hardware back button to behave as home button on root screens --- android/app/src/main/AndroidManifest.xml | 2 +- .../src/main/java/chat/rocket/reactnative/MainActivity.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 8c3ab8d183..440766f189 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -29,7 +29,7 @@ android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" android:exported="true" android:label="@string/app_name" - android:launchMode="singleTask" + android:launchMode="singleTop" android:windowSoftInputMode="adjustResize"> diff --git a/android/app/src/main/java/chat/rocket/reactnative/MainActivity.java b/android/app/src/main/java/chat/rocket/reactnative/MainActivity.java index e65fc28b35..e93eb3f968 100644 --- a/android/app/src/main/java/chat/rocket/reactnative/MainActivity.java +++ b/android/app/src/main/java/chat/rocket/reactnative/MainActivity.java @@ -37,6 +37,11 @@ protected void onCreate(Bundle savedInstanceState) { RNBootSplash.init(R.drawable.launch_screen, MainActivity.this); } + @Override + public void invokeDefaultOnBackPressed() { + moveTaskToBack(true); + } + /** * Returns the name of the main component registered from JavaScript. This is used to schedule * rendering of the component. From cfb136e6754039d4f233b2ced6b07908529906e1 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Fri, 15 Jan 2021 13:42:31 -0300 Subject: [PATCH 2/4] Remove unnecessary code --- app/views/RoomsListView/index.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/views/RoomsListView/index.js b/app/views/RoomsListView/index.js index 8d39995dfa..689fc384a1 100644 --- a/app/views/RoomsListView/index.js +++ b/app/views/RoomsListView/index.js @@ -549,12 +549,10 @@ class RoomsListView extends React.Component { handleBackPress = () => { const { searching } = this.state; - const { appStart } = this.props; if (searching) { this.cancelSearch(); return true; } - appStart({ root: ROOT_BACKGROUND }); return false; }; From b41ce20aaa65eb0c2283cbcf31dbb14a58c59228 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Fri, 15 Jan 2021 13:47:34 -0300 Subject: [PATCH 3/4] Remove handleBackPress from OnboardingView --- app/views/OnboardingView/index.js | 38 ++----------------------------- 1 file changed, 2 insertions(+), 36 deletions(-) diff --git a/app/views/OnboardingView/index.js b/app/views/OnboardingView/index.js index 487bb70808..a3cd50c28c 100644 --- a/app/views/OnboardingView/index.js +++ b/app/views/OnboardingView/index.js @@ -1,12 +1,10 @@ import React from 'react'; import { - View, Text, Image, BackHandler, Linking + View, Text, Image, Linking } from 'react-native'; import PropTypes from 'prop-types'; -import { connect } from 'react-redux'; import Orientation from 'react-native-orientation-locker'; -import { appStart as appStartAction, ROOT_BACKGROUND } from '../../actions/app'; import I18n from '../../i18n'; import Button from '../../containers/Button'; import styles from './styles'; @@ -23,7 +21,6 @@ class OnboardingView extends React.Component { static propTypes = { navigation: PropTypes.object, - appStart: PropTypes.func, theme: PropTypes.string } @@ -34,18 +31,6 @@ class OnboardingView extends React.Component { } } - componentDidMount() { - const { navigation } = this.props; - this.unsubscribeFocus = navigation.addListener('focus', () => { - this.backHandler = BackHandler.addEventListener('hardwareBackPress', this.handleBackPress); - }); - this.unsubscribeBlur = navigation.addListener('blur', () => { - if (this.backHandler && this.backHandler.remove) { - this.backHandler.remove(); - } - }); - } - shouldComponentUpdate(nextProps) { const { theme } = this.props; if (theme !== nextProps.theme) { @@ -54,21 +39,6 @@ class OnboardingView extends React.Component { return false; } - componentWillUnmount() { - if (this.unsubscribeFocus) { - this.unsubscribeFocus(); - } - if (this.unsubscribeBlur) { - this.unsubscribeBlur(); - } - } - - handleBackPress = () => { - const { appStart } = this.props; - appStart({ root: ROOT_BACKGROUND }); - return false; - } - connectServer = () => { logEvent(events.ONBOARD_JOIN_A_WORKSPACE); const { navigation } = this.props; @@ -116,8 +86,4 @@ class OnboardingView extends React.Component { } } -const mapDispatchToProps = dispatch => ({ - appStart: params => dispatch(appStartAction(params)) -}); - -export default connect(null, mapDispatchToProps)(withTheme(OnboardingView)); +export default withTheme(OnboardingView); From 7757eb89cec632ff9be7e17c2e23ee26acbdc115 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Fri, 15 Jan 2021 14:00:27 -0300 Subject: [PATCH 4/4] Fix lint --- app/AppContainer.js | 4 ++-- app/actions/app.js | 1 - app/views/RoomsListView/index.js | 2 -- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/app/AppContainer.js b/app/AppContainer.js index 4023635f73..9ec17ad433 100644 --- a/app/AppContainer.js +++ b/app/AppContainer.js @@ -7,7 +7,7 @@ import { connect } from 'react-redux'; import Navigation from './lib/Navigation'; import { defaultHeader, getActiveRouteName, navigationTheme } from './utils/navigation'; import { - ROOT_LOADING, ROOT_OUTSIDE, ROOT_NEW_SERVER, ROOT_INSIDE, ROOT_SET_USERNAME, ROOT_BACKGROUND + ROOT_LOADING, ROOT_OUTSIDE, ROOT_NEW_SERVER, ROOT_INSIDE, ROOT_SET_USERNAME } from './actions/app'; // Stacks @@ -65,7 +65,7 @@ const App = React.memo(({ root, isMasterDetail }) => { > <> - {root === ROOT_LOADING || root === ROOT_BACKGROUND ? ( + {root === ROOT_LOADING ? ( ({ toggleSortDropdown: () => dispatch(toggleSortDropdownAction()), openSearchHeader: () => dispatch(openSearchHeaderAction()), closeSearchHeader: () => dispatch(closeSearchHeaderAction()), - appStart: params => dispatch(appStartAction(params)), roomsRequest: params => dispatch(roomsRequestAction(params)), selectServerRequest: server => dispatch(selectServerRequestAction(server)), closeServerDropdown: () => dispatch(closeServerDropdownAction())