Skip to content

Commit 27dc438

Browse files
authored
Add AvoidKeyboardView component (#805)
* Add AvoidKeyboardView component * Fix failing test
1 parent 61079ee commit 27dc438

File tree

7 files changed

+56
-1
lines changed

7 files changed

+56
-1
lines changed

packages/core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"lodash.isnumber": "^3.0.3",
5757
"lodash.omit": "^4.5.0",
5858
"lodash.tonumber": "^4.0.3",
59+
"react-native-avoid-softinput": "^4.0.1",
5960
"react-native-confirmation-code-field": "^7.3.1",
6061
"react-native-deck-swiper": "^2.0.12",
6162
"react-native-dropdown-picker": "^5.4.6",
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React from "react";
2+
import {
3+
AvoidSoftInput,
4+
AvoidSoftInputView,
5+
AvoidSoftInputViewProps,
6+
} from "react-native-avoid-softinput";
7+
8+
/**
9+
* Requires additional setup: https://mateusz1913.github.io/react-native-avoid-softinput/docs/guides
10+
* Cannot be used with Expo Go
11+
* Will work on on Draftbit Live Preview or an app that is setup according to the linked guide
12+
*/
13+
14+
interface AvoidKeyboardViewProps
15+
extends Omit<
16+
AvoidSoftInputViewProps,
17+
"onSoftInputHidden" | "onSoftInputShown"
18+
> {
19+
onKeyboardShown?: () => void;
20+
onKeyboardHidden?: () => void;
21+
}
22+
23+
const AvoidKeyboardView: React.FC<AvoidKeyboardViewProps> = ({
24+
onKeyboardHidden,
25+
onKeyboardShown,
26+
...rest
27+
}) => {
28+
React.useEffect(() => {
29+
AvoidSoftInput.setShouldMimicIOSBehavior(true);
30+
return () => {
31+
AvoidSoftInput.setShouldMimicIOSBehavior(false);
32+
};
33+
}, []);
34+
35+
return (
36+
<AvoidSoftInputView
37+
onSoftInputHidden={onKeyboardHidden}
38+
onSoftInputShown={onKeyboardShown}
39+
{...rest}
40+
/>
41+
);
42+
};
43+
44+
export default AvoidKeyboardView;

packages/core/src/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export {
7373
Spacer,
7474
Square,
7575
} from "./components/Layout";
76+
export { default as AvoidKeyboardView } from "./components/AvoidKeyboardView";
7677

7778
/* Deprecated: Fix or Delete! */
7879
export { default as AccordionItem } from "./deprecated-components/AccordionItem";

packages/maps/jest-setup.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Needed to address failing test caused by react-native-avoid-softinput
2+
jest.mock("react-native/Libraries/EventEmitter/NativeEventEmitter");

packages/maps/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
"jest": {
5454
"preset": "jest-expo",
5555
"setupFilesAfterEnv": [
56-
"@testing-library/jest-native/extend-expect"
56+
"@testing-library/jest-native/extend-expect",
57+
"./jest-setup.js"
5758
],
5859
"testPathIgnorePatterns": [
5960
"lib",

packages/ui/src/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export {
6767
VStack,
6868
ZStack,
6969
PickerItem,
70+
AvoidKeyboardView,
7071
} from "@draftbit/core";
7172

7273
/**

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15316,6 +15316,11 @@ react-is@^16.13.0, react-is@^16.13.1, react-is@^16.7.0:
1531615316
resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0"
1531715317
integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==
1531815318

15319+
react-native-avoid-softinput@^4.0.1:
15320+
version "4.0.1"
15321+
resolved "https://registry.yarnpkg.com/react-native-avoid-softinput/-/react-native-avoid-softinput-4.0.1.tgz#c08802f66c46ddc91f72d05d1b80644102f80a30"
15322+
integrity sha512-feMt+Pb/wEcuobbIRDHXj1leXT15uC8CekgwMb/t8s61kWy5ifCGtX/YqDZMDRiD0sqeFLZx0gykLQOSrCpybA==
15323+
1531915324
react-native-codegen@^0.71.5:
1532015325
version "0.71.5"
1532115326
resolved "https://registry.yarnpkg.com/react-native-codegen/-/react-native-codegen-0.71.5.tgz#454a42a891cd4ca5fc436440d301044dc1349c14"

0 commit comments

Comments
 (0)