Skip to content

Commit

Permalink
Merge pull request #37155 from margelo/kiryl/fix-broken-search-screen…
Browse files Browse the repository at this point in the history
…-on-android

fix: broken search screen on Android
  • Loading branch information
rlinoz authored Feb 26, 2024
2 parents f83ebde + b6f71a1 commit 407679d
Showing 1 changed file with 40 additions and 31 deletions.
71 changes: 40 additions & 31 deletions src/libs/Navigation/AppNavigator/ModalStackNavigators.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type {ParamListBase} from '@react-navigation/routers';
import type {StackNavigationOptions} from '@react-navigation/stack';
import {createStackNavigator} from '@react-navigation/stack';
import React, {useMemo} from 'react';
import useThemeStyles from '@hooks/useThemeStyles';
import createPlatformStackNavigator from '@libs/Navigation/PlatformStackNavigation/createPlatformStackNavigator';
Expand Down Expand Up @@ -45,38 +46,46 @@ type Screens = Partial<Record<Screen, () => React.ComponentType>>;
* @param screens key/value pairs where the key is the name of the screen and the value is a functon that returns the lazy-loaded component
* @param getScreenOptions optional function that returns the screen options, override the default options
*/
function createModalStackNavigator<TStackParams extends ParamListBase>(screens: Screens, getScreenOptions?: (styles: ThemeStyles) => StackNavigationOptions): React.ComponentType {
const ModalStackNavigator = createPlatformStackNavigator<TStackParams>();

function ModalStack() {
const styles = useThemeStyles();

const defaultSubRouteOptions = useMemo(
(): StackNavigationOptions => ({
...subRouteOptions,
cardStyle: styles.navigationScreenCardStyle,
}),
[styles],
);

return (
<ModalStackNavigator.Navigator screenOptions={getScreenOptions?.(styles) ?? defaultSubRouteOptions}>
{Object.keys(screens as Required<Screens>).map((name) => (
<ModalStackNavigator.Screen
key={name}
name={name}
getComponent={(screens as Required<Screens>)[name as Screen]}
/>
))}
</ModalStackNavigator.Navigator>
);
}

ModalStack.displayName = 'ModalStack';

return ModalStack;
function createModalStackNavigatorFactory(factory: typeof createPlatformStackNavigator) {
return function createNestedModalStackNavigator<TStackParams extends ParamListBase>(
screens: Screens,
getScreenOptions?: (styles: ThemeStyles) => StackNavigationOptions,
): React.ComponentType {
const ModalStackNavigator = factory<TStackParams>();

function ModalStack() {
const styles = useThemeStyles();

const defaultSubRouteOptions = useMemo(
(): StackNavigationOptions => ({
...subRouteOptions,
cardStyle: styles.navigationScreenCardStyle,
}),
[styles],
);

return (
<ModalStackNavigator.Navigator screenOptions={getScreenOptions?.(styles) ?? defaultSubRouteOptions}>
{Object.keys(screens as Required<Screens>).map((name) => (
<ModalStackNavigator.Screen
key={name}
name={name}
getComponent={(screens as Required<Screens>)[name as Screen]}
/>
))}
</ModalStackNavigator.Navigator>
);
}

ModalStack.displayName = 'ModalStack';

return ModalStack;
};
}

const createModalStackNavigator = createModalStackNavigatorFactory(createPlatformStackNavigator);
const createJSModalStackNavigator = createModalStackNavigatorFactory(createStackNavigator);

const MoneyRequestModalStackNavigator = createModalStackNavigator<MoneyRequestNavigatorParamList>({
[SCREENS.MONEY_REQUEST.START]: () => require('../../../pages/iou/request/IOURequestRedirectToStartPage').default as React.ComponentType,
[SCREENS.MONEY_REQUEST.CREATE]: () => require('../../../pages/iou/request/IOURequestStartPage').default as React.ComponentType,
Expand Down Expand Up @@ -156,7 +165,7 @@ const RoomInviteModalStackNavigator = createModalStackNavigator<RoomInviteNaviga
[SCREENS.ROOM_INVITE_ROOT]: () => require('../../../pages/RoomInvitePage').default as React.ComponentType,
});

const SearchModalStackNavigator = createModalStackNavigator<SearchNavigatorParamList>({
const SearchModalStackNavigator = createJSModalStackNavigator<SearchNavigatorParamList>({
[SCREENS.SEARCH_ROOT]: () => require('../../../pages/SearchPage').default as React.ComponentType,
});

Expand Down

0 comments on commit 407679d

Please sign in to comment.