import type { TextRef, ViewRef } from '@rn-primitives/types'; import * as React from 'react'; import { TextProps, View, ViewProps } from 'react-native'; import { Text, TextClassContext } from '@/components/ui/text'; import { cn } from '@/lib/utils'; // Extended ViewProps interface that includes children interface ViewPropsWithChildren extends ViewProps { children?: React.ReactNode; } // Helper function to recursively wrap text nodes in Text components const wrapTextNodes = (children: React.ReactNode): React.ReactNode => { // If it's a string or number, wrap it in a Text component if (typeof children === 'string' || typeof children === 'number') { return {children}; } // If it's an array, map over it and recursively wrap each child if (Array.isArray(children)) { return children.map((child, index) => ( {wrapTextNodes(child)} )); } // If it's a React element if (React.isValidElement(children)) { // If it's already a Text component or a native element, return it as is if (children.type === Text || typeof children.type === 'string') { return children; } // Otherwise, recursively wrap its children if (children.props.children) { return React.cloneElement( children, { ...children.props }, wrapTextNodes(children.props.children) ); } } // For everything else, return as is return children; }; const Card = React.forwardRef(({ className, children, ...props }, ref) => { return ( {wrapTextNodes(children)} ); }); Card.displayName = 'Card'; const CardHeader = React.forwardRef(({ className, children, ...props }, ref) => { return ( {wrapTextNodes(children)} ); }); CardHeader.displayName = 'CardHeader'; const CardTitle = React.forwardRef>( ({ className, ...props }, ref) => ( ) ); CardTitle.displayName = 'CardTitle'; const CardDescription = React.forwardRef(({ className, ...props }, ref) => ( )); CardDescription.displayName = 'CardDescription'; const CardContent = React.forwardRef(({ className, children, ...props }, ref) => { return ( {wrapTextNodes(children)} ); }); CardContent.displayName = 'CardContent'; const CardFooter = React.forwardRef(({ className, children, ...props }, ref) => { return ( {wrapTextNodes(children)} ); }); CardFooter.displayName = 'CardFooter'; export { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle };