Skip to content

Commit a94dca3

Browse files
authored
Merge pull request #2142 from didi/fix-runOnjs-animation
fix animation runOnjs callback
2 parents 0691a19 + 62be82e commit a94dca3

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

packages/webpack-plugin/lib/runtime/components/react/useAnimationHooks.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
} from 'react-native-reanimated'
1515
import type { AnimationCallback, WithTimingConfig, SharedValue, AnimatableValue } from 'react-native-reanimated'
1616
import { error, hasOwn, collectDataset } from '@mpxjs/utils'
17+
import { useRunOnJSCallback } from './utils'
1718
import { ExtendedViewStyle } from './types/common'
1819
import type { _ViewProps } from './mpx-view'
1920

@@ -218,13 +219,19 @@ export default function useAnimationHooks<T, P> (props: _ViewProps & { enableAni
218219
timeStamp: Date.now()
219220
})
220221
}
222+
// eslint-disable-next-line react-hooks/rules-of-hooks
223+
const runOnJSCallbackRef = useRef({
224+
withTimingCallback
225+
})
226+
// eslint-disable-next-line react-hooks/rules-of-hooks
227+
const runOnJSCallback = useRunOnJSCallback(runOnJSCallbackRef)
221228
// 创建单个animation
222229
function getAnimation ({ key, value }: { key: string, value: string|number }, { delay, duration, easing }: ExtendWithTimingConfig, callback?: AnimationCallback) {
223230
const animation = typeof callback === 'function'
224231
? withTiming(value, { duration, easing }, (finished, current) => {
225232
callback(finished, current)
226233
if (transitionend && finished) {
227-
runOnJS(withTimingCallback)(finished, current, duration)
234+
runOnJS(runOnJSCallback)('withTimingCallback', finished, current, duration)
228235
}
229236
})
230237
: withTiming(value, { duration, easing })

0 commit comments

Comments
 (0)