Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ import type {StackCardInterpolationProps} from '@react-navigation/stack';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import {isMobileSafari} from '@libs/Browser';
import Animations from '@libs/Navigation/PlatformStackNavigation/navigationOptions/animation';
import type {PlatformStackNavigationOptions} from '@libs/Navigation/PlatformStackNavigation/types';
import variables from '@styles/variables';
import CONFIG from '@src/CONFIG';
import hideKeyboardOnSwipe from './hideKeyboardOnSwipe';
import useModalCardStyleInterpolator from './useModalCardStyleInterpolator';

const IS_MOBILE_SAFARI = isMobileSafari();

type SplitNavigatorScreenOptions = {
sidebarScreen: PlatformStackNavigationOptions;
centralScreen: PlatformStackNavigationOptions;
Expand Down Expand Up @@ -51,10 +54,11 @@ const useSplitNavigatorScreenOptions = () => {
...hideKeyboardOnSwipe,
headerShown: false,
title: CONFIG.SITE_TITLE,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-13 (docs)

The isMobileSafari() function is called on every render of this hook since its not memoized. The function performs user agent string parsing which is expensive work that could be hoisted outside the hook.

Consider storing the result in a constant at module level:

const IS_MOBILE_SAFARI = isMobileSafari();

const useSplitNavigatorScreenOptions = () => {
    // ...
    animation: shouldUseNarrowLayout && !IS_MOBILE_SAFARI ? Animations.SLIDE_FROM_RIGHT : Animations.NONE,
    // ...
    animationEnabled: !IS_MOBILE_SAFARI
}

This pattern is already used elsewhere in the codebase (e.g., src/components/FlatList/index.tsx).


Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@paulnjs Please check this comment.

animation: shouldUseNarrowLayout ? Animations.SLIDE_FROM_RIGHT : Animations.NONE,
animation: shouldUseNarrowLayout && !IS_MOBILE_SAFARI ? Animations.SLIDE_FROM_RIGHT : Animations.NONE,
animationTypeForReplace: 'pop',
web: {
cardStyleInterpolator: (props: StackCardInterpolationProps) => modalCardStyleInterpolator({props, isFullScreenModal: true, shouldAnimateSidePanel: true}),
cardStyleInterpolator: (props: StackCardInterpolationProps) =>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-13 (docs)

The isMobileSafari() function is called again here, performing redundant user agent parsing on every render.

Use the same module-level constant suggested above:

const IS_MOBILE_SAFARI = isMobileSafari();

// In the hook:
modalCardStyleInterpolator({props, isFullScreenModal: true, shouldAnimateSidePanel: true, animationEnabled: !IS_MOBILE_SAFARI})

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@paulnjs Please check this comment.

modalCardStyleInterpolator({props, isFullScreenModal: true, shouldAnimateSidePanel: true, animationEnabled: !IS_MOBILE_SAFARI}),
cardStyle: shouldUseNarrowLayout ? StyleUtils.getNavigationModalCardStyle() : themeStyles.h100,
},
},
Expand Down
Loading