react-native-universal-keyboard-aware-scrollview 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +145 -148
- package/package.json +1 -1
- package/src/NativeModule.ts +45 -41
- package/src/components/KeyboardAwareScrollView.tsx +258 -357
- package/src/hooks/index.ts +5 -1
- package/src/hooks/useKeyboard.ts +65 -305
- package/src/index.ts +13 -16
- package/src/types.ts +30 -67
- package/src/utils/KeyboardController.ts +10 -97
|
@@ -1,111 +1,24 @@
|
|
|
1
|
-
import { Keyboard
|
|
2
|
-
import {
|
|
3
|
-
UniversalKeyboardModule,
|
|
4
|
-
isNativeModuleAvailable,
|
|
5
|
-
} from '../NativeModule';
|
|
1
|
+
import { Keyboard } from 'react-native';
|
|
6
2
|
|
|
7
3
|
/**
|
|
8
|
-
* KeyboardController - Utility
|
|
9
|
-
*
|
|
10
|
-
* Provides static methods for dismissing the keyboard and querying keyboard state.
|
|
11
|
-
* Uses native module when available for more reliable behavior in modals.
|
|
4
|
+
* KeyboardController - Utility for controlling keyboard
|
|
12
5
|
*/
|
|
13
6
|
export class KeyboardController {
|
|
14
7
|
/**
|
|
15
|
-
* Dismiss the keyboard
|
|
16
|
-
*
|
|
17
|
-
* Uses native implementation when available for better reliability,
|
|
18
|
-
* especially in modal contexts.
|
|
8
|
+
* Dismiss the keyboard
|
|
19
9
|
*/
|
|
20
|
-
static
|
|
21
|
-
if (isNativeModuleAvailable()) {
|
|
22
|
-
try {
|
|
23
|
-
await UniversalKeyboardModule.dismissKeyboard();
|
|
24
|
-
return;
|
|
25
|
-
} catch (error) {
|
|
26
|
-
// Fall through to RN Keyboard
|
|
27
|
-
}
|
|
28
|
-
}
|
|
10
|
+
static dismiss(): void {
|
|
29
11
|
Keyboard.dismiss();
|
|
30
12
|
}
|
|
31
13
|
|
|
32
14
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* @returns Keyboard height in points/dp, or 0 if keyboard is hidden
|
|
15
|
+
* Add keyboard listener
|
|
36
16
|
*/
|
|
37
|
-
static
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return 0;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return 0;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Check if the keyboard is currently visible
|
|
50
|
-
*
|
|
51
|
-
* @returns true if keyboard is visible, false otherwise
|
|
52
|
-
*/
|
|
53
|
-
static async isVisible(): Promise<boolean> {
|
|
54
|
-
if (isNativeModuleAvailable()) {
|
|
55
|
-
try {
|
|
56
|
-
return await UniversalKeyboardModule.isKeyboardVisible();
|
|
57
|
-
} catch (error) {
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Start listening for keyboard events on the native side
|
|
66
|
-
*
|
|
67
|
-
* Call this if you want to use the native event emitter directly.
|
|
68
|
-
* Usually not needed as useKeyboard hook handles this automatically.
|
|
69
|
-
*/
|
|
70
|
-
static async startListening(): Promise<boolean> {
|
|
71
|
-
if (isNativeModuleAvailable()) {
|
|
72
|
-
try {
|
|
73
|
-
return await UniversalKeyboardModule.startListening();
|
|
74
|
-
} catch (error) {
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Stop listening for keyboard events on the native side
|
|
83
|
-
*
|
|
84
|
-
* Call this to clean up native listeners if you called startListening directly.
|
|
85
|
-
*/
|
|
86
|
-
static async stopListening(): Promise<boolean> {
|
|
87
|
-
if (isNativeModuleAvailable()) {
|
|
88
|
-
try {
|
|
89
|
-
return await UniversalKeyboardModule.stopListening();
|
|
90
|
-
} catch (error) {
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Check if the current platform is supported
|
|
99
|
-
*/
|
|
100
|
-
static isSupported(): boolean {
|
|
101
|
-
return Platform.OS === 'ios' || Platform.OS === 'android';
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Check if native module is available
|
|
106
|
-
*/
|
|
107
|
-
static isNativeModuleAvailable(): boolean {
|
|
108
|
-
return isNativeModuleAvailable();
|
|
17
|
+
static addListener(
|
|
18
|
+
event: 'keyboardDidShow' | 'keyboardDidHide' | 'keyboardWillShow' | 'keyboardWillHide',
|
|
19
|
+
callback: (e: any) => void
|
|
20
|
+
) {
|
|
21
|
+
return Keyboard.addListener(event, callback);
|
|
109
22
|
}
|
|
110
23
|
}
|
|
111
24
|
|