import React, { FC, forwardRef } from 'react' import { Controller } from 'react-hook-form' import type { TextInput, TextInputProps } from 'react-native' import type { WithNativeControllerProps } from './types' // TODO: consider moving this to @baseapp-frontend/utils const withNativeController = (Component: FC) => forwardRef>( ({ name, control, helperText, ...props }, ref) => { if (control) { const { onChangeText, onBlur, ...restOfTheProps } = props return ( { const handleOnChangeText = (text: string) => { field.onChange(text) onChangeText?.(text) } const handleOnBlur = () => { field.onBlur() onBlur?.() } return ( ) }} /> ) } return ( ) }, ) export default withNativeController