Skip to content

Commit ec4156b

Browse files
committed
feat: implementation for platforms with missing native API (aka polyfill)
1 parent 7075a55 commit ec4156b

File tree

2 files changed

+62
-17
lines changed

2 files changed

+62
-17
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React from "react";
2+
import { View } from "react-native";
3+
4+
import { RCTKeyboardExtender } from "../../bindings";
5+
import { useWindowDimensions } from "../../hooks";
6+
7+
import type { KeyboardExtenderProps } from "../../types";
8+
import type { PropsWithChildren } from "react";
9+
10+
/**
11+
* A component that embeds its children into the keyboard thus enhancing keyboard functionality.
12+
*
13+
* @param props - Component props.
14+
* @returns A view component that renders inside the keyboard above all system buttons.
15+
* @example
16+
* ```tsx
17+
* <KeyboardExtender>
18+
* <Button>10$</Button>
19+
* <Button>20$</Button>
20+
* <Button>50$</Button>
21+
* </KeyboardExtender>
22+
* ```
23+
*/
24+
const KeyboardExtender = (props: PropsWithChildren<KeyboardExtenderProps>) => {
25+
const { children, enabled = true } = props;
26+
const { width } = useWindowDimensions();
27+
28+
return (
29+
<RCTKeyboardExtender enabled={enabled}>
30+
<View style={{ width }}>{children}</View>
31+
</RCTKeyboardExtender>
32+
);
33+
};
34+
35+
export default KeyboardExtender;

src/views/KeyboardExtender/index.tsx

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,41 @@
11
import React from "react";
2-
import { Platform, View } from "react-native";
2+
import { Animated } from "react-native";
33

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";
67

78
import type { KeyboardExtenderProps } from "../../types";
89
import type { PropsWithChildren } from "react";
910

10-
// TODO: should be in views because on Android we gonna use KeyboardStickyView?
11+
const AnimatedKeyboardBackgroundView = Animated.createAnimatedComponent(
12+
KeyboardBackgroundView,
13+
);
14+
1115
/**
1216
* 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+
* ```
1328
*/
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();
2432

2533
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>
2939
);
3040
};
3141

0 commit comments

Comments
 (0)