diff --git a/src/components/MoneyRequestReportView/useMoneyRequestReportScroll.ts b/src/components/MoneyRequestReportView/useMoneyRequestReportScroll.ts index 886dca0b06d2..101c14c16b6a 100644 --- a/src/components/MoneyRequestReportView/useMoneyRequestReportScroll.ts +++ b/src/components/MoneyRequestReportView/useMoneyRequestReportScroll.ts @@ -15,8 +15,9 @@ import {subscribeToNewActionEvent} from '@userActions/Report/reportActionSubscri import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type * as OnyxTypes from '@src/types/onyx'; +import type {ViewToken} from '@src/types/utils/ReactNativeCompat'; -import type {LayoutChangeEvent, NativeScrollEvent, NativeSyntheticEvent, ViewToken} from 'react-native'; +import type {LayoutChangeEvent, NativeScrollEvent, NativeSyntheticEvent} from 'react-native'; import {guidedSetupAndTourStatusSelector} from '@selectors/Onboarding'; import {useEffect, useEffectEvent, useRef} from 'react'; diff --git a/src/hooks/useThumbnailDimensions.ts b/src/hooks/useThumbnailDimensions.ts index 8327098eeb0d..d3262ebe2c0e 100644 --- a/src/hooks/useThumbnailDimensions.ts +++ b/src/hooks/useThumbnailDimensions.ts @@ -1,7 +1,6 @@ import CONST from '@src/CONST'; -import type {StyleProp, ViewStyle} from 'react-native'; -import type {DimensionValue} from 'react-native/Libraries/StyleSheet/StyleSheetTypes'; +import type {DimensionValue, StyleProp, ViewStyle} from 'react-native'; import useIsInSidePanel from './useIsInSidePanel'; import useResponsiveLayout from './useResponsiveLayout'; diff --git a/src/pages/inbox/report/ReportActionCompose/useComposerSuggestions.ts b/src/pages/inbox/report/ReportActionCompose/useComposerSuggestions.ts index c3768f5d8b11..57c70e010611 100644 --- a/src/pages/inbox/report/ReportActionCompose/useComposerSuggestions.ts +++ b/src/pages/inbox/report/ReportActionCompose/useComposerSuggestions.ts @@ -3,11 +3,12 @@ import type {ComposerRef, TextSelection} from '@components/Composer/types'; import useIsScrollLikelyLayoutTriggered from '@hooks/useIsScrollLikelyLayoutTriggered'; +import type {TextInputScrollEvent} from '@src/types/utils/ReactNativeCompat'; // eslint-disable-next-line no-restricted-imports import findNodeHandle from '@src/utils/findNodeHandle'; import type {RefObject} from 'react'; -import type {MeasureInWindowOnSuccessCallback, TextInputScrollEvent} from 'react-native'; +import type {MeasureInWindowOnSuccessCallback} from 'react-native'; import {useEffect, useRef} from 'react'; import {useFocusedInputHandler} from 'react-native-keyboard-controller'; diff --git a/src/pages/inbox/report/ReportActionsList/useReportActionsListScroll.ts b/src/pages/inbox/report/ReportActionsList/useReportActionsListScroll.ts index e4de34fece9d..e85bd86780fa 100644 --- a/src/pages/inbox/report/ReportActionsList/useReportActionsListScroll.ts +++ b/src/pages/inbox/report/ReportActionsList/useReportActionsListScroll.ts @@ -12,8 +12,9 @@ import useScrollToEditingReportAction from '@pages/inbox/report/useScrollToEditi import CONST from '@src/CONST'; import type * as OnyxTypes from '@src/types/onyx'; +import type {ViewToken} from '@src/types/utils/ReactNativeCompat'; -import type {LayoutChangeEvent, NativeScrollEvent, NativeSyntheticEvent, ViewToken} from 'react-native'; +import type {LayoutChangeEvent, NativeScrollEvent, NativeSyntheticEvent} from 'react-native'; import {useEffect, useRef} from 'react'; @@ -149,7 +150,7 @@ function useReportActionsListScroll({ }; const trackViewableRowIndexes = (info: {viewableItems: ViewToken[]; changed: ViewToken[]}) => { - viewableRowIndexesRef.current = new Set(info.viewableItems.map((token) => token.index).filter((index) => index !== null)); + viewableRowIndexesRef.current = new Set(info.viewableItems.map((token) => token.index).filter((index) => typeof index === 'number')); onViewableItemsChanged(info); }; diff --git a/src/pages/inbox/sidebar/ProfileAvatarWithIndicator.tsx b/src/pages/inbox/sidebar/ProfileAvatarWithIndicator.tsx index 2894c67b62c9..60a09cb7804e 100644 --- a/src/pages/inbox/sidebar/ProfileAvatarWithIndicator.tsx +++ b/src/pages/inbox/sidebar/ProfileAvatarWithIndicator.tsx @@ -16,8 +16,7 @@ import type {AvatarSizeName} from '@styles/utils/types'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {StyleProp} from 'react-native'; -import type {ViewStyle} from 'react-native/Libraries/StyleSheet/StyleSheetTypes'; +import type {StyleProp, ViewStyle} from 'react-native'; import React from 'react'; import {View} from 'react-native'; diff --git a/src/pages/workspace/members/ImportedMembersConfirmationPage.tsx b/src/pages/workspace/members/ImportedMembersConfirmationPage.tsx index d28c6236a5d9..66ac1a6084da 100644 --- a/src/pages/workspace/members/ImportedMembersConfirmationPage.tsx +++ b/src/pages/workspace/members/ImportedMembersConfirmationPage.tsx @@ -37,8 +37,8 @@ import ROUTES, {DYNAMIC_ROUTES} from '@src/ROUTES'; import SCREENS from '@src/SCREENS'; import type {Rule} from '@src/types/onyx'; +import type {GestureResponderEvent} from 'react-native'; import type {OnyxCollection} from 'react-native-onyx'; -import type {GestureResponderEvent} from 'react-native/Libraries/Types/CoreEventTypes'; import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react'; import {View} from 'react-native'; diff --git a/src/pages/workspace/members/WorkspaceInviteMessageComponent.tsx b/src/pages/workspace/members/WorkspaceInviteMessageComponent.tsx index 6dd1823efea8..d2784d2aaf51 100644 --- a/src/pages/workspace/members/WorkspaceInviteMessageComponent.tsx +++ b/src/pages/workspace/members/WorkspaceInviteMessageComponent.tsx @@ -57,8 +57,8 @@ import type {CurrentUserPersonalDetails} from '@src/types/onyx/PersonalDetails'; import type Policy from '@src/types/onyx/Policy'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; +import type {GestureResponderEvent} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; -import type {GestureResponderEvent} from 'react-native/Libraries/Types/CoreEventTypes'; import {Str} from 'expensify-common'; import React, {useEffect, useState} from 'react'; diff --git a/src/styles/utils/index.ts b/src/styles/utils/index.ts index c6044bcbc71c..1e8e931823a0 100644 --- a/src/styles/utils/index.ts +++ b/src/styles/utils/index.ts @@ -15,7 +15,7 @@ import type {Dimensions} from '@src/types/utils/Layout'; import type Nullable from '@src/types/utils/Nullable'; // eslint-disable-next-line no-restricted-imports -import type {AnimatableNumericValue, Animated, ColorValue, DimensionValue, ImageStyle, PressableStateCallbackType, StyleProp, TextStyle, ViewStyle} from 'react-native'; +import type {Animated, ColorValue, DimensionValue, ImageStyle, PressableStateCallbackType, StyleProp, TextStyle, ViewStyle} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; import type {EdgeInsets} from 'react-native-safe-area-context'; import type {ValueOf} from 'type-fest'; @@ -1120,7 +1120,7 @@ function getEmojiReactionBubbleTextStyle(isContextMenu = false): TextStyle { }; } -function getTransformScaleStyle(scaleValue: AnimatableNumericValue): ViewStyle { +function getTransformScaleStyle(scaleValue: number): ViewStyle { return { transform: [{scale: scaleValue}], }; diff --git a/src/types/utils/ReactNativeCompat.ts b/src/types/utils/ReactNativeCompat.ts index a739182744af..dc420662ac68 100644 --- a/src/types/utils/ReactNativeCompat.ts +++ b/src/types/utils/ReactNativeCompat.ts @@ -1,10 +1,10 @@ /** - * Stand-ins for root type exports the RN Strict TypeScript API removes. - * Derived from FlatList props so the same aliases typecheck on 0.86 and the Strict API. - * The generic is phantom under the Strict API: VirtualizedListProps is not generic there (`Item = any`), + * Stand-ins for type exports the RN Strict TypeScript API removes or hides behind deep imports. + * Each one is derived from a public prop or API signature so the same alias typechecks on 0.86 and the Strict API. + * The FlatList generic is phantom under the Strict API: VirtualizedListProps is not generic there (`Item = any`), * so `T` is ignored and `viewableItems[].item` widens from `unknown` to `any` after the flip. */ -import type {FlatListProps} from 'react-native'; +import type {BackHandler, FlatListProps, TextInputProps} from 'react-native'; type ViewableItemsChanged = NonNullable['onViewableItemsChanged']>; @@ -14,4 +14,9 @@ type ViewabilityConfig = NonNullable['viewabilityConfig'] type CellRendererProps = NonNullable['CellRendererComponent']> extends React.ComponentType ? P : never; -export type {CellRendererProps, ViewabilityConfig, ViewableItemsChanged, ViewToken}; +type TextInputScrollEvent = Parameters>[0]; + +/** Only reachable through `react-native/Libraries/Utilities/BackHandler`, which the Strict API blocks */ +type HardwareBackPressEvent = Parameters[1]>[0]; + +export type {CellRendererProps, HardwareBackPressEvent, TextInputScrollEvent, ViewabilityConfig, ViewableItemsChanged, ViewToken}; diff --git a/src/utils/findNodeHandle/index.ts b/src/utils/findNodeHandle/index.ts index 6be2ecefe395..98d58d94cbaa 100644 --- a/src/utils/findNodeHandle/index.ts +++ b/src/utils/findNodeHandle/index.ts @@ -1,9 +1,8 @@ import type {Component, ComponentClass} from 'react'; -import type {NodeHandle} from 'react-native/Libraries/ReactNative/RendererProxy'; /** Don't add new `findNodeHandle` usages, this is only a temporary solution. We're going to remove the function in the future */ // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any -function findNodeHandle(componentOrHandle: null | number | Component | ComponentClass): null | NodeHandle { +function findNodeHandle(componentOrHandle: null | number | Component | ComponentClass): null | number { // eslint-disable-next-line no-console console.warn('findNodeHandle is not supported on web. Use the ref property of the component instead.'); return null; diff --git a/tests/ui/WorkEmailOnboardingNativeBack.tsx b/tests/ui/WorkEmailOnboardingNativeBack.tsx index e6cc33b0981e..bb7aebf2d6fa 100644 --- a/tests/ui/WorkEmailOnboardingNativeBack.tsx +++ b/tests/ui/WorkEmailOnboardingNativeBack.tsx @@ -28,9 +28,9 @@ import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import SCREENS from '@src/SCREENS'; import type {Onboarding} from '@src/types/onyx'; +import type {HardwareBackPressEvent} from '@src/types/utils/ReactNativeCompat'; import type {OnyxEntry} from 'react-native-onyx'; -import type {HardwareBackPressEvent} from 'react-native/Libraries/Utilities/BackHandler'; import {PortalProvider} from '@gorhom/portal'; import {NavigationContainer, StackActions} from '@react-navigation/native'; diff --git a/tests/unit/hooks/useDiscardChangesConfirmationNative.test.ts b/tests/unit/hooks/useDiscardChangesConfirmationNative.test.ts index f832b774b768..58b15963c8b3 100644 --- a/tests/unit/hooks/useDiscardChangesConfirmationNative.test.ts +++ b/tests/unit/hooks/useDiscardChangesConfirmationNative.test.ts @@ -3,7 +3,7 @@ import {act, renderHook} from '@testing-library/react-native'; import type {DiscardChangesConfirmation} from '@hooks/useDiscardChangesConfirmation/types'; import type UseDiscardChangesConfirmationOptions from '@hooks/useDiscardChangesConfirmation/types'; -import type {HardwareBackPressEvent} from 'react-native/Libraries/Utilities/BackHandler'; +import type {HardwareBackPressEvent} from '@src/types/utils/ReactNativeCompat'; import {BackHandler} from 'react-native';