Fix ref forwarding in web

zio/stable
Paul Frazee 2023-02-22 21:21:17 -06:00
parent f28334739b
commit 2db7ad8ef3
1 changed files with 34 additions and 21 deletions

View File

@ -33,26 +33,13 @@ export function CenteredView({
return <View style={style} {...props} /> return <View style={style} {...props} />
} }
export function FlatList<ItemT>({ export const FlatList = React.forwardRef(function <ItemT>(
{
contentContainerStyle, contentContainerStyle,
...props ...props
}: React.PropsWithChildren<FlatListProps<ItemT>>) { }: React.PropsWithChildren<FlatListProps<ItemT>>,
const theme = useTheme() ref: React.Ref<RNFlatList>,
contentContainerStyle = addStyle( ) {
contentContainerStyle,
styles.containerScroll,
)
contentContainerStyle = addStyle(
contentContainerStyle,
theme.colorScheme === 'dark' ? styles.containerDark : styles.containerLight,
)
return <RNFlatList contentContainerStyle={contentContainerStyle} {...props} />
}
export function ScrollView({
contentContainerStyle,
...props
}: React.PropsWithChildren<ScrollViewProps>) {
const theme = useTheme() const theme = useTheme()
contentContainerStyle = addStyle( contentContainerStyle = addStyle(
contentContainerStyle, contentContainerStyle,
@ -63,9 +50,35 @@ export function ScrollView({
theme.colorScheme === 'dark' ? styles.containerDark : styles.containerLight, theme.colorScheme === 'dark' ? styles.containerDark : styles.containerLight,
) )
return ( return (
<RNScrollView contentContainerStyle={contentContainerStyle} {...props} /> <RNFlatList
contentContainerStyle={contentContainerStyle}
ref={ref}
{...props}
/>
) )
} })
export const ScrollView = React.forwardRef(function (
{contentContainerStyle, ...props}: React.PropsWithChildren<ScrollViewProps>,
ref: React.Ref<RNFlatList>,
) {
const theme = useTheme()
contentContainerStyle = addStyle(
contentContainerStyle,
styles.containerScroll,
)
contentContainerStyle = addStyle(
contentContainerStyle,
theme.colorScheme === 'dark' ? styles.containerDark : styles.containerLight,
)
return (
<RNScrollView
contentContainerStyle={contentContainerStyle}
ref={ref}
{...props}
/>
)
})
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { container: {