import React, { Children } from 'react' import { StyleSheet, Text, View } from 'react-native' import { StylesBaseVariant } from '../../utils/constants' interface IComposableRowProps{ container?: any, styles?: StylesBaseVariant errorTextStyles?:StylesBaseVariant setParentRef?:any; shiftFocus?:any; rowIndex?:any; } const ComposableRow:React.FC = (props) => { const [errorTextMap,setErrorTextMap] = React.useState({}) const [rowErrorText,setRowErrorText] = React.useState(''); const {children} = props const setErr = (index,error)=>{ setErrorTextMap((prev)=>({ ...prev, [index]:error })) }; React.useEffect(()=>{ const length = React.Children.toArray(children).length; let errorText = ''; for(let i = 0;i { return React.Children.map(children, (child,index) => { if (!React.isValidElement(child)) return child; return React.cloneElement(child, {containerMethods:{ setErrorText: (errorText)=>{setErr(index,errorText)}, setRef:(ref,id)=>{props?.setParentRef(props.rowIndex+index,ref,id)}, shiftFocus:props?.shiftFocus } } as Partial) }) }; return ( {iterateOverChildren(children)} {rowErrorText} ) } const DEFAULT_ROW_STYLES = StyleSheet.create({ base:{ display:'flex', flexDirection:'row', } }); export default ComposableRow;