Skip to content

Commit 9c4a3cd

Browse files
committed
navActions: Stop dispatching navigateBack() via Redux.
Instead, dispatch it via our recently added `NavigationService`.
1 parent d10e393 commit 9c4a3cd

File tree

15 files changed

+38
-41
lines changed

15 files changed

+38
-41
lines changed

src/emoji/EmojiPickerScreen.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import React, { PureComponent } from 'react';
44
import { FlatList } from 'react-native';
55
import type { NavigationStackProp, NavigationStateRoute } from 'react-navigation-stack';
66

7+
import NavigationService from '../nav/NavigationService';
78
import * as api from '../api';
89
import { unicodeCodeByName } from './codePointMap';
910
import { Screen } from '../common';
@@ -57,12 +58,12 @@ class EmojiPickerScreen extends PureComponent<Props, State> {
5758
};
5859

5960
addReaction = (emojiName: string) => {
60-
const { auth, dispatch, navigation } = this.props;
61+
const { auth, navigation } = this.props;
6162
const { messageId } = navigation.state.params;
6263

6364
const { reactionType, emojiCode } = this.getReactionTypeAndCode(emojiName);
6465
api.emojiReactionAdd(auth, messageId, reactionType, emojiCode, emojiName);
65-
dispatch(navigateBack());
66+
NavigationService.dispatch(navigateBack());
6667
};
6768

6869
render() {

src/lightbox/Lightbox.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { View, Dimensions, Easing } from 'react-native';
55
import PhotoView from 'react-native-photo-view';
66
import { connectActionSheet } from '@expo/react-native-action-sheet';
77

8+
import NavigationService from '../nav/NavigationService';
89
import type { Auth, Dispatch, Message } from '../types';
910
import { connect } from '../react-redux';
1011
import type { ShowActionSheetWithOptions } from '../message/messageActionSheet';
@@ -79,8 +80,7 @@ class Lightbox extends PureComponent<Props, State> {
7980
};
8081

8182
handlePressBack = () => {
82-
const { dispatch } = this.props;
83-
dispatch(navigateBack());
83+
NavigationService.dispatch(navigateBack());
8484
};
8585

8686
getAnimationProps = () => ({

src/nav/BackNavigationHandler.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@ import { PureComponent } from 'react';
44
import { BackHandler } from 'react-native';
55

66
import NavigationService from './NavigationService';
7-
import type { Dispatch } from '../types';
8-
import { connect } from '../react-redux';
97
import { navigateBack } from '../actions';
108

119
type Props = $ReadOnly<{|
1210
children: React$Node,
13-
14-
dispatch: Dispatch,
1511
|}>;
1612

17-
class BackNavigationHandler extends PureComponent<Props> {
13+
export default class BackNavigationHandler extends PureComponent<Props> {
1814
componentDidMount() {
1915
BackHandler.addEventListener('hardwareBackPress', this.handleBackButtonPress);
2016
}
@@ -24,10 +20,9 @@ class BackNavigationHandler extends PureComponent<Props> {
2420
}
2521

2622
handleBackButtonPress = () => {
27-
const { dispatch } = this.props;
2823
const canGoBack = NavigationService.getState().index > 0;
2924
if (canGoBack) {
30-
dispatch(navigateBack());
25+
NavigationService.dispatch(navigateBack());
3126
}
3227
return canGoBack;
3328
};
@@ -36,5 +31,3 @@ class BackNavigationHandler extends PureComponent<Props> {
3631
return this.props.children;
3732
}
3833
}
39-
40-
export default connect(state => ({}))(BackNavigationHandler);

src/nav/ChatNavBar.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import React, { PureComponent } from 'react';
44
import { View } from 'react-native';
55
import Color from 'color';
66

7+
import NavigationService from './NavigationService';
78
import type { Dispatch, Narrow, EditMessage } from '../types';
89
import { LoadingBanner } from '../common';
910
import { connect } from '../react-redux';
@@ -29,7 +30,7 @@ type Props = $ReadOnly<{|
2930

3031
class ChatNavBar extends PureComponent<Props> {
3132
render() {
32-
const { dispatch, backgroundColor, narrow, editMessage } = this.props;
33+
const { backgroundColor, narrow, editMessage } = this.props;
3334
const color =
3435
backgroundColor === DEFAULT_TITLE_BACKGROUND_COLOR
3536
? BRAND_COLOR
@@ -63,7 +64,7 @@ class ChatNavBar extends PureComponent<Props> {
6364
name="arrow-left"
6465
color={color}
6566
onPress={() => {
66-
dispatch(navigateBack());
67+
NavigationService.dispatch(navigateBack());
6768
}}
6869
/>
6970
<Title color={color} narrow={narrow} editMessage={editMessage} />

src/nav/ModalNavBar.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@
33
import React, { PureComponent } from 'react';
44
import { View } from 'react-native';
55

6-
import type { Dispatch, LocalizableText } from '../types';
6+
import NavigationService from './NavigationService';
7+
import type { LocalizableText } from '../types';
78
import type { ThemeData } from '../styles';
89
import styles, { ThemeContext, NAVBAR_SIZE } from '../styles';
9-
import { connect } from '../react-redux';
1010

1111
import Label from '../common/Label';
1212
import NavButton from './NavButton';
1313
import { navigateBack } from '../actions';
1414

1515
type Props = $ReadOnly<{|
16-
dispatch: Dispatch,
1716
canGoBack: boolean,
1817
title: LocalizableText,
1918
|}>;
@@ -23,7 +22,7 @@ class ModalNavBar extends PureComponent<Props> {
2322
context: ThemeData;
2423

2524
render() {
26-
const { dispatch, canGoBack, title } = this.props;
25+
const { canGoBack, title } = this.props;
2726
const textStyle = [
2827
styles.navTitle,
2928
canGoBack ? { marginRight: NAVBAR_SIZE } : { marginLeft: 16 },
@@ -46,7 +45,7 @@ class ModalNavBar extends PureComponent<Props> {
4645
<NavButton
4746
name="arrow-left"
4847
onPress={() => {
49-
dispatch(navigateBack());
48+
NavigationService.dispatch(navigateBack());
5049
}}
5150
/>
5251
)}
@@ -58,4 +57,4 @@ class ModalNavBar extends PureComponent<Props> {
5857
}
5958
}
6059

61-
export default connect<{||}, _, _>()(ModalNavBar);
60+
export default ModalNavBar;

src/nav/ModalSearchNavBar.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22
import React, { PureComponent } from 'react';
33
import { View } from 'react-native';
44

5-
import type { Dispatch } from '../types';
5+
import NavigationService from './NavigationService';
66
import type { ThemeData } from '../styles';
77
import { ThemeContext, NAVBAR_SIZE } from '../styles';
8-
import { connect } from '../react-redux';
98
import SearchInput from '../common/SearchInput';
109
import NavButton from './NavButton';
1110
import { navigateBack } from '../actions';
1211

1312
type Props = $ReadOnly<{|
14-
dispatch: Dispatch,
1513
autoFocus: boolean,
1614
searchBarOnChange: (text: string) => void,
1715
canGoBack: boolean,
@@ -26,7 +24,7 @@ class ModalSearchNavBar extends PureComponent<Props> {
2624
};
2725

2826
render() {
29-
const { dispatch, autoFocus, searchBarOnChange, canGoBack } = this.props;
27+
const { autoFocus, searchBarOnChange, canGoBack } = this.props;
3028
return (
3129
<View
3230
style={{
@@ -42,7 +40,7 @@ class ModalSearchNavBar extends PureComponent<Props> {
4240
<NavButton
4341
name="arrow-left"
4442
onPress={() => {
45-
dispatch(navigateBack());
43+
NavigationService.dispatch(navigateBack());
4644
}}
4745
/>
4846
)}
@@ -53,4 +51,4 @@ class ModalSearchNavBar extends PureComponent<Props> {
5351
}
5452
}
5553

56-
export default connect<{||}, _, _>()(ModalSearchNavBar);
54+
export default ModalSearchNavBar;

src/reactions/MessageReactionList.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { createAppContainer } from 'react-navigation';
55
import type { NavigationStackProp, NavigationStateRoute } from 'react-navigation-stack';
66
import { createMaterialTopTabNavigator } from 'react-navigation-tabs';
77

8+
import NavigationService from '../nav/NavigationService';
89
import * as logging from '../utils/logging';
910
import ReactionUserList from './ReactionUserList';
1011
import { connect } from '../react-redux';
@@ -146,7 +147,7 @@ class MessageReactionList extends PureComponent<Props> {
146147
if (prevProps.message !== undefined && this.props.message === undefined) {
147148
// The message was present, but got purged (currently only caused by a
148149
// REALM_INIT following a dead event queue), so go back.
149-
this.props.dispatch(navigateBack());
150+
NavigationService.dispatch(navigateBack());
150151
}
151152
}
152153

src/sharing/ShareToPm.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React from 'react';
33
import { View, Image, ScrollView, Modal, BackHandler } from 'react-native';
44
import type { NavigationTabProp, NavigationStateRoute } from 'react-navigation-tabs';
55

6+
import NavigationService from '../nav/NavigationService';
67
import type { Dispatch, SharedData, User, Auth, GetText } from '../types';
78
import { createStyleSheet } from '../styles';
89
import { TranslationContext } from '../boot/TranslationProvider';
@@ -114,9 +115,7 @@ class ShareToPm extends React.Component<Props, State> {
114115
};
115116

116117
finishShare = () => {
117-
const { dispatch } = this.props;
118-
119-
dispatch(navigateBack());
118+
NavigationService.dispatch(navigateBack());
120119
BackHandler.exitApp();
121120
};
122121

src/sharing/ShareToStream.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React from 'react';
33
import { View, Image, ScrollView, BackHandler } from 'react-native';
44
import type { NavigationTabProp, NavigationStateRoute } from 'react-navigation-tabs';
55

6+
import NavigationService from '../nav/NavigationService';
67
import type { Dispatch, SharedData, Subscription, Auth, GetText } from '../types';
78
import { createStyleSheet } from '../styles';
89
import { TranslationContext } from '../boot/TranslationProvider';
@@ -137,9 +138,7 @@ class ShareToStream extends React.Component<Props, State> {
137138
};
138139

139140
finishShare = () => {
140-
const { dispatch } = this.props;
141-
142-
dispatch(navigateBack());
141+
NavigationService.dispatch(navigateBack());
143142
BackHandler.exitApp();
144143
};
145144

src/streams/CreateStreamScreen.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import React, { PureComponent } from 'react';
33
import type { NavigationStackProp, NavigationStateRoute } from 'react-navigation-stack';
44

5+
import NavigationService from '../nav/NavigationService';
56
import type { Dispatch } from '../types';
67
import { connect } from '../react-redux';
78
import { createNewStream, navigateBack } from '../actions';
@@ -25,7 +26,7 @@ class CreateStreamScreen extends PureComponent<Props> {
2526
const { dispatch, ownEmail } = this.props;
2627

2728
dispatch(createNewStream(name, description, [ownEmail], isPrivate));
28-
dispatch(navigateBack());
29+
NavigationService.dispatch(navigateBack());
2930
};
3031

3132
render() {

0 commit comments

Comments
 (0)