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
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 The Android Open Source Project
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
package com.reactnativekeyboardcontroller
|
|
18
|
-
|
|
19
|
-
import android.content.Context
|
|
20
|
-
import android.util.Log
|
|
21
|
-
import androidx.core.graphics.Insets
|
|
22
|
-
import androidx.core.view.ViewCompat
|
|
23
|
-
import androidx.core.view.WindowInsetsAnimationCompat
|
|
24
|
-
import androidx.core.view.WindowInsetsCompat
|
|
25
|
-
import com.facebook.react.bridge.Arguments
|
|
26
|
-
import com.facebook.react.bridge.ReactApplicationContext
|
|
27
|
-
import com.facebook.react.bridge.WritableMap
|
|
28
|
-
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
29
|
-
import com.facebook.react.uimanager.UIManagerModule
|
|
30
|
-
import com.facebook.react.views.view.ReactViewGroup
|
|
31
|
-
import com.reactnativekeyboardcontroller.events.KeyboardTransitionEvent
|
|
32
|
-
import java.util.*
|
|
33
|
-
|
|
34
|
-
fun toDp(px: Float, context: Context?): Int {
|
|
35
|
-
if (context == null) {
|
|
36
|
-
return 0
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return (px / context.resources.displayMetrics.density).toInt()
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* A [WindowInsetsAnimationCompat.Callback] which will translate/move the given view during any
|
|
44
|
-
* inset animations of the given inset type.
|
|
45
|
-
*
|
|
46
|
-
* This class works in tandem with [RootViewDeferringInsetsCallback] to support the deferring of
|
|
47
|
-
* certain [WindowInsetsCompat.Type] values during a [WindowInsetsAnimationCompat], provided in
|
|
48
|
-
* [deferredInsetTypes]. The values passed into this constructor should match those which
|
|
49
|
-
* the [RootViewDeferringInsetsCallback] is created with.
|
|
50
|
-
*
|
|
51
|
-
* @param view the view to translate from it's start to end state
|
|
52
|
-
* @param persistentInsetTypes the bitmask of any inset types which were handled as part of the
|
|
53
|
-
* layout
|
|
54
|
-
* @param deferredInsetTypes the bitmask of insets types which should be deferred until after
|
|
55
|
-
* any [WindowInsetsAnimationCompat]s have ended
|
|
56
|
-
* @param dispatchMode The dispatch mode for this callback.
|
|
57
|
-
* See [WindowInsetsAnimationCompat.Callback.getDispatchMode].
|
|
58
|
-
*/
|
|
59
|
-
class TranslateDeferringInsetsAnimationCallback(
|
|
60
|
-
val view: ReactViewGroup,
|
|
61
|
-
val persistentInsetTypes: Int,
|
|
62
|
-
val deferredInsetTypes: Int,
|
|
63
|
-
dispatchMode: Int = DISPATCH_MODE_STOP,
|
|
64
|
-
val context: ReactApplicationContext?
|
|
65
|
-
) : WindowInsetsAnimationCompat.Callback(dispatchMode) {
|
|
66
|
-
private val TAG = TranslateDeferringInsetsAnimationCallback::class.qualifiedName
|
|
67
|
-
private var persistentKeyboardHeight = 0
|
|
68
|
-
|
|
69
|
-
init {
|
|
70
|
-
require(persistentInsetTypes and deferredInsetTypes == 0) {
|
|
71
|
-
"persistentInsetTypes and deferredInsetTypes can not contain any of " +
|
|
72
|
-
" same WindowInsetsCompat.Type values"
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
override fun onStart(
|
|
77
|
-
animation: WindowInsetsAnimationCompat,
|
|
78
|
-
bounds: WindowInsetsAnimationCompat.BoundsCompat
|
|
79
|
-
): WindowInsetsAnimationCompat.BoundsCompat {
|
|
80
|
-
val keyboardHeight = getCurrentKeyboardHeight()
|
|
81
|
-
val isKeyboardVisible = isKeyboardVisible()
|
|
82
|
-
|
|
83
|
-
if (isKeyboardVisible) {
|
|
84
|
-
// do not update it on hide, since back progress will be invalid
|
|
85
|
-
this.persistentKeyboardHeight = keyboardHeight
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
val params: WritableMap = Arguments.createMap()
|
|
89
|
-
params.putInt("height", keyboardHeight)
|
|
90
|
-
context?.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)?.emit("KeyboardController::" + if (!isKeyboardVisible) "keyboardWillHide" else "keyboardWillShow", params)
|
|
91
|
-
|
|
92
|
-
Log.i(TAG, "KeyboardController::" + if (!isKeyboardVisible) "keyboardWillHide" else "keyboardWillShow")
|
|
93
|
-
Log.i(TAG, "HEIGHT:: $keyboardHeight")
|
|
94
|
-
|
|
95
|
-
return super.onStart(animation, bounds)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
override fun onEnd(animation: WindowInsetsAnimationCompat) {
|
|
99
|
-
super.onEnd(animation)
|
|
100
|
-
|
|
101
|
-
val isKeyboardVisible = isKeyboardVisible()
|
|
102
|
-
|
|
103
|
-
val params: WritableMap = Arguments.createMap()
|
|
104
|
-
context?.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)?.emit("KeyboardController::" + if (!isKeyboardVisible) "keyboardDidHide" else "keyboardDidShow", params)
|
|
105
|
-
|
|
106
|
-
Log.i(TAG, "KeyboardController::" + if (!isKeyboardVisible) "keyboardDidHide" else "keyboardDidShow")
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
private fun isKeyboardVisible(): Boolean {
|
|
110
|
-
val insets = ViewCompat.getRootWindowInsets(view)
|
|
111
|
-
|
|
112
|
-
return insets?.isVisible(WindowInsetsCompat.Type.ime()) ?: false
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
private fun getCurrentKeyboardHeight(): Int {
|
|
116
|
-
val insets = ViewCompat.getRootWindowInsets(view)
|
|
117
|
-
val keyboardHeight = insets?.getInsets(WindowInsetsCompat.Type.ime())?.bottom ?: 0
|
|
118
|
-
val navigationBar = insets?.getInsets(WindowInsetsCompat.Type.navigationBars())?.bottom ?: 0
|
|
119
|
-
|
|
120
|
-
// on hide it will be negative value, so we are using max function
|
|
121
|
-
return Math.max(toDp((keyboardHeight - navigationBar).toFloat(), context), 0)
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
override fun onProgress(
|
|
125
|
-
insets: WindowInsetsCompat,
|
|
126
|
-
runningAnimations: List<WindowInsetsAnimationCompat>
|
|
127
|
-
): WindowInsetsCompat {
|
|
128
|
-
// onProgress() is called when any of the running animations progress...
|
|
129
|
-
|
|
130
|
-
// First we get the insets which are potentially deferred
|
|
131
|
-
val typesInset = insets.getInsets(deferredInsetTypes)
|
|
132
|
-
// Then we get the persistent inset types which are applied as padding during layout
|
|
133
|
-
val otherInset = insets.getInsets(persistentInsetTypes)
|
|
134
|
-
|
|
135
|
-
// Now that we subtract the two insets, to calculate the difference. We also coerce
|
|
136
|
-
// the insets to be >= 0, to make sure we don't use negative insets.
|
|
137
|
-
val diff = Insets.subtract(typesInset, otherInset).let {
|
|
138
|
-
Insets.max(it, Insets.NONE)
|
|
139
|
-
}
|
|
140
|
-
val diffY = (diff.top - diff.bottom).toFloat()
|
|
141
|
-
val height = toDp(diffY, context)
|
|
142
|
-
|
|
143
|
-
var progress = 0.0
|
|
144
|
-
try {
|
|
145
|
-
progress = Math.abs((height.toDouble() / persistentKeyboardHeight))
|
|
146
|
-
} catch (e: ArithmeticException) {
|
|
147
|
-
// do nothing, send progress as 0
|
|
148
|
-
}
|
|
149
|
-
Log.i(TAG, "DiffY: $diffY $height")
|
|
150
|
-
|
|
151
|
-
context
|
|
152
|
-
?.getNativeModule(UIManagerModule::class.java)
|
|
153
|
-
?.eventDispatcher
|
|
154
|
-
?.dispatchEvent(KeyboardTransitionEvent(view.id, height, progress))
|
|
155
|
-
|
|
156
|
-
return insets
|
|
157
|
-
}
|
|
158
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// RCTBridge.m
|
|
3
|
-
// KeyboardController
|
|
4
|
-
//
|
|
5
|
-
// Created by Kiryl Ziusko on 22.04.22.
|
|
6
|
-
// Copyright © 2022 Facebook. All rights reserved.
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
#import <React/RCTBridgeModule.h>
|
|
10
|
-
#import <React/RCTEventEmitter.h>
|
|
11
|
-
|
|
12
|
-
@interface RCT_EXTERN_MODULE(KeyboardController, RCTEventEmitter)
|
|
13
|
-
|
|
14
|
-
// Android stubs
|
|
15
|
-
RCT_EXTERN_METHOD(setInputMode: (nonnull NSNumber*) mode)
|
|
16
|
-
RCT_EXTERN_METHOD(setDefaultMode)
|
|
17
|
-
|
|
18
|
-
// event emitter
|
|
19
|
-
RCT_EXTERN_METHOD(supportedEvents)
|
|
20
|
-
|
|
21
|
-
@end
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// KeyboardController.swift
|
|
3
|
-
// KeyboardController
|
|
4
|
-
//
|
|
5
|
-
// Created by Kiryl Ziusko on 22.04.22.
|
|
6
|
-
// Copyright © 2022 Facebook. All rights reserved.
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
import AVFoundation
|
|
10
|
-
import Foundation
|
|
11
|
-
import UIKit
|
|
12
|
-
|
|
13
|
-
@objc(KeyboardController)
|
|
14
|
-
class KeyboardController: RCTEventEmitter {
|
|
15
|
-
public static var shared: KeyboardController?
|
|
16
|
-
private var hasListeners = false
|
|
17
|
-
|
|
18
|
-
override class func requiresMainQueueSetup() -> Bool {
|
|
19
|
-
return false
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
override init() {
|
|
23
|
-
super.init()
|
|
24
|
-
KeyboardController.shared = self
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Android stubs
|
|
28
|
-
@objc func setInputMode(_: NSNumber!) {}
|
|
29
|
-
@objc func setDefaultMode() {}
|
|
30
|
-
|
|
31
|
-
@objc override open func supportedEvents() -> [String] {
|
|
32
|
-
return [
|
|
33
|
-
"KeyboardController::keyboardWillShow",
|
|
34
|
-
"KeyboardController::keyboardDidShow",
|
|
35
|
-
"KeyboardController::keyboardWillHide",
|
|
36
|
-
"KeyboardController::keyboardDidHide",
|
|
37
|
-
]
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
@objc override open func startObserving() {
|
|
41
|
-
hasListeners = true
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
@objc override open func stopObserving() {
|
|
45
|
-
hasListeners = false
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
@objc override open func sendEvent(withName name: String!, body: Any!) {
|
|
49
|
-
if hasListeners {
|
|
50
|
-
super.sendEvent(withName: name, body: body)
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// KeyboardMoveEvent.swift
|
|
3
|
-
// KeyboardController
|
|
4
|
-
//
|
|
5
|
-
// Created by Kiryl Ziusko on 26.04.22.
|
|
6
|
-
// Copyright © 2022 Facebook. All rights reserved.
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
class KeyboardMoveEvent: NSObject, RCTEvent {
|
|
10
|
-
var viewTag: NSNumber!
|
|
11
|
-
var eventName: String = "onKeyboardMove"
|
|
12
|
-
var coalescingKey: UInt16 = 0
|
|
13
|
-
var height: NSNumber!
|
|
14
|
-
var progress: NSNumber!
|
|
15
|
-
|
|
16
|
-
func canCoalesce() -> Bool {
|
|
17
|
-
return false
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
func coalesce(with newEvent: RCTEvent!) -> RCTEvent! {
|
|
21
|
-
return newEvent
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
static func moduleDotMethod() -> String! {
|
|
25
|
-
return "RCTEventEmitter.receiveEvent"
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
func arguments() -> [Any]! {
|
|
29
|
-
return [
|
|
30
|
-
viewTag,
|
|
31
|
-
RCTNormalizeInputEventName(eventName),
|
|
32
|
-
["height": height, "progress": progress],
|
|
33
|
-
]
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
init(viewTag: NSNumber, height: NSNumber, progress: NSNumber) {
|
|
37
|
-
self.viewTag = viewTag
|
|
38
|
-
self.height = height
|
|
39
|
-
self.progress = progress
|
|
40
|
-
}
|
|
41
|
-
}
|