forked from kirillzyusko/react-native-keyboard-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bindings.native.ts
62 lines (55 loc) · 2.2 KB
/
bindings.native.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { NativeEventEmitter, Platform } from "react-native";
import type {
FocusedInputEventsModule,
KeyboardControllerNativeModule,
KeyboardControllerProps,
KeyboardEventsModule,
KeyboardGestureAreaProps,
OverKeyboardViewProps,
WindowDimensionsEventsModule,
} from "./types";
const LINKING_ERROR =
`The package 'react-native-keyboard-controller' doesn't seem to be linked. Make sure: \n\n` +
Platform.select({ ios: "- You have run 'pod install'\n", default: "" }) +
"- You rebuilt the app after installing the package\n" +
"- You are not using Expo Go\n";
const RCTKeyboardController =
require("./specs/NativeKeyboardController").default;
export const KeyboardControllerNative = (
RCTKeyboardController
? RCTKeyboardController
: new Proxy(
{},
{
get() {
throw new Error(LINKING_ERROR);
},
},
)
) as KeyboardControllerNativeModule;
const KEYBOARD_CONTROLLER_NAMESPACE = "KeyboardController::";
const eventEmitter = new NativeEventEmitter(KeyboardControllerNative);
export const KeyboardEvents: KeyboardEventsModule = {
addListener: (name, cb) =>
eventEmitter.addListener(KEYBOARD_CONTROLLER_NAMESPACE + name, cb),
};
/**
* This API is not documented, it's for internal usage only (for now), and is a subject to potential breaking changes in future.
* Use it with cautious.
*/
export const FocusedInputEvents: FocusedInputEventsModule = {
addListener: (name, cb) =>
eventEmitter.addListener(KEYBOARD_CONTROLLER_NAMESPACE + name, cb),
};
export const WindowDimensionsEvents: WindowDimensionsEventsModule = {
addListener: (name, cb) =>
eventEmitter.addListener(KEYBOARD_CONTROLLER_NAMESPACE + name, cb),
};
export const KeyboardControllerView: React.FC<KeyboardControllerProps> =
require("./specs/KeyboardControllerViewNativeComponent").default;
export const KeyboardGestureArea: React.FC<KeyboardGestureAreaProps> =
Platform.OS === "android" && Platform.Version >= 30
? require("./specs/KeyboardGestureAreaNativeComponent").default
: ({ children }: KeyboardGestureAreaProps) => children;
export const RCTOverKeyboardView: React.FC<OverKeyboardViewProps> =
require("./specs/OverKeyboardViewNativeComponent").default;