Skip to content

Commit 60872e7

Browse files
committed
fix: re-layout after animation on ios
1 parent c41cca2 commit 60872e7

1 file changed

Lines changed: 13 additions & 16 deletions

File tree

packages/webpack-plugin/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { ReactNode, useContext, useEffect, useMemo } from 'react'
2-
import { DimensionValue, EmitterSubscription, Keyboard, Platform, View, ViewStyle } from 'react-native'
3-
import Animated, { useSharedValue, useAnimatedStyle, withTiming, Easing, runOnJS } from 'react-native-reanimated'
2+
import { DimensionValue, EmitterSubscription, Keyboard, View, ViewStyle } from 'react-native'
3+
import Animated, { useSharedValue, useAnimatedStyle, withTiming, Easing } from 'react-native-reanimated'
44
import { GestureDetector, Gesture } from 'react-native-gesture-handler'
55
import { KeyboardAvoidContext } from './context'
66

@@ -30,14 +30,10 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }: Keyboa
3030
}).runOnJS(true)
3131
}, [])
3232

33-
const animatedStyle = useAnimatedStyle(() => {
34-
return Object.assign(
35-
{
36-
transform: [{ translateY: -offset.value }]
37-
},
38-
isIOS ? {} : { flexBasis: basic.value as DimensionValue }
39-
)
40-
})
33+
const animatedStyle = useAnimatedStyle(() => ({
34+
transform: [{ translateY: -offset.value }],
35+
flexBasis: basic.value as DimensionValue
36+
}))
4137

4238
const resetKeyboard = () => {
4339
if (keyboardAvoid?.current) {
@@ -62,7 +58,12 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }: Keyboa
6258
const aboveValue = -aboveOffset >= cursorSpacing ? 0 : aboveOffset + cursorSpacing
6359
const belowValue = Math.min(endCoordinates.height, aboveOffset + cursorSpacing)
6460
const value = aboveOffset > 0 ? belowValue : aboveValue
65-
offset.value = withTiming(value, { duration, easing })
61+
offset.value = withTiming(value, { duration, easing }, (finished) => {
62+
if (finished) {
63+
// Set flexBasic after animation to trigger re-layout and reset layout information
64+
basic.value = '99.99%'
65+
}
66+
})
6667
})
6768
})
6869
}),
@@ -82,11 +83,7 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }: Keyboa
8283
const value = aboveOffset > 0 ? belowValue : aboveValue
8384
offset.value = withTiming(value, { duration, easing }, (finished) => {
8485
if (finished) {
85-
/**
86-
* In the Android environment, the layout information is not synchronized after the animation,
87-
* which results in the inability to correctly trigger element events.
88-
* Here, we utilize flexBasic to proactively trigger a re-layout
89-
*/
86+
// Set flexBasic after animation to trigger re-layout and reset layout information
9087
basic.value = '99.99%'
9188
}
9289
})

0 commit comments

Comments
 (0)