react-native-keyboard-controller 1.0.1 → 1.2.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/android/build.gradle +72 -3
- package/android/gradle.properties +1 -1
- package/android/src/fabric/java/com/reactnativekeyboardcontroller/KeyboardControllerComponentsRegistry.kt +31 -0
- package/android/src/fabric/java/com/reactnativekeyboardcontroller/KeyboardControllerModule.kt +25 -0
- package/android/src/fabric/java/com/reactnativekeyboardcontroller/KeyboardControllerViewManager.kt +32 -0
- package/android/src/fabric/java/com/reactnativekeyboardcontroller/StatusBarManagerCompatModule.kt +25 -0
- package/android/src/main/java/com/reactnativekeyboardcontroller/KeyboardAnimationCallback.kt +188 -0
- package/android/src/main/java/com/reactnativekeyboardcontroller/{KeyboardControllerModule.kt → KeyboardControllerModuleImpl.kt} +5 -17
- package/android/src/main/java/com/reactnativekeyboardcontroller/KeyboardControllerPackage.kt +5 -0
- package/android/src/main/java/com/reactnativekeyboardcontroller/KeyboardControllerViewManagerImpl.kt +71 -0
- package/android/src/main/java/com/reactnativekeyboardcontroller/{StatusBarManagerCompatModule.kt → StatusBarManagerCompatImpl.kt} +10 -14
- package/android/src/main/jni/Android.mk +42 -0
- package/android/src/main/jni/KeyboardControllerComponentsRegistry.cpp +71 -0
- package/android/src/main/jni/KeyboardControllerComponentsRegistry.h +35 -0
- package/android/src/main/jni/OnLoad.cpp +9 -0
- package/android/src/paper/java/com/reactnativekeyboardcontroller/KeyboardControllerModule.kt +31 -0
- package/android/src/paper/java/com/reactnativekeyboardcontroller/KeyboardControllerViewManager.kt +26 -0
- package/android/src/paper/java/com/reactnativekeyboardcontroller/StatusBarManagerCompatModule.kt +34 -0
- package/ios/.clang-format +90 -0
- package/ios/KeyboardController.xcodeproj/project.pbxproj +22 -14
- package/ios/KeyboardControllerModule-Header.h +6 -2
- package/ios/KeyboardControllerModule.mm +105 -0
- package/ios/KeyboardControllerView.h +23 -0
- package/ios/KeyboardControllerView.mm +81 -0
- package/ios/{KeyboardControllerViewManager.m → KeyboardControllerViewManager.mm} +1 -1
- package/ios/KeyboardControllerViewManager.swift +13 -64
- package/ios/KeyboardMoveEvent.h +18 -0
- package/ios/KeyboardMoveEvent.m +74 -0
- package/ios/KeyboardMovementObserver.swift +90 -0
- package/lib/commonjs/KeyboardControllerViewNativeComponent.js +16 -0
- package/lib/commonjs/KeyboardControllerViewNativeComponent.js.map +1 -0
- package/lib/commonjs/NativeKeyboardController.js +13 -0
- package/lib/commonjs/NativeKeyboardController.js.map +1 -0
- package/lib/commonjs/NativeStatusBarManagerCompat.js +13 -0
- package/lib/commonjs/NativeStatusBarManagerCompat.js.map +1 -0
- package/lib/commonjs/animated.js.map +1 -1
- package/lib/commonjs/architecture.js +13 -0
- package/lib/commonjs/architecture.js.map +1 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/monkey-patch.js +3 -1
- package/lib/commonjs/monkey-patch.js.map +1 -1
- package/lib/commonjs/native.js +4 -2
- package/lib/commonjs/native.js.map +1 -1
- package/lib/commonjs/replicas.js.map +1 -1
- package/lib/module/KeyboardControllerViewNativeComponent.js +4 -0
- package/lib/module/KeyboardControllerViewNativeComponent.js.map +1 -0
- package/lib/module/NativeKeyboardController.js +3 -0
- package/lib/module/NativeKeyboardController.js.map +1 -0
- package/lib/module/NativeStatusBarManagerCompat.js +3 -0
- package/lib/module/NativeStatusBarManagerCompat.js.map +1 -0
- package/lib/module/animated.js.map +1 -1
- package/lib/module/architecture.js +5 -0
- package/lib/module/architecture.js.map +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/monkey-patch.js +2 -1
- package/lib/module/monkey-patch.js.map +1 -1
- package/lib/module/native.js +3 -2
- package/lib/module/native.js.map +1 -1
- package/lib/module/replicas.js.map +1 -1
- package/lib/typescript/KeyboardControllerViewNativeComponent.d.ts +13 -0
- package/lib/typescript/NativeKeyboardController.d.ts +10 -0
- package/lib/typescript/NativeStatusBarManagerCompat.d.ts +10 -0
- package/lib/typescript/architecture.d.ts +2 -0
- package/lib/typescript/native.d.ts +1 -1
- package/lib/typescript/replicas.d.ts +3 -5
- package/package.json +23 -6
- package/react-native-keyboard-controller.podspec +19 -0
- package/src/KeyboardControllerViewNativeComponent.ts +23 -0
- package/src/NativeKeyboardController.ts +16 -0
- package/src/NativeStatusBarManagerCompat.ts +13 -0
- package/src/architecture.ts +4 -0
- package/src/monkey-patch.tsx +5 -1
- package/src/native.ts +12 -7
- package/android/src/main/java/com/reactnativekeyboardcontroller/KeyboardControllerViewManager.kt +0 -77
- package/android/src/main/java/com/reactnativekeyboardcontroller/TranslateDeferringInsetsAnimationCallback.kt +0 -158
- package/ios/KeyboardControllerModule.m +0 -21
- package/ios/KeyboardControllerModule.swift +0 -53
- package/ios/KeyboardMoveEvent.swift +0 -41
|
@@ -10,6 +10,7 @@ class KeyboardControllerViewManager: RCTViewManager {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
class KeyboardControllerView: UIView {
|
|
13
|
+
private var keyboardObserver: KeyboardMovementObserver?
|
|
13
14
|
private var eventDispatcher: RCTEventDispatcherProtocol
|
|
14
15
|
@objc var onKeyboardMove: RCTDirectEventBlock?
|
|
15
16
|
|
|
@@ -26,81 +27,29 @@ class KeyboardControllerView: UIView {
|
|
|
26
27
|
override func willMove(toWindow newWindow: UIWindow?) {
|
|
27
28
|
if newWindow == nil {
|
|
28
29
|
// Will be removed from a window
|
|
29
|
-
|
|
30
|
-
NotificationCenter.default.removeObserver(self)
|
|
30
|
+
keyboardObserver?.unmount()
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
override func didMoveToWindow() {
|
|
35
35
|
if window != nil {
|
|
36
36
|
// Added to a window
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
selector: #selector(keyboardWillDisappear),
|
|
40
|
-
name: UIResponder.keyboardWillHideNotification,
|
|
41
|
-
object: nil
|
|
42
|
-
)
|
|
43
|
-
NotificationCenter.default.addObserver(
|
|
44
|
-
self,
|
|
45
|
-
selector: #selector(keyboardWillAppear),
|
|
46
|
-
name: UIResponder.keyboardWillShowNotification,
|
|
47
|
-
object: nil
|
|
48
|
-
)
|
|
49
|
-
NotificationCenter.default.addObserver(
|
|
50
|
-
self,
|
|
51
|
-
selector: #selector(keyboardDidAppear),
|
|
52
|
-
name: UIResponder.keyboardDidShowNotification,
|
|
53
|
-
object: nil
|
|
54
|
-
)
|
|
55
|
-
NotificationCenter.default.addObserver(
|
|
56
|
-
self,
|
|
57
|
-
selector: #selector(keyboardDidDisappear),
|
|
58
|
-
name: UIResponder.keyboardDidHideNotification,
|
|
59
|
-
object: nil
|
|
60
|
-
)
|
|
37
|
+
keyboardObserver = KeyboardMovementObserver(handler: onEvent, onNotify: onNotify)
|
|
38
|
+
keyboardObserver?.mount()
|
|
61
39
|
}
|
|
62
40
|
}
|
|
63
41
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
viewTag: reactTag,
|
|
71
|
-
height: -keyboardHeight as NSNumber,
|
|
72
|
-
progress: 1
|
|
73
|
-
)
|
|
42
|
+
func onEvent(height: NSNumber, progress: NSNumber) {
|
|
43
|
+
eventDispatcher.send(
|
|
44
|
+
KeyboardMoveEvent(
|
|
45
|
+
reactTag: reactTag,
|
|
46
|
+
height: height,
|
|
47
|
+
progress: progress
|
|
74
48
|
)
|
|
75
|
-
|
|
76
|
-
var data = [AnyHashable: Any]()
|
|
77
|
-
data["height"] = keyboardHeight
|
|
78
|
-
KeyboardController.shared?.sendEvent(withName: "KeyboardController::keyboardWillShow", body: data)
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
@objc func keyboardWillDisappear() {
|
|
83
|
-
eventDispatcher.send(KeyboardMoveEvent(viewTag: reactTag, height: 0, progress: 0))
|
|
84
|
-
|
|
85
|
-
var data = [AnyHashable: Any]()
|
|
86
|
-
data["height"] = 0
|
|
87
|
-
KeyboardController.shared?.sendEvent(withName: "KeyboardController::keyboardWillHide", body: data)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
@objc func keyboardDidAppear(_ notification: Notification) {
|
|
91
|
-
if let keyboardFrame: NSValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue {
|
|
92
|
-
let keyboardHeight = keyboardFrame.cgRectValue.size.height
|
|
93
|
-
|
|
94
|
-
var data = [AnyHashable: Any]()
|
|
95
|
-
data["height"] = keyboardHeight
|
|
96
|
-
|
|
97
|
-
KeyboardController.shared?.sendEvent(withName: "KeyboardController::keyboardDidShow", body: data)
|
|
98
|
-
}
|
|
49
|
+
)
|
|
99
50
|
}
|
|
100
51
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
data["height"] = 0
|
|
104
|
-
KeyboardController.shared?.sendEvent(withName: "KeyboardController::keyboardDidHide", body: data)
|
|
52
|
+
func onNotify(event: String, data: Any) {
|
|
53
|
+
KeyboardController.shared()?.sendEvent(event, body: data)
|
|
105
54
|
}
|
|
106
55
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//
|
|
2
|
+
// KeyboardMoveEvent.h
|
|
3
|
+
// KeyboardController
|
|
4
|
+
//
|
|
5
|
+
// Created by Kiryl Ziusko on 6.08.22.
|
|
6
|
+
// Copyright © 2022 Facebook. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#import <Foundation/Foundation.h>
|
|
10
|
+
#import <React/RCTEventDispatcherProtocol.h>
|
|
11
|
+
|
|
12
|
+
@interface KeyboardMoveEvent : NSObject <RCTEvent>
|
|
13
|
+
|
|
14
|
+
- (instancetype)initWithReactTag:(NSNumber *)reactTag
|
|
15
|
+
height:(NSNumber *)height
|
|
16
|
+
progress:(NSNumber *)progress;
|
|
17
|
+
|
|
18
|
+
@end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
//
|
|
2
|
+
// KeyboardMoveEvent.m
|
|
3
|
+
// KeyboardController
|
|
4
|
+
//
|
|
5
|
+
// Created by Kiryl Ziusko on 6.08.22.
|
|
6
|
+
// Copyright © 2022 Facebook. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#import "KeyboardMoveEvent.h"
|
|
10
|
+
#import <React/RCTAssert.h>
|
|
11
|
+
|
|
12
|
+
@implementation KeyboardMoveEvent {
|
|
13
|
+
NSNumber *_progress;
|
|
14
|
+
NSNumber *_height;
|
|
15
|
+
uint16_t _coalescingKey;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@synthesize viewTag = _viewTag;
|
|
19
|
+
@synthesize eventName = _eventName;
|
|
20
|
+
|
|
21
|
+
- (instancetype)initWithReactTag:(NSNumber *)reactTag
|
|
22
|
+
height:(NSNumber *)height
|
|
23
|
+
progress:(NSNumber *)progress
|
|
24
|
+
{
|
|
25
|
+
RCTAssertParam(reactTag);
|
|
26
|
+
|
|
27
|
+
if ((self = [super init])) {
|
|
28
|
+
_eventName = @"onKeyboardMove";
|
|
29
|
+
_viewTag = reactTag;
|
|
30
|
+
_progress = progress;
|
|
31
|
+
_height = height;
|
|
32
|
+
_coalescingKey = 0;
|
|
33
|
+
}
|
|
34
|
+
return self;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
RCT_NOT_IMPLEMENTED(-(instancetype)init)
|
|
38
|
+
|
|
39
|
+
- (uint16_t)coalescingKey
|
|
40
|
+
{
|
|
41
|
+
return _coalescingKey;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
- (NSDictionary *)body
|
|
45
|
+
{
|
|
46
|
+
NSDictionary *body = @{
|
|
47
|
+
@"progress" : _progress,
|
|
48
|
+
@"height" : _height,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
return body;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
- (BOOL)canCoalesce
|
|
55
|
+
{
|
|
56
|
+
return NO;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
- (KeyboardMoveEvent *)coalesceWithEvent:(KeyboardMoveEvent *)newEvent
|
|
60
|
+
{
|
|
61
|
+
return newEvent;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
+ (NSString *)moduleDotMethod
|
|
65
|
+
{
|
|
66
|
+
return @"RCTEventEmitter.receiveEvent";
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
- (NSArray *)arguments
|
|
70
|
+
{
|
|
71
|
+
return @[ self.viewTag, RCTNormalizeInputEventName(self.eventName), [self body] ];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
@end
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
//
|
|
2
|
+
// KeyboardMovementObserver.swift
|
|
3
|
+
// KeyboardController
|
|
4
|
+
//
|
|
5
|
+
// Created by Kiryl Ziusko on 2.08.22.
|
|
6
|
+
// Copyright © 2022 Facebook. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
import Foundation
|
|
10
|
+
|
|
11
|
+
@objc(KeyboardMovementObserver)
|
|
12
|
+
public class KeyboardMovementObserver: NSObject {
|
|
13
|
+
var onEvent: (NSNumber, NSNumber) -> Void
|
|
14
|
+
var onNotify: (String, Any) -> Void
|
|
15
|
+
|
|
16
|
+
@objc public init(handler: @escaping (NSNumber, NSNumber) -> Void, onNotify: @escaping (String, Any) -> Void) {
|
|
17
|
+
onEvent = handler
|
|
18
|
+
self.onNotify = onNotify
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@objc public func mount() {
|
|
22
|
+
NotificationCenter.default.addObserver(
|
|
23
|
+
self,
|
|
24
|
+
selector: #selector(keyboardWillDisappear),
|
|
25
|
+
name: UIResponder.keyboardWillHideNotification,
|
|
26
|
+
object: nil
|
|
27
|
+
)
|
|
28
|
+
NotificationCenter.default.addObserver(
|
|
29
|
+
self,
|
|
30
|
+
selector: #selector(keyboardWillAppear),
|
|
31
|
+
name: UIResponder.keyboardWillShowNotification,
|
|
32
|
+
object: nil
|
|
33
|
+
)
|
|
34
|
+
NotificationCenter.default.addObserver(
|
|
35
|
+
self,
|
|
36
|
+
selector: #selector(keyboardDidAppear),
|
|
37
|
+
name: UIResponder.keyboardDidShowNotification,
|
|
38
|
+
object: nil
|
|
39
|
+
)
|
|
40
|
+
NotificationCenter.default.addObserver(
|
|
41
|
+
self,
|
|
42
|
+
selector: #selector(keyboardDidDisappear),
|
|
43
|
+
name: UIResponder.keyboardDidHideNotification,
|
|
44
|
+
object: nil
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@objc public func unmount() {
|
|
49
|
+
// swiftlint:disable notification_center_detachment
|
|
50
|
+
NotificationCenter.default.removeObserver(self)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@objc func keyboardWillAppear(_ notification: Notification) {
|
|
54
|
+
if let keyboardFrame: NSValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue {
|
|
55
|
+
let keyboardHeight = keyboardFrame.cgRectValue.size.height
|
|
56
|
+
|
|
57
|
+
var data = [AnyHashable: Any]()
|
|
58
|
+
data["height"] = keyboardHeight
|
|
59
|
+
|
|
60
|
+
onEvent(Float(-keyboardHeight) as NSNumber, 1)
|
|
61
|
+
onNotify("KeyboardController::keyboardWillShow", data)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@objc func keyboardWillDisappear() {
|
|
66
|
+
var data = [AnyHashable: Any]()
|
|
67
|
+
data["height"] = 0
|
|
68
|
+
|
|
69
|
+
onEvent(0, 0)
|
|
70
|
+
onNotify("KeyboardController::keyboardWillHide", data)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@objc func keyboardDidAppear(_ notification: Notification) {
|
|
74
|
+
if let keyboardFrame: NSValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue {
|
|
75
|
+
let keyboardHeight = keyboardFrame.cgRectValue.size.height
|
|
76
|
+
|
|
77
|
+
var data = [AnyHashable: Any]()
|
|
78
|
+
data["height"] = keyboardHeight
|
|
79
|
+
|
|
80
|
+
onNotify("KeyboardController::keyboardDidShow", data)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@objc func keyboardDidDisappear() {
|
|
85
|
+
var data = [AnyHashable: Any]()
|
|
86
|
+
data["height"] = 0
|
|
87
|
+
|
|
88
|
+
onNotify("KeyboardController::keyboardDidHide", data)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _codegenNativeComponent = _interopRequireDefault(require("react-native/Libraries/Utilities/codegenNativeComponent"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
// @ts-expect-error - no type definition
|
|
13
|
+
var _default = (0, _codegenNativeComponent.default)('KeyboardControllerView');
|
|
14
|
+
|
|
15
|
+
exports.default = _default;
|
|
16
|
+
//# sourceMappingURL=KeyboardControllerViewNativeComponent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["codegenNativeComponent"],"sources":["KeyboardControllerViewNativeComponent.ts"],"sourcesContent":["import type { HostComponent } from 'react-native';\n// @ts-expect-error - no type definition\nimport type { ViewProps } from 'react-native/Libraries/Components/View/ViewPropTypes';\nimport type {\n DirectEventHandler,\n Float,\n Int32,\n} from 'react-native/Libraries/Types/CodegenTypes';\nimport codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';\n\ntype KeyboardMoveEvent = Readonly<{\n height: Int32;\n progress: Float;\n}>;\n\nexport interface NativeProps extends ViewProps {\n statusBarTranslucent?: boolean;\n onKeyboardMove?: DirectEventHandler<KeyboardMoveEvent>;\n}\n\nexport default codegenNativeComponent<NativeProps>(\n 'KeyboardControllerView'\n) as HostComponent<NativeProps>;\n"],"mappings":";;;;;;;AAQA;;;;AAPA;eAmBe,IAAAA,+BAAA,EACb,wBADa,C"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
|
+
|
|
10
|
+
var _default = _reactNative.TurboModuleRegistry.get('KeyboardController');
|
|
11
|
+
|
|
12
|
+
exports.default = _default;
|
|
13
|
+
//# sourceMappingURL=NativeKeyboardController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["TurboModuleRegistry","get"],"sources":["NativeKeyboardController.ts"],"sourcesContent":["import type { TurboModule } from 'react-native';\nimport { TurboModuleRegistry } from 'react-native';\n\nexport interface Spec extends TurboModule {\n readonly getConstants: () => {};\n\n // methods\n setInputMode(mode: number): void;\n setDefaultMode(): void;\n\n // event emitter\n addListener: (eventName: string) => void;\n removeListeners: (count: number) => void;\n}\n\nexport default TurboModuleRegistry.get<Spec>('KeyboardController');\n"],"mappings":";;;;;;;AACA;;eAceA,gCAAA,CAAoBC,GAApB,CAA8B,oBAA9B,C"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
|
+
|
|
10
|
+
var _default = _reactNative.TurboModuleRegistry.get('StatusBarManagerCompat');
|
|
11
|
+
|
|
12
|
+
exports.default = _default;
|
|
13
|
+
//# sourceMappingURL=NativeStatusBarManagerCompat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["TurboModuleRegistry","get"],"sources":["NativeStatusBarManagerCompat.ts"],"sourcesContent":["import type { TurboModule } from 'react-native';\nimport { TurboModuleRegistry } from 'react-native';\n\nexport interface Spec extends TurboModule {\n readonly getConstants: () => {};\n\n setHidden(hidden: boolean): void;\n setColor(color: number, animated: boolean): void;\n setTranslucent(translucent: boolean): void;\n setStyle(style: string): void;\n}\n\nexport default TurboModuleRegistry.get<Spec>('StatusBarManagerCompat');\n"],"mappings":";;;;;;;AACA;;eAWeA,gCAAA,CAAoBC,GAApB,CAA8B,wBAA9B,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["KeyboardControllerViewAnimated","Reanimated","createAnimatedComponent","Animated","KeyboardControllerView","defaultContext","animated","progress","Value","height","reanimated","value","KeyboardContext","React","createContext","useKeyboardAnimation","useResizeMode","context","useContext","useReanimatedKeyboardAnimation","useAnimatedKeyboardHandler","handlers","dependencies","doDependenciesDiffer","useHandler","useEvent","event","onKeyboardMove","eventName","endsWith","styles","StyleSheet","create","container","flex","hidden","display","position","KeyboardProvider","children","statusBarTranslucent","useRef","current","progressSV","useSharedValue","heightSV","useMemo","style","transform","translateX","translateY","nativeEvent","useNativeDriver","handler"],"sources":["animated.tsx"],"sourcesContent":["import React, { useContext, useMemo, useRef } from 'react';\nimport { Animated, StyleSheet, ViewStyle } from 'react-native';\nimport Reanimated, {\n useEvent,\n useHandler,\n useSharedValue,\n} from 'react-native-reanimated';\nimport {\n EventWithName,\n KeyboardControllerProps,\n KeyboardControllerView,\n NativeEvent,\n useResizeMode,\n} from './native';\n\nconst KeyboardControllerViewAnimated = Reanimated.createAnimatedComponent(\n Animated.createAnimatedComponent(\n KeyboardControllerView\n ) as React.FC<KeyboardControllerProps>\n);\n\ntype AnimatedContext = {\n progress: Animated.Value;\n height: Animated.Value;\n};\ntype ReanimatedContext = {\n progress: Reanimated.SharedValue<number>;\n height: Reanimated.SharedValue<number>;\n};\ntype KeyboardAnimationContext = {\n animated: AnimatedContext;\n reanimated: ReanimatedContext;\n};\nconst defaultContext: KeyboardAnimationContext = {\n animated: {\n progress: new Animated.Value(0),\n height: new Animated.Value(0),\n },\n reanimated: {\n progress: { value: 0 },\n height: { value: 0 },\n },\n};\nexport const KeyboardContext = React.createContext(defaultContext);\n\nexport const useKeyboardAnimation = (): AnimatedContext => {\n useResizeMode();\n const context = useContext(KeyboardContext);\n\n return context.animated;\n};\n\nexport const useReanimatedKeyboardAnimation = (): ReanimatedContext => {\n useResizeMode();\n const context = useContext(KeyboardContext);\n\n return context.reanimated;\n};\n\nfunction useAnimatedKeyboardHandler<TContext extends Record<string, unknown>>(\n handlers: {\n onKeyboardMove?: (e: NativeEvent, context: TContext) => void;\n },\n dependencies?: ReadonlyArray<unknown>\n) {\n const { context, doDependenciesDiffer } = useHandler(handlers, dependencies);\n\n return useEvent(\n (event: EventWithName<NativeEvent>) => {\n 'worklet';\n const { onKeyboardMove } = handlers;\n\n if (onKeyboardMove && event.eventName.endsWith('onKeyboardMove')) {\n onKeyboardMove(event, context);\n }\n },\n ['onKeyboardMove'],\n doDependenciesDiffer\n );\n}\n\ntype Styles = {\n container: ViewStyle;\n hidden: ViewStyle;\n};\n\nexport const 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\nexport const KeyboardProvider = ({\n children,\n statusBarTranslucent,\n}: KeyboardProviderProps) => {\n const progress = useRef(new Animated.Value(0)).current;\n const height = useRef(new Animated.Value(0)).current;\n const progressSV = useSharedValue(0);\n const heightSV = useSharedValue(0);\n const context = useMemo(\n () => ({\n animated: { progress: progress, height: height },\n reanimated: { progress: progressSV, height: heightSV },\n }),\n []\n );\n const style = useMemo(\n () => [\n styles.hidden,\n { transform: [{ translateX: height }, { translateY: progress }] },\n ],\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\n const handler = useAnimatedKeyboardHandler(\n {\n onKeyboardMove: (event: NativeEvent) => {\n 'worklet';\n progressSV.value = event.progress;\n heightSV.value = event.height;\n },\n },\n []\n );\n\n return (\n <KeyboardContext.Provider value={context}>\n <KeyboardControllerViewAnimated\n onKeyboardMoveReanimated={handler}\n onKeyboardMove={onKeyboardMove}\n statusBarTranslucent={statusBarTranslucent}\n style={styles.container}\n >\n <>\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 {children}\n </>\n </KeyboardControllerViewAnimated>\n </KeyboardContext.Provider>\n );\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAKA;;;;;;AAQA,MAAMA,8BAA8B,GAAGC,8BAAA,CAAWC,uBAAX,CACrCC,qBAAA,CAASD,uBAAT,CACEE,8BADF,CADqC,CAAvC;;AAkBA,MAAMC,cAAwC,GAAG;EAC/CC,QAAQ,EAAE;IACRC,QAAQ,EAAE,IAAIJ,qBAAA,CAASK,KAAb,CAAmB,CAAnB,CADF;IAERC,MAAM,EAAE,IAAIN,qBAAA,CAASK,KAAb,CAAmB,CAAnB;EAFA,CADqC;EAK/CE,UAAU,EAAE;IACVH,QAAQ,EAAE;MAAEI,KAAK,EAAE;IAAT,CADA;IAEVF,MAAM,EAAE;MAAEE,KAAK,EAAE;IAAT;EAFE;AALmC,CA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C,OAD5B;IAEE,cAAc,EAAE1B,cAFlB;IAGE,oBAAoB,EAAEa,oBAHxB;IAIE,KAAK,EAAEV,MAAM,CAACG;EAJhB,gBAME,yEACE,6BAAC,qBAAD,CAAU,IAAV;IACE;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,KAAK,EAAEc;EATT,EADF,EAYGR,QAZH,CANF,CADF,CADF;AAyBD,CA3EM"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isTurboModuleEnabled = exports.isFabricEnabled = void 0;
|
|
7
|
+
// @ts-expect-error because `__turboModuleProxy` has any type (maybe think about own types declaration)
|
|
8
|
+
const isTurboModuleEnabled = global.__turboModuleProxy != null; // @ts-expect-error because `nativeFabricUIManager` has any type (maybe think about own types declaration)
|
|
9
|
+
|
|
10
|
+
exports.isTurboModuleEnabled = isTurboModuleEnabled;
|
|
11
|
+
const isFabricEnabled = global.nativeFabricUIManager != null;
|
|
12
|
+
exports.isFabricEnabled = isFabricEnabled;
|
|
13
|
+
//# sourceMappingURL=architecture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["isTurboModuleEnabled","global","__turboModuleProxy","isFabricEnabled","nativeFabricUIManager"],"sources":["architecture.ts"],"sourcesContent":["// @ts-expect-error because `__turboModuleProxy` has any type (maybe think about own types declaration)\nexport const isTurboModuleEnabled = global.__turboModuleProxy != null;\n// @ts-expect-error because `nativeFabricUIManager` has any type (maybe think about own types declaration)\nexport const isFabricEnabled = global.nativeFabricUIManager != null;\n"],"mappings":";;;;;;AAAA;AACO,MAAMA,oBAAoB,GAAGC,MAAM,CAACC,kBAAP,IAA6B,IAA1D,C,CACP;;;AACO,MAAMC,eAAe,GAAGF,MAAM,CAACG,qBAAP,IAAgC,IAAxD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts"],"
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["import './monkey-patch';\n\nexport * from './native';\nexport * from './animated';\nexport * from './replicas';\n"],"mappings":";;;;;;AAAA;;AAEA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
|
|
@@ -4,13 +4,15 @@ var _reactNative = require("react-native");
|
|
|
4
4
|
|
|
5
5
|
var NativeAndroidManager = _interopRequireWildcard(require("react-native/Libraries/Components/StatusBar/NativeStatusBarManagerAndroid"));
|
|
6
6
|
|
|
7
|
+
var _architecture = require("./architecture");
|
|
8
|
+
|
|
7
9
|
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); }
|
|
8
10
|
|
|
9
11
|
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; }
|
|
10
12
|
|
|
11
13
|
// @ts-expect-error because there is no corresponding type definition
|
|
12
14
|
const getConstants = NativeAndroidManager.default.getConstants;
|
|
13
|
-
const RCTStatusBarManagerCompat = _reactNative.NativeModules.StatusBarManagerCompat; // On Android < 11 RN uses legacy API which breaks EdgeToEdge mode in RN, so
|
|
15
|
+
const RCTStatusBarManagerCompat = _architecture.isTurboModuleEnabled ? require('./NativeStatusBarManagerCompat').default : _reactNative.NativeModules.StatusBarManagerCompat; // On Android < 11 RN uses legacy API which breaks EdgeToEdge mode in RN, so
|
|
14
16
|
// in order to use library on all available platforms we have to monkey patch
|
|
15
17
|
// default RN implementation and use modern `WindowInsetsControllerCompat`.
|
|
16
18
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["getConstants","NativeAndroidManager","default","RCTStatusBarManagerCompat","isTurboModuleEnabled","require","NativeModules","StatusBarManagerCompat","Platform","OS","setColor","color","animated","setTranslucent","translucent","setStyle","statusBarStyle","setHidden","hidden"],"sources":["monkey-patch.tsx"],"sourcesContent":["import { NativeModules, Platform } from 'react-native';\n// @ts-expect-error because there is no corresponding type definition\nimport * as NativeAndroidManager from 'react-native/Libraries/Components/StatusBar/NativeStatusBarManagerAndroid';\n\nimport { isTurboModuleEnabled } from './architecture';\n\nconst getConstants = NativeAndroidManager.default.getConstants;\n\nconst RCTStatusBarManagerCompat = isTurboModuleEnabled\n ? require('./NativeStatusBarManagerCompat').default\n : NativeModules.StatusBarManagerCompat;\n\n// On Android < 11 RN uses legacy API which breaks EdgeToEdge mode in RN, so\n// in order to use library on all available platforms we have to monkey patch\n// default RN implementation and use modern `WindowInsetsControllerCompat`.\nif (Platform.OS === 'android') {\n NativeAndroidManager.default = {\n getConstants,\n setColor(color: number, animated: boolean): void {\n RCTStatusBarManagerCompat.setColor(color, animated);\n },\n\n setTranslucent(translucent: boolean): void {\n RCTStatusBarManagerCompat.setTranslucent(translucent);\n },\n\n /**\n * - statusBarStyles can be:\n * - 'default'\n * - 'dark-content'\n */\n setStyle(statusBarStyle?: string): void {\n RCTStatusBarManagerCompat.setStyle(statusBarStyle);\n },\n\n setHidden(hidden: boolean): void {\n RCTStatusBarManagerCompat.setHidden(hidden);\n },\n };\n}\n"],"mappings":";;AAAA;;AAEA;;AAEA;;;;;;AAHA;AAKA,MAAMA,YAAY,GAAGC,oBAAoB,CAACC,OAArB,CAA6BF,YAAlD;AAEA,MAAMG,yBAAyB,GAAGC,kCAAA,GAC9BC,OAAO,CAAC,gCAAD,CAAP,CAA0CH,OADZ,GAE9BI,0BAAA,CAAcC,sBAFlB,C,CAIA;AACA;AACA;;AACA,IAAIC,qBAAA,CAASC,EAAT,KAAgB,SAApB,EAA+B;EAC7BR,oBAAoB,CAACC,OAArB,GAA+B;IAC7BF,YAD6B;;IAE7BU,QAAQ,CAACC,KAAD,EAAgBC,QAAhB,EAAyC;MAC/CT,yBAAyB,CAACO,QAA1B,CAAmCC,KAAnC,EAA0CC,QAA1C;IACD,CAJ4B;;IAM7BC,cAAc,CAACC,WAAD,EAA6B;MACzCX,yBAAyB,CAACU,cAA1B,CAAyCC,WAAzC;IACD,CAR4B;;IAU7B;AACJ;AACA;AACA;AACA;IACIC,QAAQ,CAACC,cAAD,EAAgC;MACtCb,yBAAyB,CAACY,QAA1B,CAAmCC,cAAnC;IACD,CAjB4B;;IAmB7BC,SAAS,CAACC,MAAD,EAAwB;MAC/Bf,yBAAyB,CAACc,SAA1B,CAAoCC,MAApC;IACD;;EArB4B,CAA/B;AAuBD"}
|
package/lib/commonjs/native.js
CHANGED
|
@@ -9,6 +9,8 @@ var _react = require("react");
|
|
|
9
9
|
|
|
10
10
|
var _reactNative = require("react-native");
|
|
11
11
|
|
|
12
|
+
var _architecture = require("./architecture");
|
|
13
|
+
|
|
12
14
|
const LINKING_ERROR = `The package 'react-native-keyboard-controller' doesn't seem to be linked. Make sure: \n\n` + _reactNative.Platform.select({
|
|
13
15
|
ios: "- You have run 'pod install'\n",
|
|
14
16
|
default: ''
|
|
@@ -24,7 +26,7 @@ exports.AndroidSoftInputModes = AndroidSoftInputModes;
|
|
|
24
26
|
})(AndroidSoftInputModes || (exports.AndroidSoftInputModes = AndroidSoftInputModes = {}));
|
|
25
27
|
|
|
26
28
|
const ComponentName = 'KeyboardControllerView';
|
|
27
|
-
const RCTKeyboardController = _reactNative.NativeModules.KeyboardController;
|
|
29
|
+
const RCTKeyboardController = _architecture.isTurboModuleEnabled ? require('./NativeKeyboardController').default : _reactNative.NativeModules.KeyboardController;
|
|
28
30
|
const KeyboardController = RCTKeyboardController;
|
|
29
31
|
exports.KeyboardController = KeyboardController;
|
|
30
32
|
const eventEmitter = new _reactNative.NativeEventEmitter(RCTKeyboardController);
|
|
@@ -32,7 +34,7 @@ const KeyboardEvents = {
|
|
|
32
34
|
addListener: (name, cb) => eventEmitter.addListener('KeyboardController::' + name, cb)
|
|
33
35
|
};
|
|
34
36
|
exports.KeyboardEvents = KeyboardEvents;
|
|
35
|
-
const KeyboardControllerView = _reactNative.UIManager.getViewManagerConfig(ComponentName) != null ? (0, _reactNative.requireNativeComponent)(ComponentName) : () => {
|
|
37
|
+
const KeyboardControllerView = _architecture.isFabricEnabled ? require('./KeyboardControllerViewNativeComponent').default : _reactNative.UIManager.getViewManagerConfig(ComponentName) != null ? (0, _reactNative.requireNativeComponent)(ComponentName) : () => {
|
|
36
38
|
throw new Error(LINKING_ERROR);
|
|
37
39
|
};
|
|
38
40
|
exports.KeyboardControllerView = KeyboardControllerView;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["LINKING_ERROR","Platform","select","ios","default","AndroidSoftInputModes","ComponentName","RCTKeyboardController","isTurboModuleEnabled","require","NativeModules","KeyboardController","eventEmitter","NativeEventEmitter","KeyboardEvents","addListener","name","cb","KeyboardControllerView","isFabricEnabled","UIManager","getViewManagerConfig","requireNativeComponent","Error","useResizeMode","useEffect","setInputMode","SOFT_INPUT_ADJUST_RESIZE","setDefaultMode"],"sources":["native.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport {\n requireNativeComponent,\n UIManager,\n Platform,\n NativeModules,\n NativeEventEmitter,\n NativeSyntheticEvent,\n ViewProps,\n} from 'react-native';\n\nimport { isFabricEnabled, isTurboModuleEnabled } from './architecture';\n\nconst LINKING_ERROR =\n `The package 'react-native-keyboard-controller' doesn't seem to be linked. Make sure: \\n\\n` +\n Platform.select({ ios: \"- You have run 'pod install'\\n\", default: '' }) +\n '- You rebuilt the app after installing the package\\n' +\n '- You are not using Expo managed workflow\\n';\n\nexport enum AndroidSoftInputModes {\n SOFT_INPUT_ADJUST_NOTHING = 48,\n SOFT_INPUT_ADJUST_PAN = 32,\n SOFT_INPUT_ADJUST_RESIZE = 16,\n SOFT_INPUT_ADJUST_UNSPECIFIED = 0,\n}\n\nexport type NativeEvent = {\n progress: number;\n height: number;\n};\nexport type EventWithName<T> = {\n eventName: string;\n} & T;\nexport type KeyboardControllerProps = {\n onKeyboardMove: (e: NativeSyntheticEvent<EventWithName<NativeEvent>>) => void;\n // fake prop used to activate reanimated bindings\n onKeyboardMoveReanimated: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n statusBarTranslucent?: boolean;\n} & ViewProps;\ntype KeyboardController = {\n // android only\n setDefaultMode: () => void;\n setInputMode: (mode: AndroidSoftInputModes) => void;\n};\n\nconst ComponentName = 'KeyboardControllerView';\n\nconst RCTKeyboardController = isTurboModuleEnabled\n ? require('./NativeKeyboardController').default\n : NativeModules.KeyboardController;\nexport const KeyboardController = RCTKeyboardController as KeyboardController;\n\nconst eventEmitter = new NativeEventEmitter(RCTKeyboardController);\ntype KeyboardControllerEvents =\n | 'keyboardWillShow'\n | 'keyboardDidShow'\n | 'keyboardWillHide'\n | 'keyboardDidHide';\ntype KeyboardEvent = {\n height: number;\n};\nexport const KeyboardEvents = {\n addListener: (\n name: KeyboardControllerEvents,\n cb: (e: KeyboardEvent) => void\n ) => eventEmitter.addListener('KeyboardController::' + name, cb),\n};\nexport const KeyboardControllerView = isFabricEnabled\n ? require('./KeyboardControllerViewNativeComponent').default\n : UIManager.getViewManagerConfig(ComponentName) != null\n ? requireNativeComponent<KeyboardControllerProps>(ComponentName)\n : () => {\n throw new Error(LINKING_ERROR);\n };\n\nexport const useResizeMode = () => {\n useEffect(() => {\n KeyboardController.setInputMode(\n AndroidSoftInputModes.SOFT_INPUT_ADJUST_RESIZE\n );\n\n return () => KeyboardController.setDefaultMode();\n }, []);\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AAUA;;AAEA,MAAMA,aAAa,GAChB,2FAAD,GACAC,qBAAA,CAASC,MAAT,CAAgB;EAAEC,GAAG,EAAE,gCAAP;EAAyCC,OAAO,EAAE;AAAlD,CAAhB,CADA,GAEA,sDAFA,GAGA,6CAJF;IAMYC,qB;;;WAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;GAAAA,qB,qCAAAA,qB;;AA4BZ,MAAMC,aAAa,GAAG,wBAAtB;AAEA,MAAMC,qBAAqB,GAAGC,kCAAA,GAC1BC,OAAO,CAAC,4BAAD,CAAP,CAAsCL,OADZ,GAE1BM,0BAAA,CAAcC,kBAFlB;AAGO,MAAMA,kBAAkB,GAAGJ,qBAA3B;;AAEP,MAAMK,YAAY,GAAG,IAAIC,+BAAJ,CAAuBN,qBAAvB,CAArB;AASO,MAAMO,cAAc,GAAG;EAC5BC,WAAW,EAAE,CACXC,IADW,EAEXC,EAFW,KAGRL,YAAY,CAACG,WAAb,CAAyB,yBAAyBC,IAAlD,EAAwDC,EAAxD;AAJuB,CAAvB;;AAMA,MAAMC,sBAAsB,GAAGC,6BAAA,GAClCV,OAAO,CAAC,yCAAD,CAAP,CAAmDL,OADjB,GAElCgB,sBAAA,CAAUC,oBAAV,CAA+Bf,aAA/B,KAAiD,IAAjD,GACA,IAAAgB,mCAAA,EAAgDhB,aAAhD,CADA,GAEA,MAAM;EACJ,MAAM,IAAIiB,KAAJ,CAAUvB,aAAV,CAAN;AACD,CANE;;;AAQA,MAAMwB,aAAa,GAAG,MAAM;EACjC,IAAAC,gBAAA,EAAU,MAAM;IACdd,kBAAkB,CAACe,YAAnB,CACErB,qBAAqB,CAACsB,wBADxB;IAIA,OAAO,MAAMhB,kBAAkB,CAACiB,cAAnB,EAAb;EACD,CAND,EAMG,EANH;AAOD,CARM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["availableOSEventType","Platform","OS","defaultAndroidEasing","Easing","bezier","useKeyboardAnimationReplica","height","useRef","Animated","Value","progress","animation","useMemo","current","useEffect","KeyboardController","setInputMode","AndroidSoftInputModes","SOFT_INPUT_ADJUST_RESIZE","setDefaultMode","listener","Keyboard","addListener","e","timing","toValue","endCoordinates","duration","easing","useNativeDriver","start","remove","IOS_SPRING_CONFIG","damping","stiffness","mass","overshootClamping","restDisplacementThreshold","restSpeedThreshold","useReanimatedKeyboardAnimationReplica","useSharedValue","heightEvent","useDerivedValue","value","handler","useWorkletCallback","_height","useAnimatedReaction","_keyboardHeight","result","_previousResult","_previousKeyboardHeight","withSpring","show","runOnUI","hide","useGradualKeyboardAnimation","useReanimatedKeyboardAnimation"],"sources":["replicas.ts"],"sourcesContent":["import { useRef, useEffect, useMemo } from 'react';\nimport { Animated, Easing, Keyboard, Platform } from 'react-native';\nimport {\n runOnUI,\n useAnimatedReaction,\n useDerivedValue,\n useSharedValue,\n useWorkletCallback,\n withSpring,\n} from 'react-native-reanimated';\nimport { useReanimatedKeyboardAnimation } from './animated';\n\nimport { AndroidSoftInputModes, KeyboardController } from './native';\n\nconst availableOSEventType = Platform.OS === 'ios' ? 'Will' : 'Did';\n\n// cubic-bezier(.17,.67,.34,.94)\nexport const defaultAndroidEasing = Easing.bezier(0.4, 0.0, 0.2, 1);\ntype KeyboardAnimation = {\n progress: Animated.Value;\n height: Animated.Value;\n};\n\n/**\n * An experimental implementation of tracing keyboard appearance.\n * Switch an input mode to adjust resize mode. In this case all did* events\n * are triggering before keyboard appears, and using some approximations\n * it tries to mimicries a native transition.\n *\n * @returns {Animated.Value}\n */\nexport const useKeyboardAnimationReplica = (): KeyboardAnimation => {\n const height = useRef(new Animated.Value(0));\n const progress = useRef(new Animated.Value(0));\n const animation = useMemo(\n () => ({\n height: height.current,\n progress: progress.current,\n }),\n []\n );\n\n useEffect(() => {\n KeyboardController.setInputMode(\n AndroidSoftInputModes.SOFT_INPUT_ADJUST_RESIZE\n );\n\n return () => KeyboardController.setDefaultMode();\n }, []);\n useEffect(() => {\n const listener = Keyboard.addListener(\n `keyboard${availableOSEventType}Show`,\n (e) => {\n Animated.timing(height.current, {\n toValue: -e.endCoordinates.height,\n duration: e.duration !== 0 ? e.duration : 300,\n easing: Easing.bezier(0.4, 0.0, 0.2, 1),\n useNativeDriver: true,\n }).start();\n\n return () => listener.remove();\n }\n );\n }, []);\n useEffect(() => {\n const listener = Keyboard.addListener(\n `keyboard${availableOSEventType}Hide`,\n (e) => {\n Animated.timing(height.current, {\n toValue: 0,\n duration: e.duration !== 0 ? e.duration : 300,\n easing: Easing.bezier(0.4, 0.0, 0.2, 1),\n useNativeDriver: true,\n }).start();\n\n return () => listener.remove();\n }\n );\n }, []);\n\n return animation;\n};\n\nconst IOS_SPRING_CONFIG = {\n damping: 500,\n stiffness: 1000,\n mass: 3,\n overshootClamping: true,\n restDisplacementThreshold: 10,\n restSpeedThreshold: 10,\n};\n\n/**\n * A close replica to native iOS keyboard animation. The problem is that\n * iOS (unlike Android) can not fire events for each keyboard frame movement.\n * As a result we can not get gradual values (for example, for progress it always\n * will be 1 or 0). So if you want to rely on gradual values you will need to use\n * this replica.\n *\n * The transition is hardcoded and may vary from one to another OS versions. But it\n * seems like last time it has been changed in iOS 7. Since RN supports at least iOS\n * 11 it doesn't make sense to replicate iOS 7 behavior. If it changes in next OS\n * versions, then this implementation should be revisited and reflect necessary changes.\n *\n * @returns {height, progress} - animated values\n */\nexport const useReanimatedKeyboardAnimationReplica = () => {\n const height = useSharedValue(0);\n const heightEvent = useSharedValue(0);\n\n const progress = useDerivedValue(() => height.value / heightEvent.value);\n\n const handler = useWorkletCallback((_height: number) => {\n heightEvent.value = _height;\n }, []);\n\n useAnimatedReaction(\n () => ({\n _keyboardHeight: heightEvent.value,\n }),\n (result, _previousResult) => {\n const { _keyboardHeight } = result;\n const _previousKeyboardHeight = _previousResult?._keyboardHeight;\n\n if (_keyboardHeight !== _previousKeyboardHeight) {\n height.value = withSpring(_keyboardHeight, IOS_SPRING_CONFIG);\n }\n },\n []\n );\n\n useEffect(() => {\n const show = Keyboard.addListener('keyboardWillShow', (e) => {\n runOnUI(handler)(-e.endCoordinates.height);\n });\n const hide = Keyboard.addListener('keyboardWillHide', () => {\n runOnUI(handler)(0);\n });\n\n return () => {\n show.remove();\n hide.remove();\n };\n }, []);\n\n return { height, progress };\n};\n\nexport const useGradualKeyboardAnimation =\n Platform.OS === 'ios'\n ? useReanimatedKeyboardAnimationReplica\n : useReanimatedKeyboardAnimation;\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAQA;;AAEA;;AAEA,MAAMA,oBAAoB,GAAGC,qBAAA,CAASC,EAAT,KAAgB,KAAhB,GAAwB,MAAxB,GAAiC,KAA9D,C,CAEA;;AACO,MAAMC,oBAAoB,GAAGC,mBAAA,CAAOC,MAAP,CAAc,GAAd,EAAmB,GAAnB,EAAwB,GAAxB,EAA6B,CAA7B,CAA7B;;;;AAMP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,2BAA2B,GAAG,MAAyB;EAClE,MAAMC,MAAM,GAAG,IAAAC,aAAA,EAAO,IAAIC,qBAAA,CAASC,KAAb,CAAmB,CAAnB,CAAP,CAAf;EACA,MAAMC,QAAQ,GAAG,IAAAH,aAAA,EAAO,IAAIC,qBAAA,CAASC,KAAb,CAAmB,CAAnB,CAAP,CAAjB;EACA,MAAME,SAAS,GAAG,IAAAC,cAAA,EAChB,OAAO;IACLN,MAAM,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ACF,CAXH,EAYE,EAZF;EAeA,IAAAlB,gBAAA,EAAU,MAAM;IACd,MAAMuC,IAAI,GAAGhC,qBAAA,CAASC,WAAT,CAAqB,kBAArB,EAA0CC,CAAD,IAAO;MAC3D,IAAA+B,8BAAA,EAAQV,OAAR,EAAiB,CAACrB,CAAC,CAACG,cAAF,CAAiBpB,MAAnC;IACD,CAFY,CAAb;;IAGA,MAAMiD,IAAI,GAAGlC,qBAAA,CAASC,WAAT,CAAqB,kBAArB,EAAyC,MAAM;MAC1D,IAAAgC,8BAAA,EAAQV,OAAR,EAAiB,CAAjB;IACD,CAFY,CAAb;;IAIA,OAAO,MAAM;MACXS,IAAI,CAACtB,MAAL;MACAwB,IAAI,CAACxB,MAAL;IACD,CAHD;EAID,CAZD,EAYG,EAZH;EAcA,OAAO;IAAEzB,MAAF;IAAUI;EAAV,CAAP;AACD,CAxCM;;;AA0CA,MAAM8C,2BAA2B,GACtCxD,qBAAA,CAASC,EAAT,KAAgB,KAAhB,GACIsC,qCADJ,GAEIkB,wCAHC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["codegenNativeComponent"],"sources":["KeyboardControllerViewNativeComponent.ts"],"sourcesContent":["import type { HostComponent } from 'react-native';\n// @ts-expect-error - no type definition\nimport type { ViewProps } from 'react-native/Libraries/Components/View/ViewPropTypes';\nimport type {\n DirectEventHandler,\n Float,\n Int32,\n} from 'react-native/Libraries/Types/CodegenTypes';\nimport codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';\n\ntype KeyboardMoveEvent = Readonly<{\n height: Int32;\n progress: Float;\n}>;\n\nexport interface NativeProps extends ViewProps {\n statusBarTranslucent?: boolean;\n onKeyboardMove?: DirectEventHandler<KeyboardMoveEvent>;\n}\n\nexport default codegenNativeComponent<NativeProps>(\n 'KeyboardControllerView'\n) as HostComponent<NativeProps>;\n"],"mappings":"AACA;AAOA,OAAOA,sBAAP,MAAmC,yDAAnC;AAYA,eAAeA,sBAAsB,CACnC,wBADmC,CAArC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["TurboModuleRegistry","get"],"sources":["NativeKeyboardController.ts"],"sourcesContent":["import type { TurboModule } from 'react-native';\nimport { TurboModuleRegistry } from 'react-native';\n\nexport interface Spec extends TurboModule {\n readonly getConstants: () => {};\n\n // methods\n setInputMode(mode: number): void;\n setDefaultMode(): void;\n\n // event emitter\n addListener: (eventName: string) => void;\n removeListeners: (count: number) => void;\n}\n\nexport default TurboModuleRegistry.get<Spec>('KeyboardController');\n"],"mappings":"AACA,SAASA,mBAAT,QAAoC,cAApC;AAcA,eAAeA,mBAAmB,CAACC,GAApB,CAA8B,oBAA9B,CAAf"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["TurboModuleRegistry","get"],"sources":["NativeStatusBarManagerCompat.ts"],"sourcesContent":["import type { TurboModule } from 'react-native';\nimport { TurboModuleRegistry } from 'react-native';\n\nexport interface Spec extends TurboModule {\n readonly getConstants: () => {};\n\n setHidden(hidden: boolean): void;\n setColor(color: number, animated: boolean): void;\n setTranslucent(translucent: boolean): void;\n setStyle(style: string): void;\n}\n\nexport default TurboModuleRegistry.get<Spec>('StatusBarManagerCompat');\n"],"mappings":"AACA,SAASA,mBAAT,QAAoC,cAApC;AAWA,eAAeA,mBAAmB,CAACC,GAApB,CAA8B,wBAA9B,CAAf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["React","useContext","useMemo","useRef","Animated","StyleSheet","Reanimated","useEvent","useHandler","useSharedValue","KeyboardControllerView","useResizeMode","KeyboardControllerViewAnimated","createAnimatedComponent","defaultContext","animated","progress","Value","height","reanimated","value","KeyboardContext","createContext","useKeyboardAnimation","context","useReanimatedKeyboardAnimation","useAnimatedKeyboardHandler","handlers","dependencies","doDependenciesDiffer","event","onKeyboardMove","eventName","endsWith","styles","create","container","flex","hidden","display","position","KeyboardProvider","children","statusBarTranslucent","current","progressSV","heightSV","style","transform","translateX","translateY","nativeEvent","useNativeDriver","handler"],"sources":["animated.tsx"],"sourcesContent":["import React, { useContext, useMemo, useRef } from 'react';\nimport { Animated, StyleSheet, ViewStyle } from 'react-native';\nimport Reanimated, {\n useEvent,\n useHandler,\n useSharedValue,\n} from 'react-native-reanimated';\nimport {\n EventWithName,\n KeyboardControllerProps,\n KeyboardControllerView,\n NativeEvent,\n useResizeMode,\n} from './native';\n\nconst KeyboardControllerViewAnimated = Reanimated.createAnimatedComponent(\n Animated.createAnimatedComponent(\n KeyboardControllerView\n ) as React.FC<KeyboardControllerProps>\n);\n\ntype AnimatedContext = {\n progress: Animated.Value;\n height: Animated.Value;\n};\ntype ReanimatedContext = {\n progress: Reanimated.SharedValue<number>;\n height: Reanimated.SharedValue<number>;\n};\ntype KeyboardAnimationContext = {\n animated: AnimatedContext;\n reanimated: ReanimatedContext;\n};\nconst defaultContext: KeyboardAnimationContext = {\n animated: {\n progress: new Animated.Value(0),\n height: new Animated.Value(0),\n },\n reanimated: {\n progress: { value: 0 },\n height: { value: 0 },\n },\n};\nexport const KeyboardContext = React.createContext(defaultContext);\n\nexport const useKeyboardAnimation = (): AnimatedContext => {\n useResizeMode();\n const context = useContext(KeyboardContext);\n\n return context.animated;\n};\n\nexport const useReanimatedKeyboardAnimation = (): ReanimatedContext => {\n useResizeMode();\n const context = useContext(KeyboardContext);\n\n return context.reanimated;\n};\n\nfunction useAnimatedKeyboardHandler<TContext extends Record<string, unknown>>(\n handlers: {\n onKeyboardMove?: (e: NativeEvent, context: TContext) => void;\n },\n dependencies?: ReadonlyArray<unknown>\n) {\n const { context, doDependenciesDiffer } = useHandler(handlers, dependencies);\n\n return useEvent(\n (event: EventWithName<NativeEvent>) => {\n 'worklet';\n const { onKeyboardMove } = handlers;\n\n if (onKeyboardMove && event.eventName.endsWith('onKeyboardMove')) {\n onKeyboardMove(event, context);\n }\n },\n ['onKeyboardMove'],\n doDependenciesDiffer\n );\n}\n\ntype Styles = {\n container: ViewStyle;\n hidden: ViewStyle;\n};\n\nexport const 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\nexport const KeyboardProvider = ({\n children,\n statusBarTranslucent,\n}: KeyboardProviderProps) => {\n const progress = useRef(new Animated.Value(0)).current;\n const height = useRef(new Animated.Value(0)).current;\n const progressSV = useSharedValue(0);\n const heightSV = useSharedValue(0);\n const context = useMemo(\n () => ({\n animated: { progress: progress, height: height },\n reanimated: { progress: progressSV, height: heightSV },\n }),\n []\n );\n const style = useMemo(\n () => [\n styles.hidden,\n { transform: [{ translateX: height }, { translateY: progress }] },\n ],\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\n const handler = useAnimatedKeyboardHandler(\n {\n onKeyboardMove: (event: NativeEvent) => {\n 'worklet';\n progressSV.value = event.progress;\n heightSV.value = event.height;\n },\n },\n []\n );\n\n return (\n <KeyboardContext.Provider value={context}>\n <KeyboardControllerViewAnimated\n onKeyboardMoveReanimated={handler}\n onKeyboardMove={onKeyboardMove}\n statusBarTranslucent={statusBarTranslucent}\n style={styles.container}\n >\n <>\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 {children}\n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