change `contentVisibility` to `contain` (#4752)
parent
f8a59e10dd
commit
a3c43a7471
|
@ -386,10 +386,10 @@ export function MessagesList({
|
||||||
data={convoState.items}
|
data={convoState.items}
|
||||||
renderItem={renderItem}
|
renderItem={renderItem}
|
||||||
keyExtractor={keyExtractor}
|
keyExtractor={keyExtractor}
|
||||||
containWeb={true}
|
disableFullWindowScroll={true}
|
||||||
// Prevents wrong position in Firefox when sending a message
|
// Prevents wrong position in Firefox when sending a message
|
||||||
// as well as scroll getting stuck on Chome when scrolling upwards.
|
// as well as scroll getting stuck on Chome when scrolling upwards.
|
||||||
disableContentVisibility={true}
|
disableContainStyle={true}
|
||||||
disableVirtualization={true}
|
disableVirtualization={true}
|
||||||
style={animatedListStyle}
|
style={animatedListStyle}
|
||||||
// The extra two items account for the header and the footer components
|
// The extra two items account for the header and the footer components
|
||||||
|
|
|
@ -101,7 +101,7 @@ export function StepFeeds({moderationOpts}: {moderationOpts: ModerationOpts}) {
|
||||||
onEndReachedThreshold={2}
|
onEndReachedThreshold={2}
|
||||||
renderScrollComponent={props => <KeyboardAwareScrollView {...props} />}
|
renderScrollComponent={props => <KeyboardAwareScrollView {...props} />}
|
||||||
keyboardShouldPersistTaps="handled"
|
keyboardShouldPersistTaps="handled"
|
||||||
containWeb={true}
|
disableFullWindowScroll={true}
|
||||||
sideBorders={false}
|
sideBorders={false}
|
||||||
style={{flex: 1}}
|
style={{flex: 1}}
|
||||||
ListEmptyComponent={
|
ListEmptyComponent={
|
||||||
|
|
|
@ -80,7 +80,7 @@ export function StepProfiles({
|
||||||
keyExtractor={keyExtractor}
|
keyExtractor={keyExtractor}
|
||||||
renderScrollComponent={props => <KeyboardAwareScrollView {...props} />}
|
renderScrollComponent={props => <KeyboardAwareScrollView {...props} />}
|
||||||
keyboardShouldPersistTaps="handled"
|
keyboardShouldPersistTaps="handled"
|
||||||
containWeb={true}
|
disableFullWindowScroll={true}
|
||||||
sideBorders={false}
|
sideBorders={false}
|
||||||
style={[a.flex_1]}
|
style={[a.flex_1]}
|
||||||
onEndReached={
|
onEndReached={
|
||||||
|
|
|
@ -24,11 +24,12 @@ export type ListProps<ItemT> = Omit<
|
||||||
refreshing?: boolean
|
refreshing?: boolean
|
||||||
onRefresh?: () => void
|
onRefresh?: () => void
|
||||||
onItemSeen?: (item: ItemT) => void
|
onItemSeen?: (item: ItemT) => void
|
||||||
containWeb?: boolean
|
|
||||||
desktopFixedHeight?: number | boolean
|
desktopFixedHeight?: number | boolean
|
||||||
|
// Web only prop to contain the scroll to the container rather than the window
|
||||||
|
disableFullWindowScroll?: boolean
|
||||||
sideBorders?: boolean
|
sideBorders?: boolean
|
||||||
// Web only prop to disable a perf optimization (which would otherwise be on).
|
// Web only prop to disable a perf optimization (which would otherwise be on).
|
||||||
disableContentVisibility?: boolean
|
disableContainStyle?: boolean
|
||||||
}
|
}
|
||||||
export type ListRef = React.MutableRefObject<FlatList_INTERNAL | null>
|
export type ListRef = React.MutableRefObject<FlatList_INTERNAL | null>
|
||||||
|
|
||||||
|
|
|
@ -23,9 +23,11 @@ export type ListProps<ItemT> = Omit<
|
||||||
onRefresh?: () => void
|
onRefresh?: () => void
|
||||||
onItemSeen?: (item: ItemT) => void
|
onItemSeen?: (item: ItemT) => void
|
||||||
desktopFixedHeight?: number | boolean
|
desktopFixedHeight?: number | boolean
|
||||||
containWeb?: boolean
|
// Web only prop to contain the scroll to the container rather than the window
|
||||||
|
disableFullWindowScroll?: boolean
|
||||||
sideBorders?: boolean
|
sideBorders?: boolean
|
||||||
disableContentVisibility?: boolean
|
// Web only prop to disable a perf optimization (which would otherwise be on).
|
||||||
|
disableContainStyle?: boolean
|
||||||
}
|
}
|
||||||
export type ListRef = React.MutableRefObject<any | null> // TODO: Better types.
|
export type ListRef = React.MutableRefObject<any | null> // TODO: Better types.
|
||||||
|
|
||||||
|
@ -39,7 +41,7 @@ function ListImpl<ItemT>(
|
||||||
ListHeaderComponent,
|
ListHeaderComponent,
|
||||||
ListFooterComponent,
|
ListFooterComponent,
|
||||||
ListEmptyComponent,
|
ListEmptyComponent,
|
||||||
containWeb,
|
disableFullWindowScroll,
|
||||||
contentContainerStyle,
|
contentContainerStyle,
|
||||||
data,
|
data,
|
||||||
desktopFixedHeight,
|
desktopFixedHeight,
|
||||||
|
@ -58,7 +60,7 @@ function ListImpl<ItemT>(
|
||||||
extraData,
|
extraData,
|
||||||
style,
|
style,
|
||||||
sideBorders = true,
|
sideBorders = true,
|
||||||
disableContentVisibility,
|
disableContainStyle,
|
||||||
...props
|
...props
|
||||||
}: ListProps<ItemT>,
|
}: ListProps<ItemT>,
|
||||||
ref: React.Ref<ListMethods>,
|
ref: React.Ref<ListMethods>,
|
||||||
|
@ -112,7 +114,7 @@ function ListImpl<ItemT>(
|
||||||
}
|
}
|
||||||
|
|
||||||
const getScrollableNode = React.useCallback(() => {
|
const getScrollableNode = React.useCallback(() => {
|
||||||
if (containWeb) {
|
if (disableFullWindowScroll) {
|
||||||
const element = nativeRef.current as HTMLDivElement | null
|
const element = nativeRef.current as HTMLDivElement | null
|
||||||
if (!element) return
|
if (!element) return
|
||||||
|
|
||||||
|
@ -182,7 +184,7 @@ function ListImpl<ItemT>(
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [containWeb])
|
}, [disableFullWindowScroll])
|
||||||
|
|
||||||
const nativeRef = React.useRef<HTMLDivElement>(null)
|
const nativeRef = React.useRef<HTMLDivElement>(null)
|
||||||
React.useImperativeHandle(
|
React.useImperativeHandle(
|
||||||
|
@ -267,7 +269,12 @@ function ListImpl<ItemT>(
|
||||||
return () => {
|
return () => {
|
||||||
element?.removeEventListener('scroll', handleScroll)
|
element?.removeEventListener('scroll', handleScroll)
|
||||||
}
|
}
|
||||||
}, [isInsideVisibleTree, handleScroll, containWeb, getScrollableNode])
|
}, [
|
||||||
|
isInsideVisibleTree,
|
||||||
|
handleScroll,
|
||||||
|
disableFullWindowScroll,
|
||||||
|
getScrollableNode,
|
||||||
|
])
|
||||||
|
|
||||||
// --- onScrolledDownChange ---
|
// --- onScrolledDownChange ---
|
||||||
const isScrolledDown = useRef(false)
|
const isScrolledDown = useRef(false)
|
||||||
|
@ -308,7 +315,7 @@ function ListImpl<ItemT>(
|
||||||
{...props}
|
{...props}
|
||||||
style={[
|
style={[
|
||||||
style,
|
style,
|
||||||
containWeb && {
|
disableFullWindowScroll && {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
// @ts-expect-error web only
|
// @ts-expect-error web only
|
||||||
'overflow-y': 'scroll',
|
'overflow-y': 'scroll',
|
||||||
|
@ -332,13 +339,13 @@ function ListImpl<ItemT>(
|
||||||
pal.border,
|
pal.border,
|
||||||
]}>
|
]}>
|
||||||
<Visibility
|
<Visibility
|
||||||
root={containWeb ? nativeRef : null}
|
root={disableFullWindowScroll ? nativeRef : null}
|
||||||
onVisibleChange={handleAboveTheFoldVisibleChange}
|
onVisibleChange={handleAboveTheFoldVisibleChange}
|
||||||
style={[styles.aboveTheFoldDetector, {height: headerOffset}]}
|
style={[styles.aboveTheFoldDetector, {height: headerOffset}]}
|
||||||
/>
|
/>
|
||||||
{onStartReached && !isEmpty && (
|
{onStartReached && !isEmpty && (
|
||||||
<Visibility
|
<Visibility
|
||||||
root={containWeb ? nativeRef : null}
|
root={disableFullWindowScroll ? nativeRef : null}
|
||||||
onVisibleChange={onHeadVisibilityChange}
|
onVisibleChange={onHeadVisibilityChange}
|
||||||
topMargin={(onStartReachedThreshold ?? 0) * 100 + '%'}
|
topMargin={(onStartReachedThreshold ?? 0) * 100 + '%'}
|
||||||
/>
|
/>
|
||||||
|
@ -356,13 +363,13 @@ function ListImpl<ItemT>(
|
||||||
renderItem={renderItem}
|
renderItem={renderItem}
|
||||||
extraData={extraData}
|
extraData={extraData}
|
||||||
onItemSeen={onItemSeen}
|
onItemSeen={onItemSeen}
|
||||||
disableContentVisibility={disableContentVisibility}
|
disableContainStyle={disableContainStyle}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
{onEndReached && !isEmpty && (
|
{onEndReached && !isEmpty && (
|
||||||
<Visibility
|
<Visibility
|
||||||
root={containWeb ? nativeRef : null}
|
root={disableFullWindowScroll ? nativeRef : null}
|
||||||
onVisibleChange={onTailVisibilityChange}
|
onVisibleChange={onTailVisibilityChange}
|
||||||
bottomMargin={(onEndReachedThreshold ?? 0) * 100 + '%'}
|
bottomMargin={(onEndReachedThreshold ?? 0) * 100 + '%'}
|
||||||
key={data?.length}
|
key={data?.length}
|
||||||
|
@ -406,7 +413,7 @@ let Row = function RowImpl<ItemT>({
|
||||||
renderItem,
|
renderItem,
|
||||||
extraData: _unused,
|
extraData: _unused,
|
||||||
onItemSeen,
|
onItemSeen,
|
||||||
disableContentVisibility,
|
disableContainStyle,
|
||||||
}: {
|
}: {
|
||||||
item: ItemT
|
item: ItemT
|
||||||
index: number
|
index: number
|
||||||
|
@ -416,7 +423,7 @@ let Row = function RowImpl<ItemT>({
|
||||||
| ((data: {index: number; item: any; separators: any}) => React.ReactNode)
|
| ((data: {index: number; item: any; separators: any}) => React.ReactNode)
|
||||||
extraData: any
|
extraData: any
|
||||||
onItemSeen: ((item: any) => void) | undefined
|
onItemSeen: ((item: any) => void) | undefined
|
||||||
disableContentVisibility?: boolean
|
disableContainStyle?: boolean
|
||||||
}): React.ReactNode {
|
}): React.ReactNode {
|
||||||
const rowRef = React.useRef(null)
|
const rowRef = React.useRef(null)
|
||||||
const intersectionTimeout = React.useRef<NodeJS.Timer | undefined>(undefined)
|
const intersectionTimeout = React.useRef<NodeJS.Timer | undefined>(undefined)
|
||||||
|
@ -465,14 +472,10 @@ let Row = function RowImpl<ItemT>({
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
const shouldDisableContentVisibility = disableContentVisibility || isSafari
|
const shouldDisableContainStyle = disableContainStyle || isSafari
|
||||||
return (
|
return (
|
||||||
<View
|
<View
|
||||||
style={
|
style={shouldDisableContainStyle ? undefined : styles.contain}
|
||||||
shouldDisableContentVisibility
|
|
||||||
? undefined
|
|
||||||
: styles.contentVisibilityAuto
|
|
||||||
}
|
|
||||||
ref={rowRef}>
|
ref={rowRef}>
|
||||||
{renderItem({item, index, separators: null as any})}
|
{renderItem({item, index, separators: null as any})}
|
||||||
</View>
|
</View>
|
||||||
|
@ -544,9 +547,9 @@ const styles = StyleSheet.create({
|
||||||
marginLeft: 'auto',
|
marginLeft: 'auto',
|
||||||
marginRight: 'auto',
|
marginRight: 'auto',
|
||||||
},
|
},
|
||||||
contentVisibilityAuto: {
|
contain: {
|
||||||
// @ts-ignore web only
|
// @ts-ignore web only
|
||||||
contentVisibility: 'auto',
|
contain: 'layout paint',
|
||||||
},
|
},
|
||||||
minHeightViewport: {
|
minHeightViewport: {
|
||||||
// @ts-ignore web only
|
// @ts-ignore web only
|
||||||
|
|
|
@ -47,7 +47,7 @@ export function ListContained() {
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
keyExtractor={item => item.id.toString()}
|
keyExtractor={item => item.id.toString()}
|
||||||
containWeb={true}
|
disableFullWindowScroll={true}
|
||||||
style={{flex: 1}}
|
style={{flex: 1}}
|
||||||
onStartReached={() => {
|
onStartReached={() => {
|
||||||
console.log('Start Reached')
|
console.log('Start Reached')
|
||||||
|
|
Loading…
Reference in New Issue