import { HeapIgnore } from '@contentsquare/react-native-autocapture'; import React from 'react'; import { Platform } from 'react-native'; import { CSQMaskProps } from '../../types/types'; import { getComponentDisplayName, getHeapIgnoreProps } from '../../utils/utils'; const CSQMaskedView = Platform.OS === 'ios' ? require('../../core/specs/CSQMaskedViewNativeComponent').default : require('./CSQMaskedView').default; const CSQUnmaskedView = Platform.OS === 'ios' ? require('../../core/specs/CSQUnmaskedViewNativeComponent').default : require('./CSQUnmaskedView').default; type ParentProps = { children: React.ReactNode; }; export const withCSQMask = ( WrappedComponent: React.JSXElementConstructor

, maskOptions?: CSQMaskProps ) => { const WithCSQMask = (props: P & ParentProps, ref: React.Ref) => { const { isSessionReplayMasked = true } = maskOptions || {}; const heapIgnoreProps = getHeapIgnoreProps(maskOptions); const CSQComponent = isSessionReplayMasked ? CSQMaskedView : CSQUnmaskedView; return ( {props.children} ); }; const displayName = `withCSQMask(${getComponentDisplayName( WrappedComponent, 'WrappedComponent' )})`; WithCSQMask.displayName = displayName; // @ts-expect-error - TypeScript has difficulty inferring the correct types for forwardRef with generic props const ForwardedComponent = React.forwardRef(WithCSQMask); ForwardedComponent.displayName = displayName; return ForwardedComponent; };