|
1 | 1 | import React, { forwardRef, useMemo } from "react"; |
2 | | -import { Animated } from "react-native"; |
| 2 | +import Reanimated, { |
| 3 | + interpolate, |
| 4 | + useAnimatedStyle, |
| 5 | +} from "react-native-reanimated"; |
3 | 6 |
|
4 | | -import { useKeyboardAnimation } from "../../hooks"; |
| 7 | +import { useReanimatedKeyboardAnimation } from "../../hooks"; |
5 | 8 |
|
6 | 9 | import type { View, ViewProps } from "react-native"; |
7 | 10 |
|
@@ -51,29 +54,25 @@ const KeyboardStickyView = forwardRef< |
51 | 54 | }, |
52 | 55 | ref, |
53 | 56 | ) => { |
54 | | - const { height, progress } = useKeyboardAnimation(); |
| 57 | + const { height, progress } = useReanimatedKeyboardAnimation(); |
55 | 58 |
|
56 | | - const offset = progress.interpolate({ |
57 | | - inputRange: [0, 1], |
58 | | - outputRange: [closed, opened], |
59 | | - }); |
| 59 | + const stickyViewStyle = useAnimatedStyle(() => { |
| 60 | + const offset = interpolate(progress.value, [0, 1], [closed, opened]); |
60 | 61 |
|
61 | | - const styles = useMemo(() => { |
62 | | - const disabled = Animated.add(Animated.multiply(height, 0), closed); |
63 | | - const active = Animated.add(height, offset); |
| 62 | + return { |
| 63 | + transform: [{ translateY: enabled ? height.value + offset : closed }], |
| 64 | + }; |
| 65 | + }, [closed, opened, enabled]); |
64 | 66 |
|
65 | | - return [ |
66 | | - { |
67 | | - transform: [{ translateY: enabled ? active : disabled }], |
68 | | - }, |
69 | | - style, |
70 | | - ]; |
71 | | - }, [closed, enabled, height, offset, style]); |
| 67 | + const styles = useMemo( |
| 68 | + () => [style, stickyViewStyle], |
| 69 | + [style, stickyViewStyle], |
| 70 | + ); |
72 | 71 |
|
73 | 72 | return ( |
74 | | - <Animated.View ref={ref} style={styles} {...props}> |
| 73 | + <Reanimated.View ref={ref} style={styles} {...props}> |
75 | 74 | {children} |
76 | | - </Animated.View> |
| 75 | + </Reanimated.View> |
77 | 76 | ); |
78 | 77 | }, |
79 | 78 | ); |
|
0 commit comments