import React, { Component, PropsWithChildren } from 'react'; import { View, StyleProp, ViewStyle } from 'react-native'; type TableProps = { style?: StyleProp; borderStyle?: ViewStyle; testID?: string; }; export class Table extends Component> { _renderChildren(props: PropsWithChildren) { return React.Children.map(props.children, child => { if (React.isValidElement(child)) { return React.cloneElement<{borderStyle: any} | {}>( child, props.borderStyle && (child.type as React.FunctionComponent).displayName !== 'ScrollView' ? { borderStyle: props.borderStyle } : {} ); } }); } render() { const { borderStyle } = this.props; const borderLeftWidth = (borderStyle && borderStyle.borderWidth) || 0; const borderBottomWidth = borderLeftWidth; const borderColor = (borderStyle && borderStyle.borderColor) || '#000'; return ( {this._renderChildren(this.props)} ); } } type TableWrapperProps = { style?: StyleProp; borderStyle?: ViewStyle; testID?: string; }; export class TableWrapper extends Component> { _renderChildren(props: PropsWithChildren) { return React.Children.map(props.children, child => React.cloneElement(child as React.ReactElement, props.borderStyle ? { borderStyle: props.borderStyle } : {}) ); } render() { const { style, testID } = this.props; return {this._renderChildren(this.props)}; } }