[FIX] Back button closing activity when on root stack screen (#2804)
* Make hardware back button to behave as home button on root screens * Remove unnecessary code * Remove handleBackPress from OnboardingView * Fix lint
This commit is contained in:
parent
b77603c729
commit
a51a98513d
|
@ -29,7 +29,7 @@
|
||||||
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
|
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:launchMode="singleTask"
|
android:launchMode="singleTop"
|
||||||
android:windowSoftInputMode="adjustResize">
|
android:windowSoftInputMode="adjustResize">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.DOWNLOAD_COMPLETE" />
|
<action android:name="android.intent.action.DOWNLOAD_COMPLETE" />
|
||||||
|
|
|
@ -37,6 +37,11 @@ public class MainActivity extends ReactFragmentActivity {
|
||||||
RNBootSplash.init(R.drawable.launch_screen, MainActivity.this);
|
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
|
* Returns the name of the main component registered from JavaScript. This is used to schedule
|
||||||
* rendering of the component.
|
* rendering of the component.
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { connect } from 'react-redux';
|
||||||
import Navigation from './lib/Navigation';
|
import Navigation from './lib/Navigation';
|
||||||
import { defaultHeader, getActiveRouteName, navigationTheme } from './utils/navigation';
|
import { defaultHeader, getActiveRouteName, navigationTheme } from './utils/navigation';
|
||||||
import {
|
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';
|
} from './actions/app';
|
||||||
|
|
||||||
// Stacks
|
// Stacks
|
||||||
|
@ -65,7 +65,7 @@ const App = React.memo(({ root, isMasterDetail }) => {
|
||||||
>
|
>
|
||||||
<Stack.Navigator screenOptions={{ headerShown: false, animationEnabled: false }}>
|
<Stack.Navigator screenOptions={{ headerShown: false, animationEnabled: false }}>
|
||||||
<>
|
<>
|
||||||
{root === ROOT_LOADING || root === ROOT_BACKGROUND ? (
|
{root === ROOT_LOADING ? (
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
name='AuthLoading'
|
name='AuthLoading'
|
||||||
component={AuthLoadingView}
|
component={AuthLoadingView}
|
||||||
|
|
|
@ -5,7 +5,6 @@ export const ROOT_INSIDE = 'inside';
|
||||||
export const ROOT_LOADING = 'loading';
|
export const ROOT_LOADING = 'loading';
|
||||||
export const ROOT_NEW_SERVER = 'newServer';
|
export const ROOT_NEW_SERVER = 'newServer';
|
||||||
export const ROOT_SET_USERNAME = 'setUsername';
|
export const ROOT_SET_USERNAME = 'setUsername';
|
||||||
export const ROOT_BACKGROUND = 'background';
|
|
||||||
|
|
||||||
export function appStart({ root, ...args }) {
|
export function appStart({ root, ...args }) {
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import {
|
import {
|
||||||
View, Text, Image, BackHandler, Linking
|
View, Text, Image, Linking
|
||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { connect } from 'react-redux';
|
|
||||||
import Orientation from 'react-native-orientation-locker';
|
import Orientation from 'react-native-orientation-locker';
|
||||||
|
|
||||||
import { appStart as appStartAction, ROOT_BACKGROUND } from '../../actions/app';
|
|
||||||
import I18n from '../../i18n';
|
import I18n from '../../i18n';
|
||||||
import Button from '../../containers/Button';
|
import Button from '../../containers/Button';
|
||||||
import styles from './styles';
|
import styles from './styles';
|
||||||
|
@ -23,7 +21,6 @@ class OnboardingView extends React.Component {
|
||||||
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
navigation: PropTypes.object,
|
navigation: PropTypes.object,
|
||||||
appStart: PropTypes.func,
|
|
||||||
theme: PropTypes.string
|
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) {
|
shouldComponentUpdate(nextProps) {
|
||||||
const { theme } = this.props;
|
const { theme } = this.props;
|
||||||
if (theme !== nextProps.theme) {
|
if (theme !== nextProps.theme) {
|
||||||
|
@ -54,21 +39,6 @@ class OnboardingView extends React.Component {
|
||||||
return false;
|
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 = () => {
|
connectServer = () => {
|
||||||
logEvent(events.ONBOARD_JOIN_A_WORKSPACE);
|
logEvent(events.ONBOARD_JOIN_A_WORKSPACE);
|
||||||
const { navigation } = this.props;
|
const { navigation } = this.props;
|
||||||
|
@ -116,8 +86,4 @@ class OnboardingView extends React.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapDispatchToProps = dispatch => ({
|
export default withTheme(OnboardingView);
|
||||||
appStart: params => dispatch(appStartAction(params))
|
|
||||||
});
|
|
||||||
|
|
||||||
export default connect(null, mapDispatchToProps)(withTheme(OnboardingView));
|
|
||||||
|
|
|
@ -29,7 +29,6 @@ import {
|
||||||
roomsRequest as roomsRequestAction,
|
roomsRequest as roomsRequestAction,
|
||||||
closeServerDropdown as closeServerDropdownAction
|
closeServerDropdown as closeServerDropdownAction
|
||||||
} from '../../actions/rooms';
|
} from '../../actions/rooms';
|
||||||
import { appStart as appStartAction, ROOT_BACKGROUND } from '../../actions/app';
|
|
||||||
import debounce from '../../utils/debounce';
|
import debounce from '../../utils/debounce';
|
||||||
import { isIOS, isTablet } from '../../utils/deviceInfo';
|
import { isIOS, isTablet } from '../../utils/deviceInfo';
|
||||||
import RoomsListHeaderView from './Header';
|
import RoomsListHeaderView from './Header';
|
||||||
|
@ -549,12 +548,10 @@ class RoomsListView extends React.Component {
|
||||||
|
|
||||||
handleBackPress = () => {
|
handleBackPress = () => {
|
||||||
const { searching } = this.state;
|
const { searching } = this.state;
|
||||||
const { appStart } = this.props;
|
|
||||||
if (searching) {
|
if (searching) {
|
||||||
this.cancelSearch();
|
this.cancelSearch();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
appStart({ root: ROOT_BACKGROUND });
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1044,7 +1041,6 @@ const mapDispatchToProps = dispatch => ({
|
||||||
toggleSortDropdown: () => dispatch(toggleSortDropdownAction()),
|
toggleSortDropdown: () => dispatch(toggleSortDropdownAction()),
|
||||||
openSearchHeader: () => dispatch(openSearchHeaderAction()),
|
openSearchHeader: () => dispatch(openSearchHeaderAction()),
|
||||||
closeSearchHeader: () => dispatch(closeSearchHeaderAction()),
|
closeSearchHeader: () => dispatch(closeSearchHeaderAction()),
|
||||||
appStart: params => dispatch(appStartAction(params)),
|
|
||||||
roomsRequest: params => dispatch(roomsRequestAction(params)),
|
roomsRequest: params => dispatch(roomsRequestAction(params)),
|
||||||
selectServerRequest: server => dispatch(selectServerRequestAction(server)),
|
selectServerRequest: server => dispatch(selectServerRequestAction(server)),
|
||||||
closeServerDropdown: () => dispatch(closeServerDropdownAction())
|
closeServerDropdown: () => dispatch(closeServerDropdownAction())
|
||||||
|
|
Loading…
Reference in New Issue