Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Back button closing activity when on root stack screen #2804

Merged
merged 4 commits into from
Jan 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
<intent-filter>
<action android:name="android.intent.action.DOWNLOAD_COMPLETE" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions app/AppContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -65,7 +65,7 @@ const App = React.memo(({ root, isMasterDetail }) => {
>
<Stack.Navigator screenOptions={{ headerShown: false, animationEnabled: false }}>
<>
{root === ROOT_LOADING || root === ROOT_BACKGROUND ? (
{root === ROOT_LOADING ? (
<Stack.Screen
name='AuthLoading'
component={AuthLoadingView}
Expand Down
1 change: 0 additions & 1 deletion app/actions/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export const ROOT_INSIDE = 'inside';
export const ROOT_LOADING = 'loading';
export const ROOT_NEW_SERVER = 'newServer';
export const ROOT_SET_USERNAME = 'setUsername';
export const ROOT_BACKGROUND = 'background';

export function appStart({ root, ...args }) {
return {
Expand Down
38 changes: 2 additions & 36 deletions app/views/OnboardingView/index.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -23,7 +21,6 @@ class OnboardingView extends React.Component {

static propTypes = {
navigation: PropTypes.object,
appStart: PropTypes.func,
theme: PropTypes.string
}

Expand All @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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);
4 changes: 0 additions & 4 deletions app/views/RoomsListView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
roomsRequest as roomsRequestAction,
closeServerDropdown as closeServerDropdownAction
} from '../../actions/rooms';
import { appStart as appStartAction, ROOT_BACKGROUND } from '../../actions/app';
import debounce from '../../utils/debounce';
import { isIOS, isTablet } from '../../utils/deviceInfo';
import RoomsListHeaderView from './Header';
Expand Down Expand Up @@ -549,12 +548,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;
};

Expand Down Expand Up @@ -1044,7 +1041,6 @@ const mapDispatchToProps = dispatch => ({
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())
Expand Down