Skip to content

Commit 55743c2

Browse files
committed
Upgrade React Navigation from 6 to 7
- Needed to use `npm i --force` to overcome a peer dependency issue, but i think this was a mistake, because running `npm i` again showed no warnings, and inspecting the package-lock.json changes I don't see any violations - Remove explicit dependency on react-native-tab-view - https://reactnavigation.org/docs/upgrading-from-6.x#material-top-tab-navigator-no-longer-requires-installing-react-native-tab-view - Update Theme to include fonts - Note that the top tab names changed from UPPERCASE to Titlecase and semibold to regular - Note that BottomTab labels no longer allow font scaling since the bottom tab bar height is fixed. So font scaling just causes the labels to be cut off. - https://reactnavigation.org/docs/upgrading-from-6.x#the-theme-prop-now-accepts-a-fonts-property - https://reactnavigation.org/docs/themes - Update navigate to popTo when intending to goBack - https://reactnavigation.org/docs/upgrading-from-6.x/#the-navigate-method-no-longer-goes-back-use-popto-instead - Add rnx-kit/align-deps overrides for react navigation 7 - This upgrade fixes a warning introduced during a previous react-native upgrade (8a6cee1) that happened when swiping between top tabs - react-navigation/react-navigation#12142
1 parent aca8bad commit 55743c2

15 files changed

+207
-183
lines changed

app/Theme.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export type Theme = ReturnType<typeof useTheme>;
133133
export type ThemeColors = Theme['colors'];
134134

135135
export const useNavigationTheme = () => {
136-
const { colors, isDarkMode } = useTheme();
136+
const { colors, font, isDarkMode } = useTheme();
137137
return {
138138
colors: {
139139
background: colors.background,
@@ -144,5 +144,23 @@ export const useNavigationTheme = () => {
144144
text: colors.label,
145145
},
146146
dark: isDarkMode,
147+
fonts: {
148+
regular: {
149+
fontFamily: font.weights.regular,
150+
fontWeight: '400' as const,
151+
},
152+
medium: {
153+
fontFamily: font.weights.medium,
154+
fontWeight: '500' as const,
155+
},
156+
bold: {
157+
fontFamily: font.weights.semiBold,
158+
fontWeight: '600' as const,
159+
},
160+
heavy: {
161+
fontFamily: font.weights.bold,
162+
fontWeight: '700' as const,
163+
},
164+
},
147165
};
148166
};

app/navigation/DefaultTopTabOptions.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import {
44
import useTheme from '../Theme';
55

66
export default function useDefaultTopTabOptions() {
7-
const {
8-
colors, font, sizes, spacing,
9-
} = useTheme();
7+
const { colors, sizes, spacing } = useTheme();
108

119
const screenPaddingStart = spacing.m;
1210
const screenOptions: MaterialTopTabNavigationOptions = {
@@ -21,9 +19,6 @@ export default function useDefaultTopTabOptions() {
2119
paddingHorizontal: 0,
2220
width: 'auto',
2321
},
24-
tabBarLabelStyle: {
25-
fontFamily: font.weights.semiBold,
26-
},
2722
tabBarScrollEnabled: true,
2823
tabBarStyle: {
2924
paddingLeft: screenPaddingStart,

app/navigation/OrgTabs.tsx

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,24 @@
11
import React from 'react';
2-
import { StyleSheet } from 'react-native';
32
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
43
import ConnectStack from './ConnectStack';
54
import { OrgTabsParamList } from './types';
6-
import useTheme from '../Theme';
75
import { TabBarIcon } from '../components';
86
import DiscussStack from './DiscussStack';
97
import VoteStack from './VoteStack';
108
import OrgStack from './OrgStack';
119
import LeadStack from './LeadStack';
1210
import { useCurrentUser } from '../model';
1311

14-
const useStyles = () => {
15-
const { font, spacing } = useTheme();
16-
17-
const styles = StyleSheet.create({
18-
tabBarIconLabel: {
19-
fontFamily: font.weights.semiBold,
20-
marginBottom: spacing.xxs,
21-
},
22-
});
23-
24-
return { styles };
25-
};
26-
2712
const Tab = createBottomTabNavigator<OrgTabsParamList>();
2813

2914
export default function OrgTabs() {
30-
const { styles } = useStyles();
31-
3215
const { currentUser } = useCurrentUser();
3316

3417
return (
3518
<Tab.Navigator
3619
screenOptions={{
20+
tabBarAllowFontScaling: false,
3721
headerShown: false,
38-
tabBarLabelStyle: styles.tabBarIconLabel,
3922
tabBarHideOnKeyboard: true,
4023
}}
4124
>

app/screens/discuss/NewCommentScreen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default function NewCommentScreen({
2626
<NewCommentScreenBase
2727
HeaderComponent={HeaderComponent}
2828
onCommentCreated={(commentId) => {
29-
navigation.navigate('Post', {
29+
navigation.popTo('Post', {
3030
insertedComments: [{ commentId }],
3131
postId: post.id,
3232
});

app/screens/discuss/NewPostScreen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default function NewPostScreen({
2121
const onPostCreated = useCallback((post: Post) => {
2222
const params = { prependedPostId: post.id };
2323
const screen = getNextScreenName(maybeCategory);
24-
navigation.navigate('DiscussTabs', { screen, params });
24+
navigation.popTo('DiscussTabs', { screen, params });
2525
}, []);
2626

2727
return (

app/screens/discuss/NewReplyScreen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default function NewReplyScreen({
2929
commentId={commentId}
3030
HeaderComponent={HeaderComponent}
3131
onCommentCreated={(newCommentId) => {
32-
navigation.navigate('Post', {
32+
navigation.popTo('Post', {
3333
insertedComments: [
3434
{ commentId: newCommentId, parentCommentId: commentId },
3535
],

app/screens/lead/BlockMemberScreen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export default function BlockMemberScreen({
5252
action: 'block', moderatable,
5353
});
5454
setResult('success');
55-
navigation.navigate('BlockedMembers', {
55+
navigation.popTo('BlockedMembers', {
5656
prependedModerationEventId: moderationEvent.id,
5757
});
5858
} catch (error) {

app/screens/onboarding/NewOrg/NewOrgStepNavigator.ts

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,25 @@ import type {
55

66
const name = 'NewOrg';
77

8-
const NewOrgStepNavigator = (navigation: NewOrgScreenNavigationProp) => {
9-
function navigateToStep(step: number, params: NewOrgScreenParams) {
10-
navigation.navigate(name, { ...params, step });
11-
}
12-
13-
return {
14-
navigateToStep,
15-
navigateToNext: (currentStep: number, params: NewOrgScreenParams) => {
16-
if (currentStep < NewOrgSteps.length - 1) {
17-
navigateToStep(currentStep + 1, params);
18-
} else {
19-
navigation.navigate({
20-
name: 'OrgReview',
21-
params: (params as OrgReviewParams),
22-
});
23-
}
24-
},
25-
navigateToPrevious: (currentStep: number, params: NewOrgScreenParams) => {
26-
if (currentStep > 0) {
27-
navigateToStep(currentStep - 1, params);
28-
} else {
29-
navigation.goBack();
30-
}
31-
},
32-
};
33-
};
8+
const NewOrgStepNavigator = (navigation: NewOrgScreenNavigationProp) => ({
9+
navigateToNext: (currentStep: number, params: NewOrgScreenParams) => {
10+
if (currentStep < NewOrgSteps.length - 1) {
11+
navigation.navigate(name, { ...params, step: currentStep + 1 });
12+
} else {
13+
navigation.navigate({
14+
name: 'OrgReview',
15+
params: (params as OrgReviewParams),
16+
});
17+
}
18+
},
19+
navigateToPrevious: (currentStep: number, params: NewOrgScreenParams) => {
20+
if (currentStep > 0) {
21+
navigation.popTo(name, { ...params, step: currentStep - 1 });
22+
} else {
23+
navigation.goBack();
24+
}
25+
},
26+
});
3427

3528
export default NewOrgStepNavigator;
3629

app/screens/org/TransparencyLogScreen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default function TransparencyLogScreen({
1717
screen: 'Post', initial: false, params: { postId: id },
1818
});
1919
} else if (category === 'User') {
20-
navigation.navigate('Org', { selectedUserId: id });
20+
navigation.popTo('Org', { selectedUserId: id });
2121
} else if (category === 'Comment') {
2222
navigation.navigate('DiscussStack', {
2323
screen: 'CommentThread', initial: false, params: { commentId: id },

app/screens/vote/NewElectionBallotScreen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export default function NewElectionBallotScreen({
107107
});
108108
resetForm();
109109
setResult('success');
110-
navigation.navigate('BallotPreviews', {
110+
navigation.popTo('BallotPreviews', {
111111
prependedBallotId: ballotPreview.id,
112112
});
113113
} catch (error) {

0 commit comments

Comments
 (0)