cancel animations before updating value for min-shell animation (#4386)
* cancel animations before updating value * commentzio/stable
parent
85e676257e
commit
72f46ed734
|
@ -1,5 +1,5 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {SharedValue, useSharedValue, withSpring} from 'react-native-reanimated'
|
import {cancelAnimation, SharedValue, useSharedValue, withSpring} from 'react-native-reanimated'
|
||||||
|
|
||||||
type StateContext = SharedValue<number>
|
type StateContext = SharedValue<number>
|
||||||
type SetContext = (v: boolean) => void
|
type SetContext = (v: boolean) => void
|
||||||
|
@ -17,6 +17,8 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||||
const setMode = React.useCallback(
|
const setMode = React.useCallback(
|
||||||
(v: boolean) => {
|
(v: boolean) => {
|
||||||
'worklet'
|
'worklet'
|
||||||
|
// Cancel any existing animation
|
||||||
|
cancelAnimation(mode)
|
||||||
mode.value = withSpring(v ? 1 : 0, {
|
mode.value = withSpring(v ? 1 : 0, {
|
||||||
overshootClamping: true,
|
overshootClamping: true,
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
import React, {useCallback, useEffect} from 'react'
|
import React, {useCallback, useEffect} from 'react'
|
||||||
import {NativeScrollEvent} from 'react-native'
|
import {NativeScrollEvent} from 'react-native'
|
||||||
import {interpolate, useSharedValue} from 'react-native-reanimated'
|
import {
|
||||||
|
cancelAnimation,
|
||||||
|
interpolate,
|
||||||
|
useSharedValue,
|
||||||
|
} from 'react-native-reanimated'
|
||||||
import EventEmitter from 'eventemitter3'
|
import EventEmitter from 'eventemitter3'
|
||||||
|
|
||||||
import {ScrollProvider} from '#/lib/ScrollContext'
|
import {ScrollProvider} from '#/lib/ScrollContext'
|
||||||
|
@ -117,6 +121,8 @@ export function MainScrollProvider({children}: {children: React.ReactNode}) {
|
||||||
const newValue = clamp(startMode.value + dProgress, 0, 1)
|
const newValue = clamp(startMode.value + dProgress, 0, 1)
|
||||||
if (newValue !== mode.value) {
|
if (newValue !== mode.value) {
|
||||||
// Manually adjust the value. This won't be (and shouldn't be) animated.
|
// Manually adjust the value. This won't be (and shouldn't be) animated.
|
||||||
|
// Cancel any any existing animation
|
||||||
|
cancelAnimation(mode)
|
||||||
mode.value = newValue
|
mode.value = newValue
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue