Skip to content

Commit 820fcb4

Browse files
authored
feat: KeyboardStickyView using plain Animated (#898)
## 📜 Description Fixed a problem when `KeyboardStickyView`/`KeyboardToolbar` changes other component behavior in unpredictable way. ## 💡 Motivation and Context The original problem comes from that issue: facebook/react-native#49694 And it seems like it's affecting many open-source projects: `react-native-screens`, `react-native-reanimated`, and `react-native-keyboard-controller` as well because I'm heavily relying on reanimated usage. This PR is rewriting `KeyboardStickyView` to plain `Animated.View`. At the moment it's possible to do that, but in future I'm planning to change interpolation when keyboard gets dismissed interactively. Again it's not proper fix for a problem, but pipeline react-native fix -> react-native-reanimated fix -> verify fix in this library can take months I believe and will require usage of new libs. So to reduce amount of reported issues I decided temporarily rewrite this component to `Animated` variant. Once the issue will be fixed it'll be a good time to re-write it back and address `interactive`- dismissal interpolation. Closes #809 ## 📢 Changelog <!-- High level overview of important changes --> <!-- For example: fixed status bar manipulation; added new types declarations; --> <!-- If your changes don't affect one of platform/language below - then remove this platform/language --> ### JS - rewrite `KeyboardStickyView` to `Animated` usage; ## 🤔 How Has This Been Tested? Tested manuall in example app. ## 📸 Screenshots (if appropriate): |Before|After| |-------|-----| |<img src="https://github.com/user-attachments/assets/678d3174-40a9-43b6-8b80-9931e6b879c1">|<img src="https://github.com/user-attachments/assets/ce7c7fdb-bf6d-457c-854a-ddd60d63e7d2">| ## 📝 Checklist - [x] CI successfully passed - [x] I added new mocks and corresponding unit-tests if library API was changed
1 parent 13dfb32 commit 820fcb4

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

src/components/KeyboardStickyView/index.tsx

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import React, { forwardRef, useMemo } from "react";
2-
import Reanimated, {
3-
interpolate,
4-
useAnimatedStyle,
5-
} from "react-native-reanimated";
2+
import { Animated } from "react-native";
63

7-
import { useReanimatedKeyboardAnimation } from "../../hooks";
4+
import { useKeyboardAnimation } from "../../hooks";
85

96
import type { View, ViewProps } from "react-native";
107

@@ -41,25 +38,29 @@ const KeyboardStickyView = forwardRef<
4138
},
4239
ref,
4340
) => {
44-
const { height, progress } = useReanimatedKeyboardAnimation();
41+
const { height, progress } = useKeyboardAnimation();
4542

46-
const stickyViewStyle = useAnimatedStyle(() => {
47-
const offset = interpolate(progress.value, [0, 1], [closed, opened]);
48-
49-
return {
50-
transform: [{ translateY: enabled ? height.value + offset : closed }],
51-
};
52-
}, [closed, opened, enabled]);
43+
const offset = progress.interpolate({
44+
inputRange: [0, 1],
45+
outputRange: [closed, opened],
46+
});
5347

5448
const styles = useMemo(
55-
() => [style, stickyViewStyle],
56-
[style, stickyViewStyle],
49+
() => [
50+
{
51+
transform: [
52+
{ translateY: enabled ? Animated.add(height, offset) : closed },
53+
],
54+
},
55+
style,
56+
],
57+
[closed, enabled, height, offset, style],
5758
);
5859

5960
return (
60-
<Reanimated.View ref={ref} style={styles} {...props}>
61+
<Animated.View ref={ref} style={styles} {...props}>
6162
{children}
62-
</Reanimated.View>
63+
</Animated.View>
6364
);
6465
},
6566
);

0 commit comments

Comments
 (0)