-
-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Smooth Keyboard Animation Height Transition in useKeyboardHandler #677
Comments
Hey @lucaspelloni2 May I ask you to attach a video to show the choppy animation? Are you testing on a real device or simulator? Also may I ask you to provide a full code snippet? Basically You can also clone |
Thank you for the response!! Here my full code snippet
|
real device, iPhone 12 Pro ScreenRecording_11-08-2024.11-15-38_1.MP4 |
@lucaspelloni2 Are you using Sentry by any chance? If yes, then which version? |
Nope. no Sentry (we arent live yet) |
Okay, this is something strange. I fixed Now I'm testing a test case with ScreenRecording_11-08-2024.11-32-35.AM_1.MP4When I test ScreenRecording_11-08-2024.11-32-21.AM_1.MP4
I definetely remember, that when I was testing #412 I tested Chat example as well with updated implementation of RPReplay_Final1714507624.MP4
I didn't modify the code, but what has changes since April is:
May I also ask yo to prepare your example so that I can copy/paste it in my example project and test as well? Right now some components (such as AnimatedFlex/MakeSpacing/Regular etc.) are not visible to me. Would be good if you could replace all these parts with simple View component, so that I can easily copy/paste and test on my device. |
Thank you very much for this! With this code you should be able to reproduce the issue
|
Here again the video. In my case, the height value not only updates with a delay but also shows distinct steps between value updates. This stepping effect causes the keyboard animation to stutter, which reduces the smoothness. ScreenRecording_11-08-2024.11-55-43_1.MP4 |
and btw:
|
Awesome, I'll try to check that today or over the weekend 👀 |
Hey @lucaspelloni2 I'm slightly late 😅 I tried to reproduce a problem but on my iPhone 11 (iOS 18.0.1) the animation is running frame in frame: ScreenRecording_11-11-2024.12-31-59.PM_1.MP4Though I have to admit that I made some modifications to your code: import { useCallback, useState } from "react";
import {
FlatList as FlashList, // <-- modification (1)
Text,
TextInput,
TouchableOpacity,
View,
} from "react-native";
import { useKeyboardHandler } from "react-native-keyboard-controller";
import Animated, {
useAnimatedStyle,
useSharedValue,
} from "react-native-reanimated";
const colors = ["yellow", "green", "blue", "red"];
const DummyListItem = ({ index }: { index: number }) => {
return (
<TouchableOpacity
style={{ height: 200, width: 200, backgroundColor: colors[index] }}
>
<Text>Dummy text.</Text>
</TouchableOpacity>
);
};
export const AgentChat = () => {
const [newMessage, setNewMessage] = useState("");
const height = useSharedValue(0);
useKeyboardHandler({
onStart: (e) => {
"worklet";
// height.value = Math.abs(e.height); // <-- modification (2)
},
onMove: (e) => {
"worklet";
height.value = Math.abs(e.height);
},
onEnd: (e) => {
"worklet";
height.value = Math.abs(e.height);
},
onInteractive: (e) => {
"worklet";
height.value = Math.abs(e.height);
},
});
const fakeViewStyle = useAnimatedStyle(() => {
return {
height: height.value + 20,
};
}, [height]);
const renderDummyItem = useCallback(({ index }: { index: number }) => {
return <DummyListItem index={index} />;
}, []);
return (
<Animated.View style={[{ flex: 1, backgroundColor: "black" }]}>
<View style={{ height: 200 }} />
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<FlashList
horizontal
data={Array.from({ length: colors.length }, (_, index) => index)}
estimatedItemSize={200}
renderItem={renderDummyItem}
/>
</View>
<TextInput
autoFocus
placeholder="Add more information..."
placeholderTextColor={"white"}
selectionColor={"white"}
value={newMessage}
onChangeText={setNewMessage}
/>
<Animated.View style={fakeViewStyle} />
<View style={{ height: 20 }} />
</Animated.View>
);
};
export default AgentChat; // <-- modification (3) Most noticeable are:
On iOS you may do this (i. e. update value immediately) and iOS will schedule a layout animation and perform smooth transitions. But if you use both Please, try to remove |
Describe the bug
Hello! Thank you for this library. Not sure if this is intended, but when animating the keyboard, the height value updates with noticeable “steps” between values, causing height animations to appear choppy rather than smooth. This “jumping” behavior detracts from the expected fluidity in the keyboard’s animation.
Code snippet
LOG current height: 291
LOG current height: 249.05628901209576
LOG current height: 217.09624960612547
LOG current height: 184.88664681262821
LOG current height: 154.56893747673666
LOG current height: 127.46685444750403
LOG current height: 103.68985801017402
etc.
To Reproduce
Run the code above
Expected behavior
Ideally, the height value should decrease smoothly without noticeable steps, creating a fluid animation when the keyboard is animated (and so access each frame)
Screenshots
Not needed
Smartphone (please complete the following information):
Additional context
This issue seems to stem from the stepped updates in height.value, likely related to the timing of the onMove events or the underlying keyboard animation handler in Reanimated. Any guidance or alternative methods for achieving a smoother keyboard animation would be appreciated.
The text was updated successfully, but these errors were encountered: