diff --git a/__mocks__/react-native-safe-area-context.js b/__mocks__/react-native-safe-area-context.js deleted file mode 100644 index b31ed670b81c..000000000000 --- a/__mocks__/react-native-safe-area-context.js +++ /dev/null @@ -1,52 +0,0 @@ -import React, {forwardRef} from 'react'; -import {View} from 'react-native'; - -const insets = { - top: 0, - right: 0, - bottom: 0, - left: 0, -}; - -function withSafeAreaInsets(WrappedComponent) { - function WithSafeAreaInsets(props) { - return ( - - ); - } - - const WithSafeAreaInsetsWithRef = forwardRef((props, ref) => ( - - )); - - WithSafeAreaInsetsWithRef.displayName = 'WithSafeAreaInsetsWithRef'; - - return WithSafeAreaInsetsWithRef; -} - -const SafeAreaView = View; -const SafeAreaProvider = (props) => props.children; -const SafeAreaConsumer = (props) => props.children(insets); -const SafeAreaInsetsContext = { - Consumer: SafeAreaConsumer, -}; - -const useSafeAreaFrame = jest.fn(() => ({ - x: 0, - y: 0, - width: 390, - height: 844, -})); -const useSafeAreaInsets = jest.fn(() => insets); - -export {SafeAreaProvider, SafeAreaConsumer, SafeAreaInsetsContext, withSafeAreaInsets, SafeAreaView, useSafeAreaFrame, useSafeAreaInsets}; diff --git a/__mocks__/react-native-safe-area-context.tsx b/__mocks__/react-native-safe-area-context.tsx new file mode 100644 index 000000000000..b789c90f87e8 --- /dev/null +++ b/__mocks__/react-native-safe-area-context.tsx @@ -0,0 +1,61 @@ +import type {ForwardedRef, ReactNode} from 'react'; +import React, {forwardRef} from 'react'; +import {View} from 'react-native'; +import type {EdgeInsets, useSafeAreaFrame as LibUseSafeAreaFrame, WithSafeAreaInsetsProps} from 'react-native-safe-area-context'; +import type ChildrenProps from '@src/types/utils/ChildrenProps'; + +type SafeAreaProviderProps = ChildrenProps; +type SafeAreaConsumerProps = { + children?: (insets: EdgeInsets) => ReactNode; +}; +type SafeAreaInsetsContextValue = { + Consumer: (props: SafeAreaConsumerProps) => ReactNode; +}; + +const insets: EdgeInsets = { + top: 0, + right: 0, + bottom: 0, + left: 0, +}; + +function withSafeAreaInsets(WrappedComponent: React.ComponentType}>) { + function WithSafeAreaInsets(props: WithSafeAreaInsetsProps & {forwardedRef: React.ForwardedRef}) { + return ( + + ); + } + + const WithSafeAreaInsetsWithRef = forwardRef((props: WithSafeAreaInsetsProps, ref: ForwardedRef) => ( + + )); + + return WithSafeAreaInsetsWithRef; +} + +const SafeAreaView = View; +const SafeAreaProvider = (props: SafeAreaProviderProps) => props.children; +const SafeAreaConsumer = (props: SafeAreaConsumerProps) => props.children?.(insets); +const SafeAreaInsetsContext: SafeAreaInsetsContextValue = { + Consumer: SafeAreaConsumer, +}; + +const useSafeAreaFrame: jest.Mock> = jest.fn(() => ({ + x: 0, + y: 0, + width: 390, + height: 844, +})); +const useSafeAreaInsets: jest.Mock = jest.fn(() => insets); + +export {SafeAreaProvider, SafeAreaConsumer, SafeAreaInsetsContext, withSafeAreaInsets, SafeAreaView, useSafeAreaFrame, useSafeAreaInsets};