react-native-keyboard-controller 1.7.0 → 1.8.0
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 +1 -0
- package/android/src/fabric/java/com/reactnativekeyboardcontroller/KeyboardControllerViewManager.kt +5 -0
- package/android/src/main/java/com/reactnativekeyboardcontroller/managers/KeyboardControllerViewManagerImpl.kt +4 -0
- package/android/src/main/java/com/reactnativekeyboardcontroller/views/EdgeToEdgeReactViewGroup.kt +111 -49
- package/android/src/paper/java/com/reactnativekeyboardcontroller/KeyboardControllerViewManager.kt +5 -0
- package/ios/KeyboardControllerView.mm +16 -1
- package/ios/KeyboardControllerViewManager.mm +4 -0
- package/ios/KeyboardControllerViewManager.swift +11 -1
- package/lib/commonjs/animated.js +17 -3
- package/lib/commonjs/animated.js.map +1 -1
- package/lib/commonjs/components/KeyboardAvoidingView/hooks.js +9 -1
- package/lib/commonjs/components/KeyboardAvoidingView/hooks.js.map +1 -1
- package/lib/commonjs/components/KeyboardAvoidingView/index.js +7 -4
- package/lib/commonjs/components/KeyboardAvoidingView/index.js.map +1 -1
- package/lib/commonjs/context.js +3 -1
- package/lib/commonjs/context.js.map +1 -1
- package/lib/commonjs/hooks.js +8 -0
- package/lib/commonjs/hooks.js.map +1 -1
- package/lib/commonjs/index.js +0 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/monkey-patch.android.js +32 -20
- package/lib/commonjs/monkey-patch.android.js.map +1 -1
- package/lib/commonjs/monkey-patch.js +11 -1
- package/lib/commonjs/monkey-patch.js.map +1 -1
- package/lib/commonjs/specs/KeyboardControllerViewNativeComponent.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/module/animated.js +18 -4
- package/lib/module/animated.js.map +1 -1
- package/lib/module/components/KeyboardAvoidingView/hooks.js +9 -1
- package/lib/module/components/KeyboardAvoidingView/hooks.js.map +1 -1
- package/lib/module/components/KeyboardAvoidingView/index.js +8 -5
- package/lib/module/components/KeyboardAvoidingView/index.js.map +1 -1
- package/lib/module/context.js +3 -1
- package/lib/module/context.js.map +1 -1
- package/lib/module/hooks.js +7 -0
- package/lib/module/hooks.js.map +1 -1
- package/lib/module/index.js +0 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/monkey-patch.android.js +26 -20
- package/lib/module/monkey-patch.android.js.map +1 -1
- package/lib/module/monkey-patch.js +3 -0
- package/lib/module/monkey-patch.js.map +1 -1
- package/lib/module/specs/KeyboardControllerViewNativeComponent.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/typescript/animated.d.ts +8 -1
- package/lib/typescript/components/KeyboardAvoidingView/hooks.d.ts +1 -0
- package/lib/typescript/context.d.ts +4 -2
- package/lib/typescript/hooks.d.ts +4 -0
- package/lib/typescript/index.d.ts +0 -1
- package/lib/typescript/monkey-patch.android.d.ts +2 -1
- package/lib/typescript/monkey-patch.d.ts +2 -0
- package/lib/typescript/specs/KeyboardControllerViewNativeComponent.d.ts +1 -0
- package/lib/typescript/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/animated.tsx +25 -4
- package/src/components/KeyboardAvoidingView/hooks.ts +8 -1
- package/src/components/KeyboardAvoidingView/index.tsx +8 -4
- package/src/context.ts +6 -2
- package/src/hooks.ts +6 -0
- package/src/index.ts +0 -2
- package/src/monkey-patch.android.ts +27 -21
- package/src/monkey-patch.ts +3 -0
- package/src/specs/KeyboardControllerViewNativeComponent.ts +1 -0
- package/src/types.ts +1 -0
package/README.md
CHANGED
|
@@ -13,6 +13,7 @@ Keyboard manager which works in identical way on both iOS and Android.
|
|
|
13
13
|
- module for changing soft input mode on Android 🤔
|
|
14
14
|
- reanimated support 🚀
|
|
15
15
|
- interactive keyboard dismissing 👆📱
|
|
16
|
+
- re-worked prebuilt components (such as `KeyboardAvoidingView`) 📚
|
|
16
17
|
- works with any navigation library 🧭
|
|
17
18
|
- and more is coming... Stay tuned! 😊
|
|
18
19
|
|
package/android/src/fabric/java/com/reactnativekeyboardcontroller/KeyboardControllerViewManager.kt
CHANGED
|
@@ -37,6 +37,11 @@ class KeyboardControllerViewManager(mReactContext: ReactApplicationContext) :
|
|
|
37
37
|
return manager.setNavigationBarTranslucent(view as EdgeToEdgeReactViewGroup, value)
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
@ReactProp(name = "enabled")
|
|
41
|
+
override fun setEnabled(view: ReactViewGroup, value: Boolean) {
|
|
42
|
+
return manager.setEnabled(view as EdgeToEdgeReactViewGroup, value)
|
|
43
|
+
}
|
|
44
|
+
|
|
40
45
|
override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any> {
|
|
41
46
|
return manager.getExportedCustomDirectEventTypeConstants()
|
|
42
47
|
}
|
|
@@ -11,6 +11,10 @@ class KeyboardControllerViewManagerImpl(mReactContext: ReactApplicationContext)
|
|
|
11
11
|
return EdgeToEdgeReactViewGroup(reactContext)
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
fun setEnabled(view: EdgeToEdgeReactViewGroup, enabled: Boolean) {
|
|
15
|
+
view.setActive(enabled)
|
|
16
|
+
}
|
|
17
|
+
|
|
14
18
|
fun setStatusBarTranslucent(view: EdgeToEdgeReactViewGroup, isStatusBarTranslucent: Boolean) {
|
|
15
19
|
view.setStatusBarTranslucent(isStatusBarTranslucent)
|
|
16
20
|
}
|
package/android/src/main/java/com/reactnativekeyboardcontroller/views/EdgeToEdgeReactViewGroup.kt
CHANGED
|
@@ -19,71 +19,43 @@ import com.reactnativekeyboardcontroller.extensions.rootView
|
|
|
19
19
|
|
|
20
20
|
private val TAG = EdgeToEdgeReactViewGroup::class.qualifiedName
|
|
21
21
|
|
|
22
|
+
@Suppress("detekt:TooManyFunctions")
|
|
22
23
|
@SuppressLint("ViewConstructor")
|
|
23
24
|
class EdgeToEdgeReactViewGroup(private val reactContext: ThemedReactContext) : ReactViewGroup(reactContext) {
|
|
25
|
+
// props
|
|
24
26
|
private var isStatusBarTranslucent = false
|
|
25
27
|
private var isNavigationBarTranslucent = false
|
|
28
|
+
private var active = false
|
|
29
|
+
|
|
30
|
+
// internal class members
|
|
26
31
|
private var eventView: ReactViewGroup? = null
|
|
32
|
+
private var wasMounted = false
|
|
27
33
|
|
|
28
34
|
// region View lifecycles
|
|
29
35
|
override fun onAttachedToWindow() {
|
|
30
36
|
super.onAttachedToWindow()
|
|
31
37
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
38
|
+
if (!wasMounted) {
|
|
39
|
+
// skip logic with callback re-creation if it was first render/mount
|
|
40
|
+
wasMounted = true
|
|
35
41
|
return
|
|
36
42
|
}
|
|
37
43
|
|
|
38
|
-
|
|
39
|
-
WindowCompat.setDecorFitsSystemWindows(
|
|
40
|
-
activity.window,
|
|
41
|
-
false,
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
eventView = ReactViewGroup(context)
|
|
45
|
-
val root = this.getContentView()
|
|
46
|
-
root?.addView(eventView)
|
|
47
|
-
|
|
48
|
-
val callback = KeyboardAnimationCallback(
|
|
49
|
-
view = this,
|
|
50
|
-
persistentInsetTypes = WindowInsetsCompat.Type.systemBars(),
|
|
51
|
-
deferredInsetTypes = WindowInsetsCompat.Type.ime(),
|
|
52
|
-
dispatchMode = WindowInsetsAnimationCompat.Callback.DISPATCH_MODE_CONTINUE_ON_SUBTREE,
|
|
53
|
-
context = reactContext,
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
eventView?.let {
|
|
57
|
-
ViewCompat.setWindowInsetsAnimationCallback(it, callback)
|
|
58
|
-
ViewCompat.setOnApplyWindowInsetsListener(it, callback)
|
|
59
|
-
it.requestApplyInsetsWhenAttached()
|
|
60
|
-
}
|
|
44
|
+
this.setupKeyboardCallbacks()
|
|
61
45
|
}
|
|
62
46
|
|
|
63
47
|
override fun onDetachedFromWindow() {
|
|
64
48
|
super.onDetachedFromWindow()
|
|
65
49
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
fun setStatusBarTranslucent(isStatusBarTranslucent: Boolean) {
|
|
72
|
-
this.isStatusBarTranslucent = isStatusBarTranslucent
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
fun setNavigationBarTranslucent(isNavigationBarTranslucent: Boolean) {
|
|
76
|
-
this.isNavigationBarTranslucent = isNavigationBarTranslucent
|
|
50
|
+
// we need to remove view asynchronously from `onDetachedFromWindow` method
|
|
51
|
+
// otherwise we may face NPE when app is getting opened via universal link
|
|
52
|
+
// see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/242
|
|
53
|
+
// for more details
|
|
54
|
+
Handler(Looper.getMainLooper()).post { this.removeKeyboardCallbacks() }
|
|
77
55
|
}
|
|
78
56
|
// endregion
|
|
79
57
|
|
|
80
|
-
// region
|
|
81
|
-
private fun getContentView(): FitWindowsLinearLayout? {
|
|
82
|
-
return reactContext.currentActivity?.window?.decorView?.rootView?.findViewById(
|
|
83
|
-
androidx.appcompat.R.id.action_bar_root,
|
|
84
|
-
)
|
|
85
|
-
}
|
|
86
|
-
|
|
58
|
+
// region State manager helpers
|
|
87
59
|
private fun setupWindowInsets() {
|
|
88
60
|
val rootView = reactContext.rootView
|
|
89
61
|
if (rootView != null) {
|
|
@@ -94,16 +66,20 @@ class EdgeToEdgeReactViewGroup(private val reactContext: ThemedReactContext) : R
|
|
|
94
66
|
FrameLayout.LayoutParams.MATCH_PARENT,
|
|
95
67
|
)
|
|
96
68
|
|
|
69
|
+
val shouldApplyZeroPaddingTop = !active || this.isStatusBarTranslucent
|
|
70
|
+
val shouldApplyZeroPaddingBottom = !active || this.isNavigationBarTranslucent
|
|
97
71
|
params.setMargins(
|
|
98
72
|
0,
|
|
99
|
-
if (
|
|
73
|
+
if (shouldApplyZeroPaddingTop) {
|
|
100
74
|
0
|
|
101
75
|
} else {
|
|
102
|
-
|
|
103
|
-
|
|
76
|
+
(
|
|
77
|
+
insets?.getInsets(WindowInsetsCompat.Type.systemBars())?.top
|
|
78
|
+
?: 0
|
|
79
|
+
)
|
|
104
80
|
},
|
|
105
81
|
0,
|
|
106
|
-
if (
|
|
82
|
+
if (shouldApplyZeroPaddingBottom) {
|
|
107
83
|
0
|
|
108
84
|
} else {
|
|
109
85
|
insets?.getInsets(WindowInsetsCompat.Type.navigationBars())?.bottom
|
|
@@ -113,9 +89,95 @@ class EdgeToEdgeReactViewGroup(private val reactContext: ThemedReactContext) : R
|
|
|
113
89
|
|
|
114
90
|
content?.layoutParams = params
|
|
115
91
|
|
|
116
|
-
insets
|
|
92
|
+
val defaultInsets = ViewCompat.onApplyWindowInsets(v, insets)
|
|
93
|
+
|
|
94
|
+
defaultInsets.replaceSystemWindowInsets(
|
|
95
|
+
defaultInsets.systemWindowInsetLeft,
|
|
96
|
+
if (this.isStatusBarTranslucent) 0 else defaultInsets.systemWindowInsetTop,
|
|
97
|
+
defaultInsets.systemWindowInsetRight,
|
|
98
|
+
defaultInsets.systemWindowInsetBottom,
|
|
99
|
+
)
|
|
117
100
|
}
|
|
118
101
|
}
|
|
119
102
|
}
|
|
103
|
+
|
|
104
|
+
private fun goToEdgeToEdge(edgeToEdge: Boolean) {
|
|
105
|
+
reactContext.currentActivity?.let {
|
|
106
|
+
WindowCompat.setDecorFitsSystemWindows(
|
|
107
|
+
it.window,
|
|
108
|
+
!edgeToEdge,
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
private fun setupKeyboardCallbacks() {
|
|
114
|
+
val activity = reactContext.currentActivity
|
|
115
|
+
|
|
116
|
+
if (activity != null) {
|
|
117
|
+
eventView = ReactViewGroup(context)
|
|
118
|
+
val root = this.getContentView()
|
|
119
|
+
root?.addView(eventView)
|
|
120
|
+
|
|
121
|
+
val callback = KeyboardAnimationCallback(
|
|
122
|
+
view = this,
|
|
123
|
+
persistentInsetTypes = WindowInsetsCompat.Type.systemBars(),
|
|
124
|
+
deferredInsetTypes = WindowInsetsCompat.Type.ime(),
|
|
125
|
+
dispatchMode = WindowInsetsAnimationCompat.Callback.DISPATCH_MODE_CONTINUE_ON_SUBTREE,
|
|
126
|
+
context = reactContext,
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
eventView?.let {
|
|
130
|
+
ViewCompat.setWindowInsetsAnimationCallback(it, callback)
|
|
131
|
+
ViewCompat.setOnApplyWindowInsetsListener(it, callback)
|
|
132
|
+
it.requestApplyInsetsWhenAttached()
|
|
133
|
+
}
|
|
134
|
+
} else {
|
|
135
|
+
Log.w(TAG, "Can not setup keyboard animation listener, since `currentActivity` is null")
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
private fun removeKeyboardCallbacks() {
|
|
140
|
+
eventView.removeSelf()
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
private fun getContentView(): FitWindowsLinearLayout? {
|
|
144
|
+
return reactContext.currentActivity?.window?.decorView?.rootView?.findViewById(
|
|
145
|
+
androidx.appcompat.R.id.action_bar_root,
|
|
146
|
+
)
|
|
147
|
+
}
|
|
148
|
+
// endregion
|
|
149
|
+
|
|
150
|
+
// region State managers
|
|
151
|
+
private fun enable() {
|
|
152
|
+
this.goToEdgeToEdge(true)
|
|
153
|
+
this.setupWindowInsets()
|
|
154
|
+
this.setupKeyboardCallbacks()
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
private fun disable() {
|
|
158
|
+
this.goToEdgeToEdge(false)
|
|
159
|
+
this.setupWindowInsets()
|
|
160
|
+
this.removeKeyboardCallbacks()
|
|
161
|
+
}
|
|
162
|
+
// endregion
|
|
163
|
+
|
|
164
|
+
// region Props setters
|
|
165
|
+
fun setStatusBarTranslucent(isStatusBarTranslucent: Boolean) {
|
|
166
|
+
this.isStatusBarTranslucent = isStatusBarTranslucent
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
fun setNavigationBarTranslucent(isNavigationBarTranslucent: Boolean) {
|
|
170
|
+
this.isNavigationBarTranslucent = isNavigationBarTranslucent
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
fun setActive(active: Boolean) {
|
|
174
|
+
this.active = active
|
|
175
|
+
|
|
176
|
+
if (active) {
|
|
177
|
+
this.enable()
|
|
178
|
+
} else {
|
|
179
|
+
this.disable()
|
|
180
|
+
}
|
|
181
|
+
}
|
|
120
182
|
// endregion
|
|
121
183
|
}
|
package/android/src/paper/java/com/reactnativekeyboardcontroller/KeyboardControllerViewManager.kt
CHANGED
|
@@ -16,6 +16,11 @@ class KeyboardControllerViewManager(mReactContext: ReactApplicationContext) : Re
|
|
|
16
16
|
return manager.createViewInstance(reactContext)
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
@ReactProp(name = "enabled")
|
|
20
|
+
fun setEnabled(view: EdgeToEdgeReactViewGroup, enabled: Boolean) {
|
|
21
|
+
manager.setEnabled(view, enabled)
|
|
22
|
+
}
|
|
23
|
+
|
|
19
24
|
@ReactProp(name = "statusBarTranslucent")
|
|
20
25
|
fun setStatusBarTranslucent(view: EdgeToEdgeReactViewGroup, isStatusBarTranslucent: Boolean) {
|
|
21
26
|
manager.setStatusBarTranslucent(view, isStatusBarTranslucent)
|
|
@@ -110,12 +110,27 @@ using namespace facebook::react;
|
|
|
110
110
|
onNotify:^(NSString *event, NSDictionary *data) {
|
|
111
111
|
[KeyboardController.shared sendEvent:event body:data];
|
|
112
112
|
}];
|
|
113
|
-
[observer mount];
|
|
114
113
|
}
|
|
115
114
|
|
|
116
115
|
return self;
|
|
117
116
|
}
|
|
118
117
|
|
|
118
|
+
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
|
|
119
|
+
{
|
|
120
|
+
const auto &oldViewProps = *std::static_pointer_cast<const KeyboardControllerViewProps>(_props);
|
|
121
|
+
const auto &newViewProps = *std::static_pointer_cast<const KeyboardControllerViewProps>(props);
|
|
122
|
+
|
|
123
|
+
if (newViewProps.enabled != oldViewProps.enabled) {
|
|
124
|
+
if (newViewProps.enabled) {
|
|
125
|
+
[observer mount];
|
|
126
|
+
} else {
|
|
127
|
+
[observer unmount];
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
[super updateProps:props oldProps:oldProps];
|
|
132
|
+
}
|
|
133
|
+
|
|
119
134
|
Class<RCTComponentViewProtocol> KeyboardControllerViewCls(void)
|
|
120
135
|
{
|
|
121
136
|
return KeyboardControllerView.class;
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
@interface RCT_EXTERN_MODULE (KeyboardControllerViewManager, RCTViewManager)
|
|
4
4
|
|
|
5
|
+
// props
|
|
6
|
+
RCT_EXPORT_VIEW_PROPERTY(enabled, BOOL)
|
|
7
|
+
|
|
8
|
+
// callbacks
|
|
5
9
|
RCT_EXPORT_VIEW_PROPERTY(onKeyboardMoveStart, RCTDirectEventBlock);
|
|
6
10
|
RCT_EXPORT_VIEW_PROPERTY(onKeyboardMove, RCTDirectEventBlock);
|
|
7
11
|
RCT_EXPORT_VIEW_PROPERTY(onKeyboardMoveEnd, RCTDirectEventBlock);
|
|
@@ -14,11 +14,21 @@ class KeyboardControllerView: UIView {
|
|
|
14
14
|
private var keyboardObserver: KeyboardMovementObserver?
|
|
15
15
|
private var eventDispatcher: RCTEventDispatcherProtocol
|
|
16
16
|
private var bridge: RCTBridge
|
|
17
|
-
// react
|
|
17
|
+
// react callbacks
|
|
18
18
|
@objc var onKeyboardMoveStart: RCTDirectEventBlock?
|
|
19
19
|
@objc var onKeyboardMove: RCTDirectEventBlock?
|
|
20
20
|
@objc var onKeyboardMoveEnd: RCTDirectEventBlock?
|
|
21
21
|
@objc var onKeyboardMoveInteractive: RCTDirectEventBlock?
|
|
22
|
+
// react props
|
|
23
|
+
@objc var enabled: ObjCBool = true {
|
|
24
|
+
didSet {
|
|
25
|
+
if enabled.boolValue {
|
|
26
|
+
keyboardObserver?.mount()
|
|
27
|
+
} else {
|
|
28
|
+
keyboardObserver?.unmount()
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
22
32
|
|
|
23
33
|
init(frame: CGRect, bridge: RCTBridge) {
|
|
24
34
|
self.bridge = bridge
|
package/lib/commonjs/animated.js
CHANGED
|
@@ -11,6 +11,7 @@ var _context = require("./context");
|
|
|
11
11
|
var _internal = require("./internal");
|
|
12
12
|
var _bindings = require("./bindings");
|
|
13
13
|
var _reanimated = require("./reanimated");
|
|
14
|
+
var _monkeyPatch = require("./monkey-patch");
|
|
14
15
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
15
16
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
16
17
|
const KeyboardControllerViewAnimated = _reactNativeReanimated.default.createAnimatedComponent(_reactNative.Animated.createAnimatedComponent(_bindings.KeyboardControllerView));
|
|
@@ -27,8 +28,10 @@ const KeyboardProvider = _ref => {
|
|
|
27
28
|
let {
|
|
28
29
|
children,
|
|
29
30
|
statusBarTranslucent,
|
|
30
|
-
navigationBarTranslucent
|
|
31
|
+
navigationBarTranslucent,
|
|
32
|
+
enabled: initiallyEnabled = true
|
|
31
33
|
} = _ref;
|
|
34
|
+
const [enabled, setEnabled] = (0, _react.useState)(initiallyEnabled);
|
|
32
35
|
// animated values
|
|
33
36
|
const progress = (0, _internal.useAnimatedValue)(0);
|
|
34
37
|
const height = (0, _internal.useAnimatedValue)(0);
|
|
@@ -41,6 +44,7 @@ const KeyboardProvider = _ref => {
|
|
|
41
44
|
} = (0, _internal.useSharedHandlers)();
|
|
42
45
|
// memo
|
|
43
46
|
const context = (0, _react.useMemo)(() => ({
|
|
47
|
+
enabled,
|
|
44
48
|
animated: {
|
|
45
49
|
progress: progress,
|
|
46
50
|
height: _reactNative.Animated.multiply(height, -1)
|
|
@@ -49,8 +53,9 @@ const KeyboardProvider = _ref => {
|
|
|
49
53
|
progress: progressSV,
|
|
50
54
|
height: heightSV
|
|
51
55
|
},
|
|
52
|
-
setHandlers
|
|
53
|
-
|
|
56
|
+
setHandlers,
|
|
57
|
+
setEnabled
|
|
58
|
+
}), [enabled]);
|
|
54
59
|
const style = (0, _react.useMemo)(() => [styles.hidden, {
|
|
55
60
|
transform: [{
|
|
56
61
|
translateX: height
|
|
@@ -100,9 +105,18 @@ const KeyboardProvider = _ref => {
|
|
|
100
105
|
broadcast('onInteractive', event);
|
|
101
106
|
}
|
|
102
107
|
}, []);
|
|
108
|
+
// effects
|
|
109
|
+
(0, _react.useEffect)(() => {
|
|
110
|
+
if (enabled) {
|
|
111
|
+
(0, _monkeyPatch.applyMonkeyPatch)();
|
|
112
|
+
} else {
|
|
113
|
+
(0, _monkeyPatch.revertMonkeyPatch)();
|
|
114
|
+
}
|
|
115
|
+
}, [enabled]);
|
|
103
116
|
return /*#__PURE__*/_react.default.createElement(_context.KeyboardContext.Provider, {
|
|
104
117
|
value: context
|
|
105
118
|
}, /*#__PURE__*/_react.default.createElement(KeyboardControllerViewAnimated, {
|
|
119
|
+
enabled: enabled,
|
|
106
120
|
onKeyboardMoveReanimated: handler,
|
|
107
121
|
onKeyboardMoveStart: _reactNative.Platform.OS === 'ios' ? onKeyboardMove : undefined,
|
|
108
122
|
onKeyboardMove: _reactNative.Platform.OS === 'android' ? onKeyboardMove : undefined,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["KeyboardControllerViewAnimated","Reanimated","createAnimatedComponent","Animated","KeyboardControllerView","styles","StyleSheet","create","container","flex","hidden","display","position","KeyboardProvider","children","statusBarTranslucent","navigationBarTranslucent","progress","useAnimatedValue","height","progressSV","useSharedValue","heightSV","setHandlers","broadcast","useSharedHandlers","context","useMemo","animated","multiply","reanimated","style","transform","translateX","translateY","onKeyboardMove","event","nativeEvent","useNativeDriver","updateSharedValues","platforms","includes","Platform","OS","value","handler","useAnimatedKeyboardHandler","onKeyboardMoveStart","onKeyboardMoveEnd","onKeyboardMoveInteractive","undefined"],"sources":["animated.tsx"],"sourcesContent":["import React, { useMemo } from 'react';\nimport { Animated, Platform, StyleSheet, ViewStyle } from 'react-native';\nimport Reanimated, { useSharedValue } from 'react-native-reanimated';\n\nimport { KeyboardContext } from './context';\nimport { useSharedHandlers, useAnimatedValue } from './internal';\nimport { KeyboardControllerView } from './bindings';\nimport { useAnimatedKeyboardHandler } from './reanimated';\n\nimport type {\n KeyboardControllerProps,\n KeyboardHandler,\n NativeEvent,\n} from './types';\n\nconst KeyboardControllerViewAnimated = Reanimated.createAnimatedComponent(\n Animated.createAnimatedComponent(\n KeyboardControllerView\n ) as React.FC<KeyboardControllerProps>\n);\n\ntype Styles = {\n container: ViewStyle;\n hidden: ViewStyle;\n};\n\nconst styles = StyleSheet.create<Styles>({\n container: {\n flex: 1,\n },\n hidden: {\n display: 'none',\n position: 'absolute',\n },\n});\n\ntype KeyboardProviderProps = {\n children: React.ReactNode;\n /**\n * Set the value to `true`, if you use translucent status bar on Android.\n * If you already control status bar translucency via `react-native-screens`\n * or `StatusBar` component from `react-native`, you can ignore it.\n * Defaults to `false`.\n *\n * @see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/14\n * @platform android\n */\n statusBarTranslucent?: boolean;\n /**\n * Set the value to `true`, if you use translucent navigation bar on Android.\n * Defaults to `false`.\n *\n * @see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/119\n * @platform android\n */\n navigationBarTranslucent?: boolean;\n};\n\nexport const KeyboardProvider = ({\n children,\n statusBarTranslucent,\n navigationBarTranslucent,\n}: KeyboardProviderProps) => {\n // animated values\n const progress = useAnimatedValue(0);\n const height = useAnimatedValue(0);\n // shared values\n const progressSV = useSharedValue(0);\n const heightSV = useSharedValue(0);\n const { setHandlers, broadcast } = useSharedHandlers<KeyboardHandler>();\n // memo\n const context = useMemo(\n () => ({\n animated: { progress: progress, height: Animated.multiply(height, -1) },\n reanimated: { progress: progressSV, height: heightSV },\n setHandlers,\n }),\n []\n );\n const style = useMemo(\n () => [\n styles.hidden,\n { transform: [{ translateX: height }, { translateY: progress }] },\n ],\n []\n );\n const onKeyboardMove = useMemo(\n () =>\n Animated.event(\n [\n {\n nativeEvent: {\n progress,\n height,\n },\n },\n ],\n { useNativeDriver: true }\n ),\n []\n );\n // handlers\n const updateSharedValues = (event: NativeEvent, platforms: string[]) => {\n 'worklet';\n\n if (platforms.includes(Platform.OS)) {\n progressSV.value = event.progress;\n heightSV.value = -event.height;\n }\n };\n const handler = useAnimatedKeyboardHandler(\n {\n onKeyboardMoveStart: (event: NativeEvent) => {\n 'worklet';\n\n broadcast('onStart', event);\n updateSharedValues(event, ['ios']);\n },\n onKeyboardMove: (event: NativeEvent) => {\n 'worklet';\n\n broadcast('onMove', event);\n updateSharedValues(event, ['android']);\n },\n onKeyboardMoveEnd: (event: NativeEvent) => {\n 'worklet';\n\n broadcast('onEnd', event);\n },\n onKeyboardMoveInteractive: (event: NativeEvent) => {\n 'worklet';\n\n updateSharedValues(event, ['android', 'ios']);\n broadcast('onInteractive', event);\n },\n },\n []\n );\n\n return (\n <KeyboardContext.Provider value={context}>\n <KeyboardControllerViewAnimated\n onKeyboardMoveReanimated={handler}\n onKeyboardMoveStart={Platform.OS === 'ios' ? onKeyboardMove : undefined}\n onKeyboardMove={Platform.OS === 'android' ? onKeyboardMove : undefined}\n onKeyboardMoveInteractive={onKeyboardMove}\n navigationBarTranslucent={navigationBarTranslucent}\n statusBarTranslucent={statusBarTranslucent}\n // @ts-expect-error https://github.com/software-mansion/react-native-reanimated/pull/4923\n style={styles.container}\n >\n {children}\n </KeyboardControllerViewAnimated>\n <Animated.View\n // we are using this small hack, because if the component (where\n // animated value has been used) is unmounted, then animation will\n // stop receiving events (seems like it's react-native optimization).\n // So we need to keep a reference to the animated value, to keep it's\n // always mounted (keep a reference to an animated value).\n //\n // To test why it's needed, try to open screen which consumes Animated.Value\n // then close it and open it again (for example 'Animated transition').\n style={style}\n />\n </KeyboardContext.Provider>\n );\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AAEA;AACA;AACA;AACA;
|
|
1
|
+
{"version":3,"names":["KeyboardControllerViewAnimated","Reanimated","createAnimatedComponent","Animated","KeyboardControllerView","styles","StyleSheet","create","container","flex","hidden","display","position","KeyboardProvider","children","statusBarTranslucent","navigationBarTranslucent","enabled","initiallyEnabled","setEnabled","useState","progress","useAnimatedValue","height","progressSV","useSharedValue","heightSV","setHandlers","broadcast","useSharedHandlers","context","useMemo","animated","multiply","reanimated","style","transform","translateX","translateY","onKeyboardMove","event","nativeEvent","useNativeDriver","updateSharedValues","platforms","includes","Platform","OS","value","handler","useAnimatedKeyboardHandler","onKeyboardMoveStart","onKeyboardMoveEnd","onKeyboardMoveInteractive","useEffect","applyMonkeyPatch","revertMonkeyPatch","undefined"],"sources":["animated.tsx"],"sourcesContent":["import React, { useEffect, useMemo, useState } from 'react';\nimport { Animated, Platform, StyleSheet, ViewStyle } from 'react-native';\nimport Reanimated, { useSharedValue } from 'react-native-reanimated';\n\nimport { KeyboardAnimationContext, KeyboardContext } from './context';\nimport { useSharedHandlers, useAnimatedValue } from './internal';\nimport { KeyboardControllerView } from './bindings';\nimport { useAnimatedKeyboardHandler } from './reanimated';\n\nimport type {\n KeyboardControllerProps,\n KeyboardHandler,\n NativeEvent,\n} from './types';\nimport { applyMonkeyPatch, revertMonkeyPatch } from './monkey-patch';\n\nconst KeyboardControllerViewAnimated = Reanimated.createAnimatedComponent(\n Animated.createAnimatedComponent(\n KeyboardControllerView\n ) as React.FC<KeyboardControllerProps>\n);\n\ntype Styles = {\n container: ViewStyle;\n hidden: ViewStyle;\n};\n\nconst styles = StyleSheet.create<Styles>({\n container: {\n flex: 1,\n },\n hidden: {\n display: 'none',\n position: 'absolute',\n },\n});\n\ntype KeyboardProviderProps = {\n children: React.ReactNode;\n /**\n * Set the value to `true`, if you use translucent status bar on Android.\n * If you already control status bar translucency via `react-native-screens`\n * or `StatusBar` component from `react-native`, you can ignore it.\n * Defaults to `false`.\n *\n * @see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/14\n * @platform android\n */\n statusBarTranslucent?: boolean;\n /**\n * Set the value to `true`, if you use translucent navigation bar on Android.\n * Defaults to `false`.\n *\n * @see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/119\n * @platform android\n */\n navigationBarTranslucent?: boolean;\n /**\n * A boolean prop indicating whether the module is enabled. It indicate only initial state,\n * i. e. if you try to change this prop after component mount it will not have any effect.\n * To change the property in runtime use `useKeyboardController` hook and `setEnabled` method.\n * Defaults to `true`.\n */\n enabled?: boolean;\n};\n\nexport const KeyboardProvider = ({\n children,\n statusBarTranslucent,\n navigationBarTranslucent,\n enabled: initiallyEnabled = true,\n}: KeyboardProviderProps) => {\n const [enabled, setEnabled] = useState(initiallyEnabled);\n // animated values\n const progress = useAnimatedValue(0);\n const height = useAnimatedValue(0);\n // shared values\n const progressSV = useSharedValue(0);\n const heightSV = useSharedValue(0);\n const { setHandlers, broadcast } = useSharedHandlers<KeyboardHandler>();\n // memo\n const context = useMemo<KeyboardAnimationContext>(\n () => ({\n enabled,\n animated: { progress: progress, height: Animated.multiply(height, -1) },\n reanimated: { progress: progressSV, height: heightSV },\n setHandlers,\n setEnabled,\n }),\n [enabled]\n );\n const style = useMemo(\n () => [\n styles.hidden,\n { transform: [{ translateX: height }, { translateY: progress }] },\n ],\n []\n );\n const onKeyboardMove = useMemo(\n () =>\n Animated.event(\n [\n {\n nativeEvent: {\n progress,\n height,\n },\n },\n ],\n { useNativeDriver: true }\n ),\n []\n );\n // handlers\n const updateSharedValues = (event: NativeEvent, platforms: string[]) => {\n 'worklet';\n\n if (platforms.includes(Platform.OS)) {\n progressSV.value = event.progress;\n heightSV.value = -event.height;\n }\n };\n const handler = useAnimatedKeyboardHandler(\n {\n onKeyboardMoveStart: (event: NativeEvent) => {\n 'worklet';\n\n broadcast('onStart', event);\n updateSharedValues(event, ['ios']);\n },\n onKeyboardMove: (event: NativeEvent) => {\n 'worklet';\n\n broadcast('onMove', event);\n updateSharedValues(event, ['android']);\n },\n onKeyboardMoveEnd: (event: NativeEvent) => {\n 'worklet';\n\n broadcast('onEnd', event);\n },\n onKeyboardMoveInteractive: (event: NativeEvent) => {\n 'worklet';\n\n updateSharedValues(event, ['android', 'ios']);\n broadcast('onInteractive', event);\n },\n },\n []\n );\n // effects\n useEffect(() => {\n if (enabled) {\n applyMonkeyPatch();\n } else {\n revertMonkeyPatch();\n }\n }, [enabled]);\n\n return (\n <KeyboardContext.Provider value={context}>\n <KeyboardControllerViewAnimated\n enabled={enabled}\n onKeyboardMoveReanimated={handler}\n onKeyboardMoveStart={Platform.OS === 'ios' ? onKeyboardMove : undefined}\n onKeyboardMove={Platform.OS === 'android' ? onKeyboardMove : undefined}\n onKeyboardMoveInteractive={onKeyboardMove}\n navigationBarTranslucent={navigationBarTranslucent}\n statusBarTranslucent={statusBarTranslucent}\n // @ts-expect-error https://github.com/software-mansion/react-native-reanimated/pull/4923\n style={styles.container}\n >\n {children}\n </KeyboardControllerViewAnimated>\n <Animated.View\n // we are using this small hack, because if the component (where\n // animated value has been used) is unmounted, then animation will\n // stop receiving events (seems like it's react-native optimization).\n // So we need to keep a reference to the animated value, to keep it's\n // always mounted (keep a reference to an animated value).\n //\n // To test why it's needed, try to open screen which consumes Animated.Value\n // then close it and open it again (for example 'Animated transition').\n style={style}\n />\n </KeyboardContext.Provider>\n );\n};\n"],"mappings":"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"}
|
|
@@ -10,11 +10,13 @@ const useKeyboardAnimation = () => {
|
|
|
10
10
|
const heightWhenOpened = (0, _reactNativeReanimated.useSharedValue)(0);
|
|
11
11
|
const height = (0, _reactNativeReanimated.useSharedValue)(0);
|
|
12
12
|
const progress = (0, _reactNativeReanimated.useSharedValue)(0);
|
|
13
|
+
const isClosed = (0, _reactNativeReanimated.useSharedValue)(true);
|
|
13
14
|
(0, _hooks.useKeyboardHandler)({
|
|
14
15
|
onStart: e => {
|
|
15
16
|
'worklet';
|
|
16
17
|
|
|
17
18
|
if (e.height > 0) {
|
|
19
|
+
isClosed.value = false;
|
|
18
20
|
heightWhenOpened.value = e.height;
|
|
19
21
|
}
|
|
20
22
|
},
|
|
@@ -23,12 +25,18 @@ const useKeyboardAnimation = () => {
|
|
|
23
25
|
|
|
24
26
|
progress.value = e.progress;
|
|
25
27
|
height.value = e.height;
|
|
28
|
+
},
|
|
29
|
+
onEnd: e => {
|
|
30
|
+
'worklet';
|
|
31
|
+
|
|
32
|
+
isClosed.value = e.height === 0;
|
|
26
33
|
}
|
|
27
34
|
}, []);
|
|
28
35
|
return {
|
|
29
36
|
height,
|
|
30
37
|
progress,
|
|
31
|
-
heightWhenOpened
|
|
38
|
+
heightWhenOpened,
|
|
39
|
+
isClosed
|
|
32
40
|
};
|
|
33
41
|
};
|
|
34
42
|
exports.useKeyboardAnimation = useKeyboardAnimation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useKeyboardAnimation","heightWhenOpened","useSharedValue","height","progress","useKeyboardHandler","onStart","e","value","onMove"],"sources":["hooks.ts"],"sourcesContent":["import { useSharedValue } from 'react-native-reanimated';\nimport { useKeyboardHandler } from '../../hooks';\n\nexport const useKeyboardAnimation = () => {\n const heightWhenOpened = useSharedValue(0);\n const height = useSharedValue(0);\n const progress = useSharedValue(0);\n\n useKeyboardHandler(\n {\n onStart: (e) => {\n 'worklet';\n\n if (e.height > 0) {\n heightWhenOpened.value = e.height;\n }\n },\n onMove: (e) => {\n 'worklet';\n\n progress.value = e.progress;\n height.value = e.height;\n },\n },\n []\n );\n\n return { height, progress, heightWhenOpened };\n};\n"],"mappings":";;;;;;AAAA;AACA;AAEO,MAAMA,oBAAoB,GAAG,MAAM;EACxC,MAAMC,gBAAgB,GAAG,IAAAC,qCAAc,EAAC,CAAC,CAAC;EAC1C,MAAMC,MAAM,GAAG,IAAAD,qCAAc,EAAC,CAAC,CAAC;EAChC,MAAME,QAAQ,GAAG,IAAAF,qCAAc,EAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"names":["useKeyboardAnimation","heightWhenOpened","useSharedValue","height","progress","isClosed","useKeyboardHandler","onStart","e","value","onMove","onEnd"],"sources":["hooks.ts"],"sourcesContent":["import { useSharedValue } from 'react-native-reanimated';\nimport { useKeyboardHandler } from '../../hooks';\n\nexport const useKeyboardAnimation = () => {\n const heightWhenOpened = useSharedValue(0);\n const height = useSharedValue(0);\n const progress = useSharedValue(0);\n const isClosed = useSharedValue(true);\n\n useKeyboardHandler(\n {\n onStart: (e) => {\n 'worklet';\n\n if (e.height > 0) {\n isClosed.value = false;\n heightWhenOpened.value = e.height;\n }\n },\n onMove: (e) => {\n 'worklet';\n\n progress.value = e.progress;\n height.value = e.height;\n },\n onEnd: (e) => {\n 'worklet';\n\n isClosed.value = e.height === 0;\n },\n },\n []\n );\n\n return { height, progress, heightWhenOpened, isClosed };\n};\n"],"mappings":";;;;;;AAAA;AACA;AAEO,MAAMA,oBAAoB,GAAG,MAAM;EACxC,MAAMC,gBAAgB,GAAG,IAAAC,qCAAc,EAAC,CAAC,CAAC;EAC1C,MAAMC,MAAM,GAAG,IAAAD,qCAAc,EAAC,CAAC,CAAC;EAChC,MAAME,QAAQ,GAAG,IAAAF,qCAAc,EAAC,CAAC,CAAC;EAClC,MAAMG,QAAQ,GAAG,IAAAH,qCAAc,EAAC,IAAI,CAAC;EAErC,IAAAI,yBAAkB,EAChB;IACEC,OAAO,EAAGC,CAAC,IAAK;MACd,SAAS;;MAET,IAAIA,CAAC,CAACL,MAAM,GAAG,CAAC,EAAE;QAChBE,QAAQ,CAACI,KAAK,GAAG,KAAK;QACtBR,gBAAgB,CAACQ,KAAK,GAAGD,CAAC,CAACL,MAAM;MACnC;IACF,CAAC;IACDO,MAAM,EAAGF,CAAC,IAAK;MACb,SAAS;;MAETJ,QAAQ,CAACK,KAAK,GAAGD,CAAC,CAACJ,QAAQ;MAC3BD,MAAM,CAACM,KAAK,GAAGD,CAAC,CAACL,MAAM;IACzB,CAAC;IACDQ,KAAK,EAAGH,CAAC,IAAK;MACZ,SAAS;;MAETH,QAAQ,CAACI,KAAK,GAAGD,CAAC,CAACL,MAAM,KAAK,CAAC;IACjC;EACF,CAAC,EACD,EAAE,CACH;EAED,OAAO;IAAEA,MAAM;IAAEC,QAAQ;IAAEH,gBAAgB;IAAEI;EAAS,CAAC;AACzD,CAAC;AAAC"}
|
|
@@ -43,10 +43,13 @@ const KeyboardAvoidingView = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) =>
|
|
|
43
43
|
const keyboardY = screenHeight - keyboard.heightWhenOpened.value - keyboardVerticalOffset;
|
|
44
44
|
return Math.max(frame.value.y + frame.value.height - keyboardY, 0);
|
|
45
45
|
}, [screenHeight, keyboardVerticalOffset]);
|
|
46
|
-
const
|
|
47
|
-
if (
|
|
48
|
-
initialFrame.value =
|
|
46
|
+
const onLayoutWorklet = (0, _reactNativeReanimated.useWorkletCallback)(layout => {
|
|
47
|
+
if (keyboard.isClosed.value) {
|
|
48
|
+
initialFrame.value = layout;
|
|
49
49
|
}
|
|
50
|
+
});
|
|
51
|
+
const onLayout = (0, _react.useCallback)(e => {
|
|
52
|
+
(0, _reactNativeReanimated.runOnUI)(onLayoutWorklet)(e.nativeEvent.layout);
|
|
50
53
|
onLayoutProps === null || onLayoutProps === void 0 ? void 0 : onLayoutProps(e);
|
|
51
54
|
}, [onLayoutProps]);
|
|
52
55
|
const animatedStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => {
|
|
@@ -54,7 +57,7 @@ const KeyboardAvoidingView = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) =>
|
|
|
54
57
|
const bottomHeight = enabled ? bottom : 0;
|
|
55
58
|
switch (behavior) {
|
|
56
59
|
case 'height':
|
|
57
|
-
if (
|
|
60
|
+
if (!keyboard.isClosed.value) {
|
|
58
61
|
return {
|
|
59
62
|
height: frame.value.height - bottomHeight,
|
|
60
63
|
flex: 0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["defaultLayout","x","y","width","height","KeyboardAvoidingView","forwardRef","ref","behavior","children","contentContainerStyle","enabled","keyboardVerticalOffset","style","onLayout","onLayoutProps","props","initialFrame","useSharedValue","frame","useDerivedValue","value","keyboard","useKeyboardAnimation","screenHeight","useWindowDimensions","relativeKeyboardHeight","useWorkletCallback","keyboardY","heightWhenOpened","Math","max","useCallback","e","
|
|
1
|
+
{"version":3,"names":["defaultLayout","x","y","width","height","KeyboardAvoidingView","forwardRef","ref","behavior","children","contentContainerStyle","enabled","keyboardVerticalOffset","style","onLayout","onLayoutProps","props","initialFrame","useSharedValue","frame","useDerivedValue","value","keyboard","useKeyboardAnimation","screenHeight","useWindowDimensions","relativeKeyboardHeight","useWorkletCallback","keyboardY","heightWhenOpened","Math","max","onLayoutWorklet","layout","isClosed","useCallback","e","runOnUI","nativeEvent","animatedStyle","useAnimatedStyle","bottom","interpolate","progress","bottomHeight","flex","paddingBottom","isPositionBehavior","containerStyle","combinedStyles","useMemo"],"sources":["index.tsx"],"sourcesContent":["import React, { forwardRef, useCallback, useMemo } from 'react';\nimport {\n LayoutRectangle,\n useWindowDimensions,\n View,\n ViewProps,\n} from 'react-native';\nimport Reanimated, {\n useAnimatedStyle,\n useWorkletCallback,\n useSharedValue,\n useDerivedValue,\n interpolate,\n runOnUI,\n} from 'react-native-reanimated';\nimport { useKeyboardAnimation } from './hooks';\n\ntype Props = {\n /**\n * Specify how to react to the presence of the keyboard.\n */\n behavior?: 'height' | 'position' | 'padding';\n\n /**\n * Style of the content container when `behavior` is 'position'.\n */\n contentContainerStyle?: ViewProps['style'];\n\n /**\n * Controls whether this `KeyboardAvoidingView` instance should take effect.\n * This is useful when more than one is on the screen. Defaults to true.\n */\n enabled?: boolean;\n\n /**\n * Distance between the top of the user screen and the React Native view. This\n * may be non-zero in some cases. Defaults to 0.\n */\n keyboardVerticalOffset?: number;\n} & ViewProps;\n\nconst defaultLayout: LayoutRectangle = {\n x: 0,\n y: 0,\n width: 0,\n height: 0,\n};\n\n/**\n * View that moves out of the way when the keyboard appears by automatically\n * adjusting its height, position, or bottom padding.\n */\nconst KeyboardAvoidingView = forwardRef<View, React.PropsWithChildren<Props>>(\n (\n {\n behavior,\n children,\n contentContainerStyle,\n enabled = true,\n keyboardVerticalOffset = 0,\n style,\n onLayout: onLayoutProps,\n ...props\n },\n ref\n ) => {\n const initialFrame = useSharedValue<LayoutRectangle | null>(null);\n const frame = useDerivedValue(() => initialFrame.value || defaultLayout);\n\n const keyboard = useKeyboardAnimation();\n const { height: screenHeight } = useWindowDimensions();\n\n const relativeKeyboardHeight = useWorkletCallback(() => {\n const keyboardY =\n screenHeight - keyboard.heightWhenOpened.value - keyboardVerticalOffset;\n\n return Math.max(frame.value.y + frame.value.height - keyboardY, 0);\n }, [screenHeight, keyboardVerticalOffset]);\n\n const onLayoutWorklet = useWorkletCallback((layout: LayoutRectangle) => {\n if (keyboard.isClosed.value) {\n initialFrame.value = layout;\n }\n });\n const onLayout = useCallback<NonNullable<ViewProps['onLayout']>>(\n (e) => {\n runOnUI(onLayoutWorklet)(e.nativeEvent.layout);\n onLayoutProps?.(e);\n },\n [onLayoutProps]\n );\n\n const animatedStyle = useAnimatedStyle(() => {\n const bottom = interpolate(\n keyboard.progress.value,\n [0, 1],\n [0, relativeKeyboardHeight()]\n );\n const bottomHeight = enabled ? bottom : 0;\n\n switch (behavior) {\n case 'height':\n if (!keyboard.isClosed.value) {\n return {\n height: frame.value.height - bottomHeight,\n flex: 0,\n };\n }\n\n return {};\n\n case 'position':\n return { bottom: bottomHeight };\n\n case 'padding':\n return { paddingBottom: bottomHeight };\n\n default:\n return {};\n }\n }, [behavior, enabled, relativeKeyboardHeight]);\n const isPositionBehavior = behavior === 'position';\n const containerStyle = isPositionBehavior ? contentContainerStyle : style;\n const combinedStyles = useMemo(\n () => [containerStyle, animatedStyle],\n [containerStyle, animatedStyle]\n );\n\n if (isPositionBehavior) {\n return (\n <View ref={ref} style={style} onLayout={onLayout} {...props}>\n <Reanimated.View style={combinedStyles}>{children}</Reanimated.View>\n </View>\n );\n }\n\n return (\n <Reanimated.View\n // @ts-expect-error because `ref` from reanimated is not compatible with react-native\n ref={ref}\n onLayout={onLayout}\n style={combinedStyles}\n {...props}\n >\n {children}\n </Reanimated.View>\n );\n }\n);\n\nexport default KeyboardAvoidingView;\n"],"mappings":"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"}
|
package/lib/commonjs/context.js
CHANGED
|
@@ -14,6 +14,7 @@ const DEFAULT_SHARED_VALUE = {
|
|
|
14
14
|
modify: NOOP
|
|
15
15
|
};
|
|
16
16
|
const defaultContext = {
|
|
17
|
+
enabled: true,
|
|
17
18
|
animated: {
|
|
18
19
|
progress: new _reactNative.Animated.Value(0),
|
|
19
20
|
height: new _reactNative.Animated.Value(0)
|
|
@@ -22,7 +23,8 @@ const defaultContext = {
|
|
|
22
23
|
progress: DEFAULT_SHARED_VALUE,
|
|
23
24
|
height: DEFAULT_SHARED_VALUE
|
|
24
25
|
},
|
|
25
|
-
setHandlers:
|
|
26
|
+
setHandlers: NOOP,
|
|
27
|
+
setEnabled: NOOP
|
|
26
28
|
};
|
|
27
29
|
const KeyboardContext = /*#__PURE__*/(0, _react.createContext)(defaultContext);
|
|
28
30
|
exports.KeyboardContext = KeyboardContext;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NOOP","DEFAULT_SHARED_VALUE","value","addListener","removeListener","modify","defaultContext","animated","progress","Animated","Value","height","reanimated","setHandlers","KeyboardContext","createContext","useKeyboardContext","context","useContext","__DEV__","console","warn"],"sources":["context.ts"],"sourcesContent":["import { createContext, useContext } from 'react';\nimport { Animated } from 'react-native';\n\nimport type { SharedValue } from 'react-native-reanimated';\nimport type { KeyboardHandlers } from './types';\n\nexport type AnimatedContext = {\n progress: Animated.Value;\n height: Animated.AnimatedMultiplication<number>;\n};\nexport type ReanimatedContext = {\n progress: SharedValue<number>;\n height: SharedValue<number>;\n};\nexport type KeyboardAnimationContext = {\n animated: AnimatedContext;\n reanimated: ReanimatedContext;\n setHandlers: (handlers: KeyboardHandlers) => void;\n};\nconst NOOP = () => {};\nconst DEFAULT_SHARED_VALUE: SharedValue<number> = {\n value: 0,\n addListener: NOOP,\n removeListener: NOOP,\n modify: NOOP,\n};\nconst defaultContext: KeyboardAnimationContext = {\n animated: {\n progress: new Animated.Value(0),\n height: new Animated.Value(0),\n },\n reanimated: {\n progress: DEFAULT_SHARED_VALUE,\n height: DEFAULT_SHARED_VALUE,\n },\n setHandlers:
|
|
1
|
+
{"version":3,"names":["NOOP","DEFAULT_SHARED_VALUE","value","addListener","removeListener","modify","defaultContext","enabled","animated","progress","Animated","Value","height","reanimated","setHandlers","setEnabled","KeyboardContext","createContext","useKeyboardContext","context","useContext","__DEV__","console","warn"],"sources":["context.ts"],"sourcesContent":["import React, { createContext, useContext } from 'react';\nimport { Animated } from 'react-native';\n\nimport type { SharedValue } from 'react-native-reanimated';\nimport type { KeyboardHandlers } from './types';\n\nexport type AnimatedContext = {\n progress: Animated.Value;\n height: Animated.AnimatedMultiplication<number>;\n};\nexport type ReanimatedContext = {\n progress: SharedValue<number>;\n height: SharedValue<number>;\n};\nexport type KeyboardAnimationContext = {\n enabled: boolean;\n animated: AnimatedContext;\n reanimated: ReanimatedContext;\n setHandlers: (handlers: KeyboardHandlers) => void;\n setEnabled: React.Dispatch<React.SetStateAction<boolean>>;\n};\nconst NOOP = () => {};\nconst DEFAULT_SHARED_VALUE: SharedValue<number> = {\n value: 0,\n addListener: NOOP,\n removeListener: NOOP,\n modify: NOOP,\n};\nconst defaultContext: KeyboardAnimationContext = {\n enabled: true,\n animated: {\n progress: new Animated.Value(0),\n height: new Animated.Value(0),\n },\n reanimated: {\n progress: DEFAULT_SHARED_VALUE,\n height: DEFAULT_SHARED_VALUE,\n },\n setHandlers: NOOP,\n setEnabled: NOOP,\n};\nexport const KeyboardContext = createContext(defaultContext);\nexport const useKeyboardContext = () => {\n const context = useContext(KeyboardContext);\n\n if (__DEV__ && context === defaultContext) {\n console.warn(\n \"Couldn't find real values for `KeyboardContext`. Please make sure you're inside of `KeyboardProvider` - otherwise functionality of `react-native-keyboard-controller` will not work.\"\n );\n }\n\n return context;\n};\n"],"mappings":";;;;;;AAAA;AACA;AAoBA,MAAMA,IAAI,GAAG,MAAM,CAAC,CAAC;AACrB,MAAMC,oBAAyC,GAAG;EAChDC,KAAK,EAAE,CAAC;EACRC,WAAW,EAAEH,IAAI;EACjBI,cAAc,EAAEJ,IAAI;EACpBK,MAAM,EAAEL;AACV,CAAC;AACD,MAAMM,cAAwC,GAAG;EAC/CC,OAAO,EAAE,IAAI;EACbC,QAAQ,EAAE;IACRC,QAAQ,EAAE,IAAIC,qBAAQ,CAACC,KAAK,CAAC,CAAC,CAAC;IAC/BC,MAAM,EAAE,IAAIF,qBAAQ,CAACC,KAAK,CAAC,CAAC;EAC9B,CAAC;EACDE,UAAU,EAAE;IACVJ,QAAQ,EAAER,oBAAoB;IAC9BW,MAAM,EAAEX;EACV,CAAC;EACDa,WAAW,EAAEd,IAAI;EACjBe,UAAU,EAAEf;AACd,CAAC;AACM,MAAMgB,eAAe,gBAAG,IAAAC,oBAAa,EAACX,cAAc,CAAC;AAAC;AACtD,MAAMY,kBAAkB,GAAG,MAAM;EACtC,MAAMC,OAAO,GAAG,IAAAC,iBAAU,EAACJ,eAAe,CAAC;EAE3C,IAAIK,OAAO,IAAIF,OAAO,KAAKb,cAAc,EAAE;IACzCgB,OAAO,CAACC,IAAI,CACV,sLAAsL,CACvL;EACH;EAEA,OAAOJ,OAAO;AAChB,CAAC;AAAC"}
|
package/lib/commonjs/hooks.js
CHANGED
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.useGenericKeyboardHandler = useGenericKeyboardHandler;
|
|
7
7
|
exports.useKeyboardAnimation = void 0;
|
|
8
|
+
exports.useKeyboardController = useKeyboardController;
|
|
8
9
|
exports.useKeyboardHandler = useKeyboardHandler;
|
|
9
10
|
exports.useResizeMode = exports.useReanimatedKeyboardAnimation = void 0;
|
|
10
11
|
var _react = require("react");
|
|
@@ -49,4 +50,11 @@ function useKeyboardHandler(handler, deps) {
|
|
|
49
50
|
useResizeMode();
|
|
50
51
|
useGenericKeyboardHandler(handler, deps);
|
|
51
52
|
}
|
|
53
|
+
function useKeyboardController() {
|
|
54
|
+
const context = (0, _context.useKeyboardContext)();
|
|
55
|
+
return {
|
|
56
|
+
setEnabled: context.setEnabled,
|
|
57
|
+
enabled: context.enabled
|
|
58
|
+
};
|
|
59
|
+
}
|
|
52
60
|
//# sourceMappingURL=hooks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useResizeMode","useEffect","KeyboardController","setInputMode","AndroidSoftInputModes","SOFT_INPUT_ADJUST_RESIZE","setDefaultMode","useKeyboardAnimation","context","useKeyboardContext","animated","useReanimatedKeyboardAnimation","reanimated","useGenericKeyboardHandler","handler","deps","key","uuid","setHandlers","undefined","useKeyboardHandler"],"sources":["hooks.ts"],"sourcesContent":["import { DependencyList, useEffect } from 'react';\n\nimport {\n AnimatedContext,\n ReanimatedContext,\n useKeyboardContext,\n} from './context';\nimport { KeyboardController } from './bindings';\nimport { AndroidSoftInputModes } from './constants';\nimport { uuid } from './utils';\n\nimport type { KeyboardHandler } from './types';\n\nexport const useResizeMode = () => {\n useEffect(() => {\n KeyboardController.setInputMode(\n AndroidSoftInputModes.SOFT_INPUT_ADJUST_RESIZE\n );\n\n return () => KeyboardController.setDefaultMode();\n }, []);\n};\n\nexport const useKeyboardAnimation = (): AnimatedContext => {\n useResizeMode();\n const context = useKeyboardContext();\n\n return context.animated;\n};\n\nexport const useReanimatedKeyboardAnimation = (): ReanimatedContext => {\n useResizeMode();\n const context = useKeyboardContext();\n\n return context.reanimated;\n};\n\nexport function useGenericKeyboardHandler(\n handler: KeyboardHandler,\n deps?: DependencyList\n) {\n const context = useKeyboardContext();\n\n useEffect(() => {\n const key = uuid();\n\n context.setHandlers({ [key]: handler });\n\n return () => {\n context.setHandlers({ [key]: undefined });\n };\n }, deps);\n}\n\nexport function useKeyboardHandler(\n handler: KeyboardHandler,\n deps?: DependencyList\n) {\n useResizeMode();\n useGenericKeyboardHandler(handler, deps);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["useResizeMode","useEffect","KeyboardController","setInputMode","AndroidSoftInputModes","SOFT_INPUT_ADJUST_RESIZE","setDefaultMode","useKeyboardAnimation","context","useKeyboardContext","animated","useReanimatedKeyboardAnimation","reanimated","useGenericKeyboardHandler","handler","deps","key","uuid","setHandlers","undefined","useKeyboardHandler","useKeyboardController","setEnabled","enabled"],"sources":["hooks.ts"],"sourcesContent":["import { DependencyList, useEffect } from 'react';\n\nimport {\n AnimatedContext,\n ReanimatedContext,\n useKeyboardContext,\n} from './context';\nimport { KeyboardController } from './bindings';\nimport { AndroidSoftInputModes } from './constants';\nimport { uuid } from './utils';\n\nimport type { KeyboardHandler } from './types';\n\nexport const useResizeMode = () => {\n useEffect(() => {\n KeyboardController.setInputMode(\n AndroidSoftInputModes.SOFT_INPUT_ADJUST_RESIZE\n );\n\n return () => KeyboardController.setDefaultMode();\n }, []);\n};\n\nexport const useKeyboardAnimation = (): AnimatedContext => {\n useResizeMode();\n const context = useKeyboardContext();\n\n return context.animated;\n};\n\nexport const useReanimatedKeyboardAnimation = (): ReanimatedContext => {\n useResizeMode();\n const context = useKeyboardContext();\n\n return context.reanimated;\n};\n\nexport function useGenericKeyboardHandler(\n handler: KeyboardHandler,\n deps?: DependencyList\n) {\n const context = useKeyboardContext();\n\n useEffect(() => {\n const key = uuid();\n\n context.setHandlers({ [key]: handler });\n\n return () => {\n context.setHandlers({ [key]: undefined });\n };\n }, deps);\n}\n\nexport function useKeyboardHandler(\n handler: KeyboardHandler,\n deps?: DependencyList\n) {\n useResizeMode();\n useGenericKeyboardHandler(handler, deps);\n}\n\nexport function useKeyboardController() {\n const context = useKeyboardContext();\n\n return { setEnabled: context.setEnabled, enabled: context.enabled };\n}\n"],"mappings":";;;;;;;;;;AAAA;AAEA;AAKA;AACA;AACA;AAIO,MAAMA,aAAa,GAAG,MAAM;EACjC,IAAAC,gBAAS,EAAC,MAAM;IACdC,4BAAkB,CAACC,YAAY,CAC7BC,gCAAqB,CAACC,wBAAwB,CAC/C;IAED,OAAO,MAAMH,4BAAkB,CAACI,cAAc,EAAE;EAClD,CAAC,EAAE,EAAE,CAAC;AACR,CAAC;AAAC;AAEK,MAAMC,oBAAoB,GAAG,MAAuB;EACzDP,aAAa,EAAE;EACf,MAAMQ,OAAO,GAAG,IAAAC,2BAAkB,GAAE;EAEpC,OAAOD,OAAO,CAACE,QAAQ;AACzB,CAAC;AAAC;AAEK,MAAMC,8BAA8B,GAAG,MAAyB;EACrEX,aAAa,EAAE;EACf,MAAMQ,OAAO,GAAG,IAAAC,2BAAkB,GAAE;EAEpC,OAAOD,OAAO,CAACI,UAAU;AAC3B,CAAC;AAAC;AAEK,SAASC,yBAAyB,CACvCC,OAAwB,EACxBC,IAAqB,EACrB;EACA,MAAMP,OAAO,GAAG,IAAAC,2BAAkB,GAAE;EAEpC,IAAAR,gBAAS,EAAC,MAAM;IACd,MAAMe,GAAG,GAAG,IAAAC,WAAI,GAAE;IAElBT,OAAO,CAACU,WAAW,CAAC;MAAE,CAACF,GAAG,GAAGF;IAAQ,CAAC,CAAC;IAEvC,OAAO,MAAM;MACXN,OAAO,CAACU,WAAW,CAAC;QAAE,CAACF,GAAG,GAAGG;MAAU,CAAC,CAAC;IAC3C,CAAC;EACH,CAAC,EAAEJ,IAAI,CAAC;AACV;AAEO,SAASK,kBAAkB,CAChCN,OAAwB,EACxBC,IAAqB,EACrB;EACAf,aAAa,EAAE;EACfa,yBAAyB,CAACC,OAAO,EAAEC,IAAI,CAAC;AAC1C;AAEO,SAASM,qBAAqB,GAAG;EACtC,MAAMb,OAAO,GAAG,IAAAC,2BAAkB,GAAE;EAEpC,OAAO;IAAEa,UAAU,EAAEd,OAAO,CAACc,UAAU;IAAEC,OAAO,EAAEf,OAAO,CAACe;EAAQ,CAAC;AACrE"}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -12,7 +12,6 @@ Object.defineProperty(exports, "KeyboardAvoidingView", {
|
|
|
12
12
|
return _components.KeyboardAvoidingView;
|
|
13
13
|
}
|
|
14
14
|
});
|
|
15
|
-
require("./monkey-patch");
|
|
16
15
|
var _bindings = require("./bindings");
|
|
17
16
|
Object.keys(_bindings).forEach(function (key) {
|
|
18
17
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from './bindings';\nexport * from './animated';\nexport * from './replicas';\nexport * from './context';\nexport * from './hooks';\nexport * from './constants';\nexport * from './types';\n\nexport { KeyboardAvoidingView } from './components';\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AAEA"}
|