Skip to content

Commit cbaafdc

Browse files
authored
refactor: derive isMasterDetail per-component and remove Dimensions provider (#7422)
1 parent b7fd78f commit cbaafdc

67 files changed

Lines changed: 222 additions & 307 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/AppContainer.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { useContext, memo, useEffect } from 'react';
22
import { NavigationContainer } from '@react-navigation/native';
33
import { createNativeStackNavigator } from '@react-navigation/native-stack';
4-
import { connect } from 'react-redux';
54

65
import type { SetUsernameStackParamList, StackParamList } from './definitions/navigationTypes';
76
import Navigation from './lib/navigation/appNavigation';
7+
import { useMasterDetail } from './lib/hooks/useMasterDetail';
8+
import { useAppSelector } from './lib/hooks/useAppSelector';
89
import { defaultHeader, getActiveRouteName, navigationTheme } from './lib/methods/helpers/navigation';
910
import { RootEnum } from './definitions';
1011
// Stacks
@@ -33,8 +34,10 @@ const SetUsernameStack = () => (
3334

3435
// App
3536
const Stack = createStackNavigator<StackParamList>();
36-
const App = memo(({ root, isMasterDetail }: { root: string; isMasterDetail: boolean }) => {
37+
const App = memo(() => {
3738
const { theme } = useContext(ThemeContext);
39+
const isMasterDetail = useMasterDetail();
40+
const root = useAppSelector(state => state.app.root);
3841

3942
useEffect(() => {
4043
if (root) {
@@ -87,10 +90,4 @@ const App = memo(({ root, isMasterDetail }: { root: string; isMasterDetail: bool
8790
</>
8891
);
8992
});
90-
const mapStateToProps = (state: any) => ({
91-
root: state.app.root,
92-
isMasterDetail: state.app.isMasterDetail
93-
});
94-
95-
const AppContainer = connect(mapStateToProps)(App);
96-
export default AppContainer;
93+
export default App;

app/actions/actionsTypes.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export const APP = createRequestTypes('APP', [
3939
'READY',
4040
'INIT',
4141
'INIT_LOCAL_SETTINGS',
42-
'SET_MASTER_DETAIL',
4342
'SET_NOTIFICATION_PRESENCE_CAP',
4443
'SET_NET_INFO_STATE'
4544
]);

app/actions/app.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ interface IAppStart extends Action {
99
text?: string;
1010
}
1111

12-
interface ISetMasterDetail extends Action {
13-
isMasterDetail: boolean;
14-
}
15-
1612
interface ISetNotificationPresenceCap extends Action {
1713
show: boolean;
1814
}
@@ -21,7 +17,7 @@ interface ISetNetInfoState extends Action {
2117
netInfoState: NetInfoStateType;
2218
}
2319

24-
export type TActionApp = IAppStart & ISetMasterDetail & ISetNotificationPresenceCap & ISetNetInfoState;
20+
export type TActionApp = IAppStart & ISetNotificationPresenceCap & ISetNetInfoState;
2521

2622
interface Params {
2723
root: RootEnum;
@@ -54,13 +50,6 @@ export function appInitLocalSettings(): Action {
5450
};
5551
}
5652

57-
export function setMasterDetail(isMasterDetail: boolean): ISetMasterDetail {
58-
return {
59-
type: APP.SET_MASTER_DETAIL,
60-
isMasterDetail
61-
};
62-
}
63-
6453
export function setNotificationPresenceCap(show: boolean): ISetNotificationPresenceCap {
6554
return {
6655
type: APP.SET_NOTIFICATION_PRESENCE_CAP,

app/containers/Header/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { type NativeStackHeaderProps } from '@react-navigation/native-stack';
55
import HeaderTitle from './components/HeaderTitle';
66
import HeaderContainer from './components/HeaderContainer';
77
import { isAndroid } from '../../lib/methods/helpers';
8-
import { useAppSelector } from '../../lib/hooks/useAppSelector';
8+
import { useMasterDetail } from '../../lib/hooks/useMasterDetail';
99
import { styles } from './styles';
1010
import { HeaderBackButton } from './components/HeaderBackButton';
1111

@@ -16,7 +16,7 @@ const Header = ({ options, navigation, route }: IHeader) => {
1616

1717
const { headerLeft, headerTitle, headerRight, title } = options;
1818
const [rightButtonsWidth, setRightButtonsWidth] = useState<number | null>(null);
19-
const isMasterDetail = useAppSelector(state => state.app.isMasterDetail);
19+
const isMasterDetail = useMasterDetail();
2020
const { fontScale } = useWindowDimensions();
2121
// It helps create an empty view to properly align the header when there is no component on the right.
2222
// 32.5 is the value I found that makes it work correctly on both platforms.

app/containers/InAppNotification/IncomingCallNotification/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { A11y } from 'react-native-a11y-order';
77
import { acceptCall, cancelCall } from '../../../actions/videoConf';
88
import { type ISubscription, type SubscriptionType } from '../../../definitions';
99
import i18n from '../../../i18n';
10-
import { useAppSelector } from '../../../lib/hooks/useAppSelector';
10+
import { useMasterDetail } from '../../../lib/hooks/useMasterDetail';
1111
import { useEndpointData } from '../../../lib/hooks/useEndpointData';
1212
import { hideNotification } from '../../../lib/methods/helpers/notifications';
1313
import { CustomIcon } from '../../CustomIcon';
@@ -39,7 +39,7 @@ const IncomingCallHeader = memo(
3939
const [cam, setCam] = useState(false);
4040
const [audio, setAudio] = useState(true);
4141
const dispatch = useDispatch();
42-
const isMasterDetail = useAppSelector(state => state.app.isMasterDetail);
42+
const isMasterDetail = useMasterDetail();
4343
const styles = useStyle();
4444
const insets = useSafeAreaInsets();
4545

app/containers/InAppNotification/NotifierComponent.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { memo } from 'react';
22
import { StyleSheet, Text, View } from 'react-native';
3-
import { connect } from 'react-redux';
43
import { useSafeAreaInsets } from 'react-native-safe-area-context';
54

65
import Avatar from '../Avatar';
@@ -9,9 +8,10 @@ import sharedStyles from '../../views/Styles';
98
import { themes } from '../../lib/constants/colors';
109
import { useTheme } from '../../theme';
1110
import { goRoom } from '../../lib/methods/helpers/goRoom';
12-
import { type IApplicationState, type ISubscription, type SubscriptionType } from '../../definitions';
11+
import { type ISubscription, type SubscriptionType } from '../../definitions';
1312
import { hideNotification } from '../../lib/methods/helpers/notifications';
1413
import { useResponsiveLayout } from '../../lib/hooks/useResponsiveLayout/useResponsiveLayout';
14+
import { withMasterDetail } from '../../lib/hooks/useMasterDetail';
1515
import Touch from '../Touch';
1616

1717
export interface INotifierComponent {
@@ -130,8 +130,4 @@ const NotifierComponent = memo(({ notification, isMasterDetail }: INotifierCompo
130130
);
131131
});
132132

133-
const mapStateToProps = (state: IApplicationState) => ({
134-
isMasterDetail: state.app.isMasterDetail
135-
});
136-
137-
export default connect(mapStateToProps)(NotifierComponent);
133+
export default withMasterDetail(NotifierComponent);

app/containers/List/List.stories.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as List from '.';
44
import SafeAreaView from '../SafeAreaView';
55
import { longText } from '../../../.rnstorybook/utils';
66
import { ThemeContext, type TSupportedThemes } from '../../theme';
7-
import { DimensionsContext } from '../../dimensions';
7+
import { ResponsiveLayoutContext } from '../../lib/hooks/useResponsiveLayout/useResponsiveLayout';
88
import { themes } from '../../lib/constants/colors';
99

1010
export default {
@@ -242,10 +242,10 @@ export const WithDarkTheme = () => <ThemeStory theme='dark' />;
242242
export const WithBlackTheme = () => <ThemeStory theme='black' />;
243243

244244
const FontStory = ({ fontScale }: { fontScale: number }) => (
245-
// @ts-ignore
246-
<DimensionsContext.Provider value={{ fontScale }}>
245+
// @ts-ignore - story overrides fontScale only; ListItem reads only that
246+
<ResponsiveLayoutContext.Provider value={{ fontScale }}>
247247
<ListFull />
248-
</DimensionsContext.Provider>
248+
</ResponsiveLayoutContext.Provider>
249249
);
250250

251251
/**

app/containers/MediaCallHeader/components/Content.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Pressable, StyleSheet, View } from 'react-native';
22

3-
import { useAppSelector } from '../../../lib/hooks/useAppSelector';
3+
import { useMasterDetail } from '../../../lib/hooks/useMasterDetail';
44
import { navigateToCallRoom } from '../../../lib/services/voip/navigateToCallRoom';
55
import { useCallStore } from '../../../lib/services/voip/useCallStore';
66
import Title from './Title';
@@ -20,7 +20,7 @@ const styles = StyleSheet.create({
2020
});
2121

2222
export const Content = () => {
23-
const isMasterDetail = useAppSelector(state => state.app.isMasterDetail);
23+
const isMasterDetail = useMasterDetail();
2424
const roomId = useCallStore(state => state.roomId);
2525
const contentDisabled = roomId == null;
2626
const pressableStyle = contentDisabled ? [styles.button, { opacity: 0.5 }] : styles.button;

app/containers/MessageActions/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
reportMessage
3737
} from '../../lib/services/restApi';
3838
import { createDirectMessage } from '../../lib/methods/createDirectMessage';
39+
import { withMasterDetail } from '../../lib/hooks/useMasterDetail';
3940

4041
// Extra delay on top of the action sheet animation so accessibility focus is restored
4142
// only after the sheet is fully dismissed.
@@ -618,7 +619,6 @@ const mapStateToProps = (state: IApplicationState) => ({
618619
Message_AllowPinning: state.settings.Message_AllowPinning as boolean,
619620
Message_AllowStarring: state.settings.Message_AllowStarring as boolean,
620621
Message_Read_Receipt_Store_Users: state.settings.Message_Read_Receipt_Store_Users as boolean,
621-
isMasterDetail: state.app.isMasterDetail,
622622
editMessagePermission: state.permissions['edit-message'],
623623
deleteMessagePermission: state.permissions['delete-message'],
624624
deleteOwnMessagePermission: state.permissions['delete-own-message'],
@@ -628,4 +628,4 @@ const mapStateToProps = (state: IApplicationState) => ({
628628
createDiscussionOtherUserPermission: state.permissions['start-discussion-other-user']
629629
});
630630

631-
export default connect(mapStateToProps, null, null, { forwardRef: true })(MessageActions);
631+
export default connect(mapStateToProps, null, null, { forwardRef: true })(withMasterDetail(MessageActions));

app/containers/MessageComposer/components/Buttons/ActionsButton.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { type TActionSheetOptionsItem, useActionSheet } from '../../../ActionShe
66
import { MessageInnerContext } from '../../context';
77
import I18n from '../../../../i18n';
88
import Navigation from '../../../../lib/navigation/appNavigation';
9-
import { useAppSelector } from '../../../../lib/hooks/useAppSelector';
9+
import { useMasterDetail } from '../../../../lib/hooks/useMasterDetail';
1010
import { usePermissions } from '../../../../lib/hooks/usePermissions';
1111
import { useCanUploadFile, useChooseMedia } from '../../hooks';
1212
import { useRoomContext } from '../../../../views/RoomView/context';
@@ -24,7 +24,7 @@ export const ActionsButton = () => {
2424
permissionToUpload
2525
});
2626
const { showActionSheet, hideActionSheet } = useActionSheet();
27-
const isMasterDetail = useAppSelector(state => state.app.isMasterDetail);
27+
const isMasterDetail = useMasterDetail();
2828

2929
const createDiscussion = async () => {
3030
if (!rid) return;

0 commit comments

Comments
 (0)