|
1 | 1 | import React, { forwardRef, useMemo } from "react";
|
2 |
| -import Reanimated, { |
3 |
| - interpolate, |
4 |
| - useAnimatedStyle, |
5 |
| -} from "react-native-reanimated"; |
| 2 | +import { Animated } from "react-native"; |
6 | 3 |
|
7 |
| -import { useReanimatedKeyboardAnimation } from "../../hooks"; |
| 4 | +import { useKeyboardAnimation } from "../../hooks"; |
8 | 5 |
|
9 | 6 | import type { View, ViewProps } from "react-native";
|
10 | 7 |
|
@@ -41,25 +38,29 @@ const KeyboardStickyView = forwardRef<
|
41 | 38 | },
|
42 | 39 | ref,
|
43 | 40 | ) => {
|
44 |
| - const { height, progress } = useReanimatedKeyboardAnimation(); |
| 41 | + const { height, progress } = useKeyboardAnimation(); |
45 | 42 |
|
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 | + }); |
53 | 47 |
|
54 | 48 | 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], |
57 | 58 | );
|
58 | 59 |
|
59 | 60 | return (
|
60 |
| - <Reanimated.View ref={ref} style={styles} {...props}> |
| 61 | + <Animated.View ref={ref} style={styles} {...props}> |
61 | 62 | {children}
|
62 |
| - </Reanimated.View> |
| 63 | + </Animated.View> |
63 | 64 | );
|
64 | 65 | },
|
65 | 66 | );
|
|
0 commit comments