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} />
}
export function FlatList<ItemT>({
export const FlatList = React.forwardRef(function <ItemT>(
{
contentContainerStyle,
...props
}: React.PropsWithChildren<FlatListProps<ItemT>>) {
const theme = useTheme()
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>) {
}: React.PropsWithChildren<FlatListProps<ItemT>>,
ref: React.Ref<RNFlatList>,
) {
const theme = useTheme()
contentContainerStyle = addStyle(
contentContainerStyle,
@ -63,9 +50,35 @@ export function ScrollView({
theme.colorScheme === 'dark' ? styles.containerDark : styles.containerLight,
)
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({
container: {