Skip to content

Commit

Permalink
fix: lazy loading glitch with reanimated 3
Browse files Browse the repository at this point in the history
  • Loading branch information
andreialecu committed Mar 4, 2023
1 parent f212ed7 commit de032e9
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/Lazy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Animated, {
useSharedValue,
useAnimatedReaction,
runOnJS,
useDerivedValue,
withTiming,
useAnimatedStyle,
} from 'react-native-reanimated'
Expand Down Expand Up @@ -63,16 +62,28 @@ export const Lazy: React.FC<{

const ref = name ? refMap[name] : null

useDerivedValue(() => {
if (afterMount) {
const tabIndex = tabNames.value.findIndex((n) => n === name)
if (ref && tabIndex >= 0) {
scrollTo(ref, 0, scrollY.value[tabIndex], false, `[${name}] lazy sync`)
useAnimatedReaction(
() => {
return afterMount
},
(trigger) => {
if (trigger) {
const tabIndex = tabNames.value.findIndex((n) => n === name)
if (ref && tabIndex >= 0) {
scrollTo(
ref,
0,
scrollY.value[tabIndex],
false,
`[${name}] lazy sync`
)
}
if (!cancelLazyFadeIn && opacity.value !== 1)
opacity.value = withTiming(1)
}
if (!cancelLazyFadeIn && opacity.value !== 1)
opacity.value = withTiming(1)
}
}, [ref, cancelLazyFadeIn, opacity, name, afterMount, tabNames, scrollTo])
},
[ref, cancelLazyFadeIn, name, afterMount, scrollTo]
)

const stylez = useAnimatedStyle(() => {
return {
Expand Down

0 comments on commit de032e9

Please sign in to comment.