|
1 | 1 | import React from "react";
|
2 |
| -import { Platform, View } from "react-native"; |
| 2 | +import { Animated } from "react-native"; |
3 | 3 |
|
4 |
| -import { RCTKeyboardExtender } from "../../bindings"; |
5 |
| -import { useWindowDimensions } from "../../hooks"; |
| 4 | +import { KeyboardBackgroundView } from "../../bindings"; |
| 5 | +import { KeyboardStickyView } from "../../components"; |
| 6 | +import { useKeyboardAnimation } from "../../hooks"; |
6 | 7 |
|
7 | 8 | import type { KeyboardExtenderProps } from "../../types";
|
8 | 9 | import type { PropsWithChildren } from "react";
|
9 | 10 |
|
10 |
| -// TODO: should be in views because on Android we gonna use KeyboardStickyView? |
| 11 | +const AnimatedKeyboardBackgroundView = Animated.createAnimatedComponent( |
| 12 | + KeyboardBackgroundView, |
| 13 | +); |
| 14 | + |
11 | 15 | /**
|
12 | 16 | * A component that embeds its children into the keyboard thus enhancing keyboard functionality.
|
| 17 | + * |
| 18 | + * @param props - Component props. |
| 19 | + * @returns A view component that renders inside the keyboard above all system buttons. |
| 20 | + * @example |
| 21 | + * ```tsx |
| 22 | + * <KeyboardExtender> |
| 23 | + * <Button>10$</Button> |
| 24 | + * <Button>20$</Button> |
| 25 | + * <Button>50$</Button> |
| 26 | + * </KeyboardExtender> |
| 27 | + * ``` |
13 | 28 | */
|
14 |
| -const KeyboardExtender = ({ |
15 |
| - children, |
16 |
| - enabled = false, |
17 |
| -}: PropsWithChildren<KeyboardExtenderProps>) => { |
18 |
| - const { width } = useWindowDimensions(); |
19 |
| - |
20 |
| - // iOS-only component |
21 |
| - if (Platform.OS !== "ios") { |
22 |
| - return null; |
23 |
| - } |
| 29 | +const KeyboardExtender = (props: PropsWithChildren<KeyboardExtenderProps>) => { |
| 30 | + const { children, enabled = true } = props; |
| 31 | + const { progress } = useKeyboardAnimation(); |
24 | 32 |
|
25 | 33 | return (
|
26 |
| - <RCTKeyboardExtender enabled={enabled}> |
27 |
| - <View style={{ width }}>{children}</View> |
28 |
| - </RCTKeyboardExtender> |
| 34 | + <KeyboardStickyView enabled={enabled}> |
| 35 | + <AnimatedKeyboardBackgroundView style={{ opacity: progress }}> |
| 36 | + {children} |
| 37 | + </AnimatedKeyboardBackgroundView> |
| 38 | + </KeyboardStickyView> |
29 | 39 | );
|
30 | 40 | };
|
31 | 41 |
|
|
0 commit comments