disable perf optimisation to allow overflow

This commit is contained in:
Samuel Newman
2024-07-26 14:00:06 +01:00
parent 5cdaceffc1
commit d1360376c3
8 changed files with 23 additions and 48 deletions
@@ -387,9 +387,6 @@ export function MessagesList({
renderItem={renderItem} renderItem={renderItem}
keyExtractor={keyExtractor} keyExtractor={keyExtractor}
disableFullWindowScroll={true} disableFullWindowScroll={true}
// Prevents wrong position in Firefox when sending a message
// as well as scroll getting stuck on Chome when scrolling upwards.
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
-1
View File
@@ -509,7 +509,6 @@ const styles = StyleSheet.create({
paddingRight: 15, paddingRight: 15,
// @ts-ignore web only -prf // @ts-ignore web only -prf
cursor: 'pointer', cursor: 'pointer',
overflow: 'hidden',
}, },
replyLine: { replyLine: {
width: 2, width: 2,
-2
View File
@@ -28,8 +28,6 @@ export type ListProps<ItemT> = Omit<
// Web only prop to contain the scroll to the container rather than the window // Web only prop to contain the scroll to the container rather than the window
disableFullWindowScroll?: boolean disableFullWindowScroll?: boolean
sideBorders?: boolean sideBorders?: boolean
// Web only prop to disable a perf optimization (which would otherwise be on).
disableContainStyle?: boolean
} }
export type ListRef = React.MutableRefObject<FlatList_INTERNAL | null> export type ListRef = React.MutableRefObject<FlatList_INTERNAL | null>
+4 -18
View File
@@ -4,11 +4,10 @@ import {ReanimatedScrollEvent} from 'react-native-reanimated/lib/typescript/rean
import {batchedUpdates} from '#/lib/batchedUpdates' import {batchedUpdates} from '#/lib/batchedUpdates'
import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback' import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback'
import {usePalette} from '#/lib/hooks/usePalette'
import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries'
import {useScrollHandlers} from '#/lib/ScrollContext' import {useScrollHandlers} from '#/lib/ScrollContext'
import {isSafari} from 'lib/browser' import {addStyle} from '#/lib/styles'
import {usePalette} from 'lib/hooks/usePalette'
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
import {addStyle} from 'lib/styles'
export type ListMethods = any // TODO: Better types. export type ListMethods = any // TODO: Better types.
export type ListProps<ItemT> = Omit< export type ListProps<ItemT> = Omit<
@@ -26,8 +25,6 @@ export type ListProps<ItemT> = Omit<
// Web only prop to contain the scroll to the container rather than the window // Web only prop to contain the scroll to the container rather than the window
disableFullWindowScroll?: boolean disableFullWindowScroll?: boolean
sideBorders?: boolean sideBorders?: 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.
@@ -60,7 +57,6 @@ function ListImpl<ItemT>(
extraData, extraData,
style, style,
sideBorders = true, sideBorders = true,
disableContainStyle,
...props ...props
}: ListProps<ItemT>, }: ListProps<ItemT>,
ref: React.Ref<ListMethods>, ref: React.Ref<ListMethods>,
@@ -363,7 +359,6 @@ function ListImpl<ItemT>(
renderItem={renderItem} renderItem={renderItem}
extraData={extraData} extraData={extraData}
onItemSeen={onItemSeen} onItemSeen={onItemSeen}
disableContainStyle={disableContainStyle}
/> />
) )
})} })}
@@ -413,7 +408,6 @@ let Row = function RowImpl<ItemT>({
renderItem, renderItem,
extraData: _unused, extraData: _unused,
onItemSeen, onItemSeen,
disableContainStyle,
}: { }: {
item: ItemT item: ItemT
index: number index: number
@@ -423,7 +417,6 @@ 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
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)
@@ -472,11 +465,8 @@ let Row = function RowImpl<ItemT>({
return null return null
} }
const shouldDisableContainStyle = disableContainStyle || isSafari
return ( return (
<View <View ref={rowRef}>
style={shouldDisableContainStyle ? undefined : styles.contain}
ref={rowRef}>
{renderItem({item, index, separators: null as any})} {renderItem({item, index, separators: null as any})}
</View> </View>
) )
@@ -547,10 +537,6 @@ const styles = StyleSheet.create({
marginLeft: 'auto', marginLeft: 'auto',
marginRight: 'auto', marginRight: 'auto',
}, },
contain: {
// @ts-ignore web only
contain: 'layout paint',
},
minHeightViewport: { minHeightViewport: {
// @ts-ignore web only // @ts-ignore web only
minHeight: '100vh', minHeight: '100vh',
@@ -32,14 +32,6 @@ export function ActiveVideoProvider({children}: {children: React.ReactNode}) {
sendViewPosition: (viewId: string, y: number) => { sendViewPosition: (viewId: string, y: number) => {
if (isNative) return if (isNative) return
// console.log(
// 'sendViewPosition',
// viewId,
// y,
// activeViewId,
// activeViewLocationRef.current,
// )
if (viewId === activeViewId) { if (viewId === activeViewId) {
activeViewLocationRef.current = y activeViewLocationRef.current = y
} else { } else {
@@ -57,7 +49,7 @@ export function ActiveVideoProvider({children}: {children: React.ReactNode}) {
} }
function distanceToIdealPosition(yPos: number) { function distanceToIdealPosition(yPos: number) {
return Math.abs(yPos - windowHeight / 3) return Math.abs(yPos - windowHeight / 2.5)
} }
function withinViewport(yPos: number) { function withinViewport(yPos: number) {
@@ -12,9 +12,10 @@ import {VideoEmbedInner} from './VideoEmbedInner'
export function VideoEmbed({source}: {source: string}) { export function VideoEmbed({source}: {source: string}) {
const t = useTheme() const t = useTheme()
const ref = useRef<HTMLDivElement>(null) const ref = useRef<HTMLDivElement>(null)
const {active, setActive, sendPosition} = useActiveVideoView({ const {active, setActive, sendPosition, currentActiveView} =
source, useActiveVideoView({
}) source,
})
const [onScreen, setOnScreen] = useState(false) const [onScreen, setOnScreen] = useState(false)
const {_} = useLingui() const {_} = useLingui()
@@ -24,7 +25,6 @@ export function VideoEmbed({source}: {source: string}) {
if (!ref.current) return if (!ref.current) return
const observer = new IntersectionObserver( const observer = new IntersectionObserver(
entries => { entries => {
console.log('OUTER')
const entry = entries[0] const entry = entries[0]
if (!entry) return if (!entry) return
setOnScreen(entry.isIntersecting) setOnScreen(entry.isIntersecting)
@@ -54,6 +54,7 @@ export function VideoEmbed({source}: {source: string}) {
setActive={setActive} setActive={setActive}
sendPosition={sendPosition} sendPosition={sendPosition}
onScreen={onScreen} onScreen={onScreen}
isAnyViewActive={currentActiveView !== null}
/> />
) : ( ) : (
<Button <Button
@@ -19,6 +19,7 @@ export function VideoEmbedInner({}: {
setActive: () => void setActive: () => void
sendPosition: (position: number) => void sendPosition: (position: number) => void
onScreen: boolean onScreen: boolean
isAnyViewActive?: boolean
}) { }) {
const player = useVideoPlayer() const player = useVideoPlayer()
const aref = useAnimatedRef<Animated.View>() const aref = useAnimatedRef<Animated.View>()
@@ -7,6 +7,7 @@ import {atoms as a, useTheme} from '#/alf'
export function VideoEmbedInner({ export function VideoEmbedInner({
active, active,
sendPosition, sendPosition,
isAnyViewActive,
...props ...props
}: { }: {
source: string source: string
@@ -14,6 +15,7 @@ export function VideoEmbedInner({
setActive: () => void setActive: () => void
sendPosition: (position: number) => void sendPosition: (position: number) => void
onScreen: boolean onScreen: boolean
isAnyViewActive?: boolean
}) { }) {
const ref = useRef<HTMLDivElement>(null) const ref = useRef<HTMLDivElement>(null)
@@ -25,7 +27,6 @@ export function VideoEmbedInner({
entries => { entries => {
const entry = entries[0] const entry = entries[0]
if (!entry) return if (!entry) return
console.log('observing', entry.intersectionRatio)
const position = const position =
entry.boundingClientRect.y + entry.boundingClientRect.height / 2 entry.boundingClientRect.y + entry.boundingClientRect.height / 2
sendPosition(position) sendPosition(position)
@@ -38,12 +39,12 @@ export function VideoEmbedInner({
// In case scrolling hasn't started yet, send up the position // In case scrolling hasn't started yet, send up the position
useEffect(() => { useEffect(() => {
if (ref.current && !active) { if (ref.current && !isAnyViewActive) {
const rect = ref.current.getBoundingClientRect() const rect = ref.current.getBoundingClientRect()
const position = rect.top + rect.height / 2 const position = rect.y + rect.height / 2
sendPosition(position) sendPosition(position)
} }
}, [active, sendPosition]) }, [isAnyViewActive, sendPosition])
return ( return (
<View style={[a.flex_1, a.flex_row]}> <View style={[a.flex_1, a.flex_row]}>
@@ -53,9 +54,10 @@ export function VideoEmbedInner({
style={{ style={{
position: 'absolute', position: 'absolute',
top: 'calc(50% - 50vh)', top: 'calc(50% - 50vh)',
left: '50%',
height: '100vh', height: '100vh',
width: 10, width: 1,
background: 'green', pointerEvents: 'none',
}} }}
/> />
</View> </View>
@@ -106,13 +108,11 @@ export function VideoPlayer({
useEffect(() => { useEffect(() => {
if (!ref.current) return if (!ref.current) return
if (active && onScreen) { if (!onScreen || !active) {
// ref.current?.play() ref.current.pause()
} else {
ref.current?.pause()
setFocused(false) setFocused(false)
} }
}, [active, onScreen]) }, [onScreen, active])
return ( return (
<View <View
@@ -141,6 +141,7 @@ export function VideoPlayer({
preload="none" preload="none"
loop loop
muted={!focused} muted={!focused}
autoPlay={active}
onClick={evt => { onClick={evt => {
evt.stopPropagation() evt.stopPropagation()
if (focused) { if (focused) {