Skip to content

Commit

Permalink
remove withNavigationFocus HOC
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardoj committed Jan 23, 2025
1 parent 523edfe commit 21d67d1
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 83 deletions.
9 changes: 3 additions & 6 deletions src/components/AvatarWithImagePicker.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {useIsFocused} from '@react-navigation/native';
import React, {useCallback, useEffect, useRef, useState} from 'react';
import {StyleSheet, View} from 'react-native';
import type {ImageStyle, StyleProp, ViewStyle} from 'react-native';
Expand Down Expand Up @@ -27,7 +28,6 @@ import OfflineWithFeedback from './OfflineWithFeedback';
import PopoverMenu from './PopoverMenu';
import PressableWithoutFeedback from './Pressable/PressableWithoutFeedback';
import Tooltip from './Tooltip';
import withNavigationFocus from './withNavigationFocus';

type ErrorData = {
validationError?: TranslationPaths | null | '';
Expand Down Expand Up @@ -107,9 +107,6 @@ type AvatarWithImagePickerProps = {
/** File name of the avatar */
originalFileName?: string;

/** Whether navigation is focused */
isFocused: boolean;

/** Style applied to the avatar */
avatarStyle: StyleProp<ViewStyle & ImageStyle>;

Expand All @@ -133,7 +130,6 @@ type AvatarWithImagePickerProps = {
};

function AvatarWithImagePicker({
isFocused,
DefaultAvatar = () => null,
style,
disabledStyle,
Expand Down Expand Up @@ -164,6 +160,7 @@ function AvatarWithImagePicker({
}: AvatarWithImagePickerProps) {
const theme = useTheme();
const styles = useThemeStyles();
const isFocused = useIsFocused();
const {windowWidth} = useWindowDimensions();
const [popoverPosition, setPopoverPosition] = useState({horizontal: 0, vertical: 0});
const [isMenuVisible, setIsMenuVisible] = useState(false);
Expand Down Expand Up @@ -466,4 +463,4 @@ function AvatarWithImagePicker({

AvatarWithImagePicker.displayName = 'AvatarWithImagePicker';

export default withNavigationFocus(AvatarWithImagePicker);
export default AvatarWithImagePicker;
19 changes: 7 additions & 12 deletions src/components/SignInButtons/AppleSignIn/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {useIsFocused} from '@react-navigation/native';
import React, {useEffect, useState} from 'react';
import type {NativeConfig} from 'react-native-config';
import Config from 'react-native-config';
import getUserLanguage from '@components/SignInButtons/GetUserLanguage';
import type {WithNavigationFocusProps} from '@components/withNavigationFocus';
import withNavigationFocus from '@components/withNavigationFocus';
import Log from '@libs/Log';
import * as Session from '@userActions/Session';

Check failure on line 7 in src/components/SignInButtons/AppleSignIn/index.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Namespace imports from @userActions are not allowed. Use named imports instead. Example: import { action } from "@userActions/module"
import CONFIG from '@src/CONFIG';
Expand All @@ -19,11 +18,9 @@ type AppleSignInDivProps = {
onPointerDown?: () => void;
};

type SingletonAppleSignInButtonProps = AppleSignInDivProps & {
isFocused: boolean;
};
type SingletonAppleSignInButtonProps = AppleSignInDivProps;

type AppleSignInProps = WithNavigationFocusProps & {
type AppleSignInProps = {
isDesktopFlow?: boolean;
onPointerDown?: () => void;
// eslint-disable-next-line react/no-unused-prop-types
Expand Down Expand Up @@ -110,7 +107,8 @@ function AppleSignInDiv({isDesktopFlow, onPointerDown}: AppleSignInDivProps) {
// The Sign in with Apple script may fail to render button if there are multiple
// of these divs present in the app, as it matches based on div id. So we'll
// only mount the div when it should be visible.
function SingletonAppleSignInButton({isFocused, isDesktopFlow, onPointerDown}: SingletonAppleSignInButtonProps) {
function SingletonAppleSignInButton({isDesktopFlow, onPointerDown}: SingletonAppleSignInButtonProps) {
const isFocused = useIsFocused();
if (!isFocused) {
return null;
}
Expand All @@ -122,9 +120,6 @@ function SingletonAppleSignInButton({isFocused, isDesktopFlow, onPointerDown}: S
);
}

// withNavigationFocus is used to only render the button when it is visible.
const SingletonAppleSignInButtonWithFocus = withNavigationFocus(SingletonAppleSignInButton);

function AppleSignIn({isDesktopFlow = false, onPointerDown}: AppleSignInProps) {
const [scriptLoaded, setScriptLoaded] = useState(false);
useEffect(() => {
Expand All @@ -146,13 +141,13 @@ function AppleSignIn({isDesktopFlow = false, onPointerDown}: AppleSignInProps) {
}

return (
<SingletonAppleSignInButtonWithFocus
<SingletonAppleSignInButton
isDesktopFlow={isDesktopFlow}
onPointerDown={onPointerDown}
/>
);
}

AppleSignIn.displayName = 'AppleSignIn';
export default withNavigationFocus(AppleSignIn);
export default AppleSignIn;
export type {AppleSignInProps};
29 changes: 0 additions & 29 deletions src/components/withNavigationFocus.tsx

This file was deleted.

19 changes: 1 addition & 18 deletions tests/perf-test/ReportActionCompose.perf-test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {fireEvent, screen} from '@testing-library/react-native';
import type {ComponentType, EffectCallback} from 'react';
import type {EffectCallback} from 'react';
import React from 'react';
import Onyx from 'react-native-onyx';
import type Animated from 'react-native-reanimated';
import {measureRenders} from 'reassure';
import type {WithNavigationFocusProps} from '@components/withNavigationFocus';
import type {EmojiPickerRef} from '@libs/actions/EmojiPickerAction';
import type Navigation from '@libs/Navigation/Navigation';
import ComposeProviders from '@src/components/ComposeProviders';
Expand Down Expand Up @@ -59,22 +58,6 @@ jest.mock('@src/libs/actions/EmojiPickerAction', () => {
};
});

jest.mock('@src/components/withNavigationFocus', <TProps extends WithNavigationFocusProps>() => (Component: ComponentType<TProps>) => {
function WithNavigationFocus(props: Omit<TProps, keyof WithNavigationFocusProps>) {
return (
<Component
// eslint-disable-next-line react/jsx-props-no-spreading
{...(props as TProps)}
isFocused={false}
/>
);
}

WithNavigationFocus.displayName = 'WithNavigationFocus';

return WithNavigationFocus;
});

beforeAll(() =>
Onyx.init({
keys: ONYXKEYS,
Expand Down
18 changes: 0 additions & 18 deletions tests/perf-test/SearchRouter.perf-test.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import type * as NativeNavigation from '@react-navigation/native';
import {fireEvent, screen} from '@testing-library/react-native';
import React, {useMemo} from 'react';
import type {ComponentType} from 'react';
import Onyx from 'react-native-onyx';
import {measureRenders} from 'reassure';
import {LocaleContextProvider} from '@components/LocaleContextProvider';
import {OptionsListContext} from '@components/OptionListContextProvider';
import SearchRouter from '@components/Search/SearchRouter/SearchRouter';
import SearchRouterInput from '@components/Search/SearchRouter/SearchRouterInput';
import type {WithNavigationFocusProps} from '@components/withNavigationFocus';
import {createOptionList} from '@libs/OptionsListUtils';
import ComposeProviders from '@src/components/ComposeProviders';
import OnyxProvider from '@src/components/OnyxProvider';
Expand Down Expand Up @@ -71,22 +69,6 @@ jest.mock('@react-navigation/native', () => {
};
});

jest.mock('@src/components/withNavigationFocus', () => (Component: ComponentType<WithNavigationFocusProps>) => {
function WithNavigationFocus(props: WithNavigationFocusProps) {
return (
<Component
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
isFocused={false}
/>
);
}

WithNavigationFocus.displayName = 'WithNavigationFocus';

return WithNavigationFocus;
});

const getMockedReports = (length = 100) =>
createCollection<Report>(
(item) => `${ONYXKEYS.COLLECTION.REPORT}${item.reportID}`,
Expand Down

0 comments on commit 21d67d1

Please sign in to comment.