react-native-keyboard-controller 1.13.2 → 1.13.4
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/src/main/java/com/reactnativekeyboardcontroller/extensions/EditText.kt +7 -7
- package/android/src/main/java/com/reactnativekeyboardcontroller/extensions/ThemedReactContext.kt +2 -2
- package/android/src/main/java/com/reactnativekeyboardcontroller/extensions/View.kt +2 -2
- package/android/src/main/java/com/reactnativekeyboardcontroller/listeners/KeyboardAnimationCallback.kt +5 -5
- package/android/src/main/java/com/reactnativekeyboardcontroller/log/Logger.kt +20 -0
- package/android/src/main/java/com/reactnativekeyboardcontroller/modal/ModalAttachedWatcher.kt +2 -2
- package/android/src/main/java/com/reactnativekeyboardcontroller/modules/StatusBarManagerCompatModuleImpl.kt +3 -3
- package/android/src/main/java/com/reactnativekeyboardcontroller/views/EdgeToEdgeReactViewGroup.kt +2 -2
- package/ios/extensions/UIResponder.swift +3 -2
- package/ios/extensions/UIView.swift +10 -2
- package/ios/observers/KeyboardMovementObserver.swift +11 -8
- package/ios/views/KeyboardControllerView.mm +6 -0
- package/lib/commonjs/components/KeyboardAvoidingView/hooks.js +4 -3
- package/lib/commonjs/components/KeyboardAvoidingView/hooks.js.map +1 -1
- package/lib/commonjs/components/KeyboardAvoidingView/index.js +4 -4
- package/lib/commonjs/components/KeyboardAvoidingView/index.js.map +1 -1
- package/lib/commonjs/components/KeyboardAwareScrollView/index.js +4 -4
- package/lib/commonjs/components/KeyboardAwareScrollView/index.js.map +1 -1
- package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +2 -2
- package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -1
- package/lib/commonjs/components/KeyboardStickyView/index.js +2 -2
- package/lib/commonjs/components/KeyboardStickyView/index.js.map +1 -1
- package/lib/commonjs/components/KeyboardToolbar/index.js +3 -3
- package/lib/commonjs/components/KeyboardToolbar/index.js.map +1 -1
- package/lib/commonjs/hooks/index.js +2 -4
- package/lib/commonjs/hooks/index.js.map +1 -1
- package/lib/commonjs/internal.js +24 -12
- package/lib/commonjs/internal.js.map +1 -1
- package/lib/module/components/KeyboardAvoidingView/hooks.js +2 -1
- package/lib/module/components/KeyboardAvoidingView/hooks.js.map +1 -1
- package/lib/module/components/KeyboardAvoidingView/index.js +1 -1
- package/lib/module/components/KeyboardAvoidingView/index.js.map +1 -1
- package/lib/module/components/KeyboardAwareScrollView/index.js +1 -1
- package/lib/module/components/KeyboardAwareScrollView/index.js.map +1 -1
- package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +1 -1
- package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -1
- package/lib/module/components/KeyboardStickyView/index.js +1 -1
- package/lib/module/components/KeyboardStickyView/index.js.map +1 -1
- package/lib/module/components/KeyboardToolbar/index.js +2 -2
- package/lib/module/components/KeyboardToolbar/index.js.map +1 -1
- package/lib/module/hooks/index.js +3 -4
- package/lib/module/hooks/index.js.map +1 -1
- package/lib/module/internal.js +24 -12
- package/lib/module/internal.js.map +1 -1
- package/lib/typescript/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.d.ts +1 -1
- package/package.json +1 -1
- package/src/components/KeyboardAvoidingView/hooks.ts +2 -4
- package/src/components/KeyboardAvoidingView/index.tsx +1 -1
- package/src/components/KeyboardAwareScrollView/index.tsx +1 -1
- package/src/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.ts +1 -1
- package/src/components/KeyboardStickyView/index.tsx +1 -1
- package/src/components/KeyboardToolbar/index.tsx +2 -6
- package/src/hooks/index.ts +3 -5
- package/src/internal.ts +34 -15
- package/lib/commonjs/hooks/useSyncEffect/index.js +0 -37
- package/lib/commonjs/hooks/useSyncEffect/index.js.map +0 -1
- package/lib/module/hooks/useSyncEffect/index.js +0 -31
- package/lib/module/hooks/useSyncEffect/index.js.map +0 -1
- package/lib/typescript/hooks/useSyncEffect/index.d.ts +0 -14
- package/src/hooks/useSyncEffect/index.ts +0 -36
|
@@ -3,11 +3,11 @@ package com.reactnativekeyboardcontroller.extensions
|
|
|
3
3
|
import android.os.Build
|
|
4
4
|
import android.text.Editable
|
|
5
5
|
import android.text.TextWatcher
|
|
6
|
-
import android.util.Log
|
|
7
6
|
import android.view.View
|
|
8
7
|
import android.widget.EditText
|
|
9
|
-
import
|
|
8
|
+
import com.facebook.react.views.scroll.ReactScrollView
|
|
10
9
|
import com.facebook.react.views.textinput.ReactEditText
|
|
10
|
+
import com.reactnativekeyboardcontroller.log.Logger
|
|
11
11
|
import com.reactnativekeyboardcontroller.ui.FrameScheduler
|
|
12
12
|
import java.lang.reflect.Field
|
|
13
13
|
import kotlin.math.max
|
|
@@ -57,15 +57,15 @@ fun EditText.addOnTextChangedListener(action: (String) -> Unit): TextWatcher {
|
|
|
57
57
|
|
|
58
58
|
textWatchListeners.add(0, listener)
|
|
59
59
|
} else {
|
|
60
|
-
|
|
60
|
+
Logger.w(
|
|
61
61
|
javaClass.simpleName,
|
|
62
62
|
"Can not attach listener because `fieldValue` does not belong to `ArrayList<TextWatcher>`",
|
|
63
63
|
)
|
|
64
64
|
}
|
|
65
65
|
} catch (e: ClassCastException) {
|
|
66
|
-
|
|
66
|
+
Logger.w(javaClass.simpleName, "Can not attach listener because casting failed: ${e.message}")
|
|
67
67
|
} catch (e: NoSuchFieldException) {
|
|
68
|
-
|
|
68
|
+
Logger.w(javaClass.simpleName, "Can not attach listener because field `mListeners` not found: ${e.message}")
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
return listener
|
|
@@ -78,8 +78,8 @@ val EditText.parentScrollViewTarget: Int
|
|
|
78
78
|
while (currentView != null) {
|
|
79
79
|
val parentView = currentView.parent as? View
|
|
80
80
|
|
|
81
|
-
if (parentView is
|
|
82
|
-
// If the parent is a vertical ScrollView
|
|
81
|
+
if (parentView is ReactScrollView && parentView.scrollEnabled) {
|
|
82
|
+
// If the parent is a vertical, scrollable ScrollView - return its id
|
|
83
83
|
return parentView.id
|
|
84
84
|
}
|
|
85
85
|
|
package/android/src/main/java/com/reactnativekeyboardcontroller/extensions/ThemedReactContext.kt
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
package com.reactnativekeyboardcontroller.extensions
|
|
2
2
|
|
|
3
|
-
import android.util.Log
|
|
4
3
|
import com.facebook.react.bridge.ReactContext
|
|
5
4
|
import com.facebook.react.bridge.WritableMap
|
|
6
5
|
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
@@ -9,6 +8,7 @@ import com.facebook.react.uimanager.UIManagerHelper
|
|
|
9
8
|
import com.facebook.react.uimanager.events.Event
|
|
10
9
|
import com.facebook.react.uimanager.events.EventDispatcher
|
|
11
10
|
import com.reactnativekeyboardcontroller.listeners.WindowDimensionListener
|
|
11
|
+
import com.reactnativekeyboardcontroller.log.Logger
|
|
12
12
|
|
|
13
13
|
fun ThemedReactContext.setupWindowDimensionsListener() {
|
|
14
14
|
WindowDimensionListener(this)
|
|
@@ -25,5 +25,5 @@ fun ThemedReactContext?.emitEvent(event: String, params: WritableMap) {
|
|
|
25
25
|
?.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
26
26
|
?.emit(event, params)
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
Logger.i("ThemedReactContext", event)
|
|
29
29
|
}
|
|
@@ -2,9 +2,9 @@ package com.reactnativekeyboardcontroller.extensions
|
|
|
2
2
|
|
|
3
3
|
import android.graphics.Rect
|
|
4
4
|
import android.os.Build
|
|
5
|
-
import android.util.Log
|
|
6
5
|
import android.view.View
|
|
7
6
|
import androidx.annotation.RequiresApi
|
|
7
|
+
import com.reactnativekeyboardcontroller.log.Logger
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Call this every time when using [ViewCompat.setOnApplyWindowInsetsListener]
|
|
@@ -43,7 +43,7 @@ fun View.copyBoundsInWindow(rect: Rect) {
|
|
|
43
43
|
getLocationInWindow(tmpIntArr)
|
|
44
44
|
rect.offset(tmpIntArr[0], tmpIntArr[1])
|
|
45
45
|
} else {
|
|
46
|
-
|
|
46
|
+
Logger.w("View.copyBoundsInWindow", "Can not copy bounds as view is not attached to window")
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
package com.reactnativekeyboardcontroller.listeners
|
|
2
2
|
|
|
3
3
|
import android.os.Build
|
|
4
|
-
import android.util.Log
|
|
5
4
|
import android.view.View
|
|
6
5
|
import android.view.ViewTreeObserver.OnGlobalFocusChangeListener
|
|
7
6
|
import androidx.core.graphics.Insets
|
|
@@ -21,6 +20,7 @@ import com.reactnativekeyboardcontroller.extensions.dp
|
|
|
21
20
|
import com.reactnativekeyboardcontroller.extensions.emitEvent
|
|
22
21
|
import com.reactnativekeyboardcontroller.extensions.isKeyboardAnimation
|
|
23
22
|
import com.reactnativekeyboardcontroller.interactive.InteractiveKeyboardProvider
|
|
23
|
+
import com.reactnativekeyboardcontroller.log.Logger
|
|
24
24
|
import kotlin.math.abs
|
|
25
25
|
|
|
26
26
|
private val TAG = KeyboardAnimationCallback::class.qualifiedName
|
|
@@ -137,7 +137,7 @@ class KeyboardAnimationCallback(
|
|
|
137
137
|
val isKeyboardSizeEqual = this.persistentKeyboardHeight == keyboardHeight
|
|
138
138
|
|
|
139
139
|
if (isKeyboardFullyVisible && !isKeyboardSizeEqual && !isResizeHandledInCallbackMethods) {
|
|
140
|
-
|
|
140
|
+
Logger.i(TAG, "onApplyWindowInsets: ${this.persistentKeyboardHeight} -> $keyboardHeight")
|
|
141
141
|
layoutObserver?.syncUpLayout()
|
|
142
142
|
this.onKeyboardResized(keyboardHeight)
|
|
143
143
|
}
|
|
@@ -182,7 +182,7 @@ class KeyboardAnimationCallback(
|
|
|
182
182
|
getEventParams(keyboardHeight),
|
|
183
183
|
)
|
|
184
184
|
|
|
185
|
-
|
|
185
|
+
Logger.i(TAG, "HEIGHT:: $keyboardHeight TAG:: $viewTagFocused")
|
|
186
186
|
context.dispatchEvent(
|
|
187
187
|
eventPropagationView.id,
|
|
188
188
|
KeyboardTransitionEvent(
|
|
@@ -229,9 +229,9 @@ class KeyboardAnimationCallback(
|
|
|
229
229
|
progress = abs((height / persistentKeyboardHeight)).let { if (it.isNaN()) 0.0 else it }
|
|
230
230
|
} catch (e: ArithmeticException) {
|
|
231
231
|
// do nothing, just log an exception send progress as 0
|
|
232
|
-
|
|
232
|
+
Logger.w(TAG, "Caught arithmetic exception during `progress` calculation: $e")
|
|
233
233
|
}
|
|
234
|
-
|
|
234
|
+
Logger.i(
|
|
235
235
|
TAG,
|
|
236
236
|
"DiffY: $diffY $height $progress ${InteractiveKeyboardProvider.isInteractive} $viewTagFocused",
|
|
237
237
|
)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
package com.reactnativekeyboardcontroller.log
|
|
2
|
+
|
|
3
|
+
import android.util.Log
|
|
4
|
+
import com.reactnativekeyboardcontroller.BuildConfig
|
|
5
|
+
|
|
6
|
+
object Logger {
|
|
7
|
+
private val enabled = BuildConfig.DEBUG
|
|
8
|
+
|
|
9
|
+
fun i(tag: String?, message: String, throwable: Throwable? = null) {
|
|
10
|
+
if (enabled) {
|
|
11
|
+
Log.i(tag, message, throwable)
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
fun w(tag: String?, message: String, throwable: Throwable? = null) {
|
|
16
|
+
if (enabled) {
|
|
17
|
+
Log.w(tag, message, throwable)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
package/android/src/main/java/com/reactnativekeyboardcontroller/modal/ModalAttachedWatcher.kt
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
package com.reactnativekeyboardcontroller.modal
|
|
2
2
|
|
|
3
|
-
import android.util.Log
|
|
4
3
|
import android.view.WindowManager
|
|
5
4
|
import androidx.core.view.ViewCompat
|
|
6
5
|
import com.facebook.react.uimanager.ThemedReactContext
|
|
@@ -13,6 +12,7 @@ import com.facebook.react.views.view.ReactViewGroup
|
|
|
13
12
|
import com.reactnativekeyboardcontroller.BuildConfig
|
|
14
13
|
import com.reactnativekeyboardcontroller.listeners.KeyboardAnimationCallback
|
|
15
14
|
import com.reactnativekeyboardcontroller.listeners.KeyboardAnimationCallbackConfig
|
|
15
|
+
import com.reactnativekeyboardcontroller.log.Logger
|
|
16
16
|
|
|
17
17
|
private val TAG = ModalAttachedWatcher::class.qualifiedName
|
|
18
18
|
|
|
@@ -33,7 +33,7 @@ class ModalAttachedWatcher(
|
|
|
33
33
|
val modal = try {
|
|
34
34
|
uiManager?.resolveView(event.viewTag) as? ReactModalHostView
|
|
35
35
|
} catch (ignore: Exception) {
|
|
36
|
-
|
|
36
|
+
Logger.w(TAG, "Can not resolve view for Modal#${event.viewTag}", ignore)
|
|
37
37
|
null
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -3,13 +3,13 @@ package com.reactnativekeyboardcontroller.modules
|
|
|
3
3
|
import android.animation.ArgbEvaluator
|
|
4
4
|
import android.animation.ValueAnimator
|
|
5
5
|
import android.os.Build
|
|
6
|
-
import android.util.Log
|
|
7
6
|
import androidx.annotation.RequiresApi
|
|
8
7
|
import androidx.core.view.WindowInsetsCompat
|
|
9
8
|
import androidx.core.view.WindowInsetsControllerCompat
|
|
10
9
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
11
10
|
import com.facebook.react.bridge.UiThreadUtil
|
|
12
11
|
import com.reactnativekeyboardcontroller.extensions.rootView
|
|
12
|
+
import com.reactnativekeyboardcontroller.log.Logger
|
|
13
13
|
import com.reactnativekeyboardcontroller.views.EdgeToEdgeReactViewGroup
|
|
14
14
|
|
|
15
15
|
private val TAG = StatusBarManagerCompatModuleImpl::class.qualifiedName
|
|
@@ -31,7 +31,7 @@ class StatusBarManagerCompatModuleImpl(private val mReactContext: ReactApplicati
|
|
|
31
31
|
fun setColor(color: Int, animated: Boolean) {
|
|
32
32
|
val activity = mReactContext.currentActivity
|
|
33
33
|
if (activity == null) {
|
|
34
|
-
|
|
34
|
+
Logger.w(TAG, "StatusBarManagerCompatModule: Ignored status bar change, current activity is null.")
|
|
35
35
|
return
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -69,7 +69,7 @@ class StatusBarManagerCompatModuleImpl(private val mReactContext: ReactApplicati
|
|
|
69
69
|
if (this.controller == null) {
|
|
70
70
|
val activity = mReactContext.currentActivity
|
|
71
71
|
if (activity == null) {
|
|
72
|
-
|
|
72
|
+
Logger.w(
|
|
73
73
|
TAG,
|
|
74
74
|
"StatusBarManagerCompatModule: can not get `WindowInsetsControllerCompat` because current activity is null.",
|
|
75
75
|
)
|
package/android/src/main/java/com/reactnativekeyboardcontroller/views/EdgeToEdgeReactViewGroup.kt
CHANGED
|
@@ -4,7 +4,6 @@ import android.annotation.SuppressLint
|
|
|
4
4
|
import android.content.res.Configuration
|
|
5
5
|
import android.os.Handler
|
|
6
6
|
import android.os.Looper
|
|
7
|
-
import android.util.Log
|
|
8
7
|
import android.widget.FrameLayout
|
|
9
8
|
import androidx.core.view.ViewCompat
|
|
10
9
|
import androidx.core.view.WindowCompat
|
|
@@ -19,6 +18,7 @@ import com.reactnativekeyboardcontroller.extensions.rootView
|
|
|
19
18
|
import com.reactnativekeyboardcontroller.extensions.setupWindowDimensionsListener
|
|
20
19
|
import com.reactnativekeyboardcontroller.listeners.KeyboardAnimationCallback
|
|
21
20
|
import com.reactnativekeyboardcontroller.listeners.KeyboardAnimationCallbackConfig
|
|
21
|
+
import com.reactnativekeyboardcontroller.log.Logger
|
|
22
22
|
import com.reactnativekeyboardcontroller.modal.ModalAttachedWatcher
|
|
23
23
|
|
|
24
24
|
private val TAG = EdgeToEdgeReactViewGroup::class.qualifiedName
|
|
@@ -149,7 +149,7 @@ class EdgeToEdgeReactViewGroup(private val reactContext: ThemedReactContext) : R
|
|
|
149
149
|
it.requestApplyInsetsWhenAttached()
|
|
150
150
|
}
|
|
151
151
|
} else {
|
|
152
|
-
|
|
152
|
+
Logger.w(TAG, "Can not setup keyboard animation listener, since `currentActivity` is null")
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
155
|
|
|
@@ -51,10 +51,11 @@ public extension Optional where Wrapped: UIResponder {
|
|
|
51
51
|
var currentResponder: UIResponder? = self
|
|
52
52
|
|
|
53
53
|
while let currentView = currentResponder {
|
|
54
|
-
// If the current responder is a vertical UIScrollView (excluding UITextView), return its tag
|
|
54
|
+
// If the current responder is a vertical, scrollable UIScrollView (excluding UITextView), return its tag
|
|
55
55
|
if let scrollView = currentView as? UIScrollView,
|
|
56
56
|
!(currentView is UITextView),
|
|
57
|
-
scrollView.frame.width >= scrollView.contentSize.width
|
|
57
|
+
scrollView.frame.width >= scrollView.contentSize.width,
|
|
58
|
+
scrollView.isScrollEnabled
|
|
58
59
|
// it was fixed in swiftlint https://github.com/realm/SwiftLint/issues/3756 but a new release is not available yet
|
|
59
60
|
// swiftlint:disable all
|
|
60
61
|
{
|
|
@@ -17,10 +17,18 @@ public extension UIView {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
public extension Optional where Wrapped == UIView {
|
|
20
|
-
var
|
|
20
|
+
var frameTransitionInWindow: (Double, Double) {
|
|
21
|
+
let areCrossFadeTransitionsEnabled = (self?.layer.presentation()?.animationKeys() ?? []).contains("opacity")
|
|
21
22
|
let frameY = self?.layer.presentation()?.frame.origin.y ?? 0
|
|
22
23
|
let windowH = self?.window?.bounds.size.height ?? 0
|
|
23
|
-
|
|
24
|
+
var position = windowH - frameY
|
|
25
|
+
|
|
26
|
+
// when cross fade transitions enabled, then keyboard changes
|
|
27
|
+
// its `opacity` instead of `translateY`, so we handle it here
|
|
28
|
+
if areCrossFadeTransitionsEnabled {
|
|
29
|
+
let opacity = self?.layer.presentation()?.opacity ?? 0
|
|
30
|
+
position = CGFloat(opacity) * position
|
|
31
|
+
}
|
|
24
32
|
|
|
25
33
|
return (position, frameY)
|
|
26
34
|
}
|
|
@@ -198,7 +198,7 @@ public class KeyboardMovementObserver: NSObject {
|
|
|
198
198
|
let timestamp = Date.currentTimeStamp
|
|
199
199
|
let (duration, frame) = metaDataFromNotification(notification)
|
|
200
200
|
if let keyboardFrame = frame {
|
|
201
|
-
let (position, _) = keyboardView.
|
|
201
|
+
let (position, _) = keyboardView.frameTransitionInWindow
|
|
202
202
|
let keyboardHeight = keyboardFrame.cgRectValue.size.height
|
|
203
203
|
tag = UIResponder.current.reactViewTag
|
|
204
204
|
self.keyboardHeight = keyboardHeight
|
|
@@ -249,12 +249,15 @@ public class KeyboardMovementObserver: NSObject {
|
|
|
249
249
|
}
|
|
250
250
|
|
|
251
251
|
func initializeAnimation(fromValue: Double, toValue: Double) {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
252
|
+
for key in ["position", "opacity"] {
|
|
253
|
+
if let keyboardAnimation = keyboardView?.layer.presentation()?.animation(forKey: key) {
|
|
254
|
+
if let springAnimation = keyboardAnimation as? CASpringAnimation {
|
|
255
|
+
animation = SpringAnimation(animation: springAnimation, fromValue: fromValue, toValue: toValue)
|
|
256
|
+
} else if let basicAnimation = keyboardAnimation as? CABasicAnimation {
|
|
257
|
+
animation = TimingAnimation(animation: basicAnimation, fromValue: fromValue, toValue: toValue)
|
|
258
|
+
}
|
|
259
|
+
return
|
|
260
|
+
}
|
|
258
261
|
}
|
|
259
262
|
}
|
|
260
263
|
|
|
@@ -263,7 +266,7 @@ public class KeyboardMovementObserver: NSObject {
|
|
|
263
266
|
return
|
|
264
267
|
}
|
|
265
268
|
|
|
266
|
-
let (visibleKeyboardHeight, keyboardFrameY) = keyboardView.
|
|
269
|
+
let (visibleKeyboardHeight, keyboardFrameY) = keyboardView.frameTransitionInWindow
|
|
267
270
|
var keyboardPosition = visibleKeyboardHeight
|
|
268
271
|
|
|
269
272
|
if keyboardPosition == prevKeyboardPosition || keyboardFrameY == 0 {
|
|
@@ -44,6 +44,12 @@ using namespace facebook::react;
|
|
|
44
44
|
return concreteComponentDescriptorProvider<KeyboardControllerViewComponentDescriptor>();
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
// Needed because of this: https://github.com/facebook/react-native/pull/37274
|
|
48
|
+
+ (void)load
|
|
49
|
+
{
|
|
50
|
+
[super load];
|
|
51
|
+
}
|
|
52
|
+
|
|
47
53
|
- (instancetype)initWithFrame:(CGRect)frame
|
|
48
54
|
{
|
|
49
55
|
if (self = [super initWithFrame:frame]) {
|
|
@@ -5,16 +5,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.useKeyboardAnimation = void 0;
|
|
7
7
|
var _reactNativeReanimated = require("react-native-reanimated");
|
|
8
|
-
var
|
|
8
|
+
var _context = require("../../context");
|
|
9
|
+
var _hooks = require("../../hooks");
|
|
9
10
|
const useKeyboardAnimation = () => {
|
|
10
11
|
const {
|
|
11
12
|
reanimated
|
|
12
|
-
} = (0,
|
|
13
|
+
} = (0, _context.useKeyboardContext)();
|
|
13
14
|
const heightWhenOpened = (0, _reactNativeReanimated.useSharedValue)(-reanimated.height.value);
|
|
14
15
|
const height = (0, _reactNativeReanimated.useSharedValue)(-reanimated.height.value);
|
|
15
16
|
const progress = (0, _reactNativeReanimated.useSharedValue)(reanimated.progress.value);
|
|
16
17
|
const isClosed = (0, _reactNativeReanimated.useSharedValue)(reanimated.progress.value === 0);
|
|
17
|
-
(0,
|
|
18
|
+
(0, _hooks.useKeyboardHandler)({
|
|
18
19
|
onStart: e => {
|
|
19
20
|
"worklet";
|
|
20
21
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNativeReanimated","require","
|
|
1
|
+
{"version":3,"names":["_reactNativeReanimated","require","_context","_hooks","useKeyboardAnimation","reanimated","useKeyboardContext","heightWhenOpened","useSharedValue","height","value","progress","isClosed","useKeyboardHandler","onStart","e","onMove","onEnd","exports"],"sources":["hooks.ts"],"sourcesContent":["import { useSharedValue } from \"react-native-reanimated\";\n\nimport { useKeyboardContext } from \"../../context\";\nimport { useKeyboardHandler } from \"../../hooks\";\n\nexport const useKeyboardAnimation = () => {\n const { reanimated } = useKeyboardContext();\n const heightWhenOpened = useSharedValue(-reanimated.height.value);\n const height = useSharedValue(-reanimated.height.value);\n const progress = useSharedValue(reanimated.progress.value);\n const isClosed = useSharedValue(reanimated.progress.value === 0);\n\n useKeyboardHandler(\n {\n onStart: (e) => {\n \"worklet\";\n\n if (e.height > 0) {\n // eslint-disable-next-line react-compiler/react-compiler\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 height.value = e.height;\n progress.value = e.progress;\n },\n },\n [],\n );\n\n return { height, progress, heightWhenOpened, isClosed };\n};\n"],"mappings":";;;;;;AAAA,IAAAA,sBAAA,GAAAC,OAAA;AAEA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAEO,MAAMG,oBAAoB,GAAGA,CAAA,KAAM;EACxC,MAAM;IAAEC;EAAW,CAAC,GAAG,IAAAC,2BAAkB,EAAC,CAAC;EAC3C,MAAMC,gBAAgB,GAAG,IAAAC,qCAAc,EAAC,CAACH,UAAU,CAACI,MAAM,CAACC,KAAK,CAAC;EACjE,MAAMD,MAAM,GAAG,IAAAD,qCAAc,EAAC,CAACH,UAAU,CAACI,MAAM,CAACC,KAAK,CAAC;EACvD,MAAMC,QAAQ,GAAG,IAAAH,qCAAc,EAACH,UAAU,CAACM,QAAQ,CAACD,KAAK,CAAC;EAC1D,MAAME,QAAQ,GAAG,IAAAJ,qCAAc,EAACH,UAAU,CAACM,QAAQ,CAACD,KAAK,KAAK,CAAC,CAAC;EAEhE,IAAAG,yBAAkB,EAChB;IACEC,OAAO,EAAGC,CAAC,IAAK;MACd,SAAS;;MAET,IAAIA,CAAC,CAACN,MAAM,GAAG,CAAC,EAAE;QAChB;QACAG,QAAQ,CAACF,KAAK,GAAG,KAAK;QACtBH,gBAAgB,CAACG,KAAK,GAAGK,CAAC,CAACN,MAAM;MACnC;IACF,CAAC;IACDO,MAAM,EAAGD,CAAC,IAAK;MACb,SAAS;;MAETJ,QAAQ,CAACD,KAAK,GAAGK,CAAC,CAACJ,QAAQ;MAC3BF,MAAM,CAACC,KAAK,GAAGK,CAAC,CAACN,MAAM;IACzB,CAAC;IACDQ,KAAK,EAAGF,CAAC,IAAK;MACZ,SAAS;;MAETH,QAAQ,CAACF,KAAK,GAAGK,CAAC,CAACN,MAAM,KAAK,CAAC;MAE/BA,MAAM,CAACC,KAAK,GAAGK,CAAC,CAACN,MAAM;MACvBE,QAAQ,CAACD,KAAK,GAAGK,CAAC,CAACJ,QAAQ;IAC7B;EACF,CAAC,EACD,EACF,CAAC;EAED,OAAO;IAAEF,MAAM;IAAEE,QAAQ;IAAEJ,gBAAgB;IAAEK;EAAS,CAAC;AACzD,CAAC;AAACM,OAAA,CAAAd,oBAAA,GAAAA,oBAAA","ignoreList":[]}
|
|
@@ -7,8 +7,8 @@ exports.default = void 0;
|
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _reactNative = require("react-native");
|
|
9
9
|
var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
|
|
10
|
-
var
|
|
11
|
-
var
|
|
10
|
+
var _hooks = require("../../hooks");
|
|
11
|
+
var _hooks2 = require("./hooks");
|
|
12
12
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
13
13
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
14
14
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
@@ -35,10 +35,10 @@ const KeyboardAvoidingView = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
35
35
|
}, ref) => {
|
|
36
36
|
const initialFrame = (0, _reactNativeReanimated.useSharedValue)(null);
|
|
37
37
|
const frame = (0, _reactNativeReanimated.useDerivedValue)(() => initialFrame.value || defaultLayout);
|
|
38
|
-
const keyboard = (0,
|
|
38
|
+
const keyboard = (0, _hooks2.useKeyboardAnimation)();
|
|
39
39
|
const {
|
|
40
40
|
height: screenHeight
|
|
41
|
-
} = (0,
|
|
41
|
+
} = (0, _hooks.useWindowDimensions)();
|
|
42
42
|
const relativeKeyboardHeight = (0, _react.useCallback)(() => {
|
|
43
43
|
"worklet";
|
|
44
44
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_reactNativeReanimated","
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_reactNativeReanimated","_hooks","_hooks2","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","_extends","assign","bind","arguments","length","apply","defaultLayout","x","y","width","height","KeyboardAvoidingView","forwardRef","behavior","children","contentContainerStyle","enabled","keyboardVerticalOffset","style","onLayout","onLayoutProps","props","ref","initialFrame","useSharedValue","frame","useDerivedValue","value","keyboard","useKeyboardAnimation","screenHeight","useWindowDimensions","relativeKeyboardHeight","useCallback","keyboardY","heightWhenOpened","Math","max","onLayoutWorklet","layout","isClosed","runOnUI","nativeEvent","animatedStyle","useAnimatedStyle","bottom","interpolate","progress","bottomHeight","flex","paddingBottom","isPositionBehavior","containerStyle","combinedStyles","useMemo","createElement","View","_default","exports"],"sources":["index.tsx"],"sourcesContent":["import React, { forwardRef, useCallback, useMemo } from \"react\";\nimport { View } from \"react-native\";\nimport Reanimated, {\n interpolate,\n runOnUI,\n useAnimatedStyle,\n useDerivedValue,\n useSharedValue,\n} from \"react-native-reanimated\";\n\nimport { useWindowDimensions } from \"../../hooks\";\n\nimport { useKeyboardAnimation } from \"./hooks\";\n\nimport type { LayoutRectangle, ViewProps } from \"react-native\";\n\nexport type KeyboardAvoidingViewProps = {\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<\n View,\n React.PropsWithChildren<KeyboardAvoidingViewProps>\n>(\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 = useCallback(() => {\n \"worklet\";\n\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 = useCallback((layout: LayoutRectangle) => {\n \"worklet\";\n\n if (keyboard.isClosed.value || initialFrame.value === null) {\n // eslint-disable-next-line react-compiler/react-compiler\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 ref={ref}\n style={combinedStyles}\n onLayout={onLayout}\n {...props}\n >\n {children}\n </Reanimated.View>\n );\n },\n);\n\nexport default KeyboardAvoidingView;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,sBAAA,GAAAH,uBAAA,CAAAC,OAAA;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AEE,aAAa,EAAEF;QAAa,CAAC;MAExC;QACE,OAAO,CAAC,CAAC;IACb;EACF,CAAC,EAAE,CAACnC,QAAQ,EAAEG,OAAO,EAAEgB,sBAAsB,CAAC,CAAC;EAC/C,MAAMmB,kBAAkB,GAAGtC,QAAQ,KAAK,UAAU;EAClD,MAAMuC,cAAc,GAAGD,kBAAkB,GAAGpC,qBAAqB,GAAGG,KAAK;EACzE,MAAMmC,cAAc,GAAG,IAAAC,cAAO,EAC5B,MAAM,CAACF,cAAc,EAAET,aAAa,CAAC,EACrC,CAACS,cAAc,EAAET,aAAa,CAChC,CAAC;EAED,IAAIQ,kBAAkB,EAAE;IACtB,oBACE9E,MAAA,CAAAa,OAAA,CAAAqE,aAAA,CAAC/E,YAAA,CAAAgF,IAAI,EAAAxD,QAAA;MAACsB,GAAG,EAAEA,GAAI;MAACJ,KAAK,EAAEA,KAAM;MAACC,QAAQ,EAAEA;IAAS,GAAKE,KAAK,gBACzDhD,MAAA,CAAAa,OAAA,CAAAqE,aAAA,CAAC9E,sBAAA,CAAAS,OAAU,CAACsE,IAAI;MAACtC,KAAK,EAAEmC;IAAe,GAAEvC,QAA0B,CAC/D,CAAC;EAEX;EAEA,oBACEzC,MAAA,CAAAa,OAAA,CAAAqE,aAAA,CAAC9E,sBAAA,CAAAS,OAAU,CAACsE,IAAI,EAAAxD,QAAA;IACdsB,GAAG,EAAEA,GAAI;IACTJ,KAAK,EAAEmC,cAAe;IACtBlC,QAAQ,EAAEA;EAAS,GACfE,KAAK,GAERP,QACc,CAAC;AAEtB,CACF,CAAC;AAAC,IAAA2C,QAAA,GAAAC,OAAA,CAAAxE,OAAA,GAEayB,oBAAoB","ignoreList":[]}
|
|
@@ -7,7 +7,7 @@ exports.default = void 0;
|
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _reactNative = require("react-native");
|
|
9
9
|
var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
|
|
10
|
-
var
|
|
10
|
+
var _hooks = require("../../hooks");
|
|
11
11
|
var _useSmoothKeyboardHandler = require("./useSmoothKeyboardHandler");
|
|
12
12
|
var _utils = require("./utils");
|
|
13
13
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
@@ -73,11 +73,11 @@ const KeyboardAwareScrollView = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
73
73
|
const scrollBeforeKeyboardMovement = (0, _reactNativeReanimated.useSharedValue)(0);
|
|
74
74
|
const {
|
|
75
75
|
input
|
|
76
|
-
} = (0,
|
|
76
|
+
} = (0, _hooks.useReanimatedFocusedInput)();
|
|
77
77
|
const layout = (0, _reactNativeReanimated.useSharedValue)(null);
|
|
78
78
|
const {
|
|
79
79
|
height
|
|
80
|
-
} = (0,
|
|
80
|
+
} = (0, _hooks.useWindowDimensions)();
|
|
81
81
|
const onRef = (0, _react.useCallback)(assignedRef => {
|
|
82
82
|
if (typeof ref === "function") {
|
|
83
83
|
ref(assignedRef);
|
|
@@ -166,7 +166,7 @@ const KeyboardAwareScrollView = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
166
166
|
}
|
|
167
167
|
}, [scrollFromCurrentPosition]);
|
|
168
168
|
const onChangeTextHandler = (0, _react.useMemo)(() => (0, _utils.debounce)(onChangeText, 200), [onChangeText]);
|
|
169
|
-
(0,
|
|
169
|
+
(0, _hooks.useFocusedInputHandler)({
|
|
170
170
|
onChangeText: onChangeTextHandler,
|
|
171
171
|
onSelectionChange: onSelectionChange
|
|
172
172
|
}, [onChangeTextHandler, onSelectionChange]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_reactNativeReanimated","_reactNativeKeyboardController","_useSmoothKeyboardHandler","_utils","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","_extends","assign","bind","arguments","length","apply","KeyboardAwareScrollView","forwardRef","children","onLayout","bottomOffset","disableScrollOnKeyboardHide","enabled","extraKeyboardSpace","snapToOffsets","rest","ref","scrollViewAnimatedRef","useAnimatedRef","scrollViewTarget","useSharedValue","scrollPosition","position","useScrollViewOffset","currentKeyboardFrameHeight","keyboardHeight","keyboardWillAppear","tag","initialKeyboardSize","scrollBeforeKeyboardMovement","input","useReanimatedFocusedInput","layout","height","useWindowDimensions","onRef","useCallback","assignedRef","current","onScrollViewLayout","value","findNodeHandle","maybeScroll","animated","_layout$value","_layout$value2","_layout$value3","parentScrollViewTarget","visibleRect","absoluteY","inputHeight","point","relativeScrollTo","interpolatedScrollTo","interpolate","scrollDistanceWithRespectToSnapPoints","targetScrollY","Math","max","scrollTo","positionOnScreen","topOfScreen","scrollFromCurrentPosition","customHeight","_input$value","prevScrollPosition","prevLayout","onChangeText","_layout$value4","_input$value2","onSelectionChange","selection","start","end","y","onChangeTextHandler","useMemo","debounce","useFocusedInputHandler","useSmoothKeyboardHandler","onStart","keyboardWillChangeSize","keyboardWillHide","focusWasChanged","target","onMove","keyboardFrame","onEnd","useAnimatedReaction","previous","view","useAnimatedStyle","paddingBottom","createElement","ScrollView","scrollEventThrottle","View","style","_default","exports"],"sources":["index.tsx"],"sourcesContent":["import React, { forwardRef, useCallback, useMemo } from \"react\";\nimport { findNodeHandle } from \"react-native\";\nimport Reanimated, {\n interpolate,\n scrollTo,\n useAnimatedReaction,\n useAnimatedRef,\n useAnimatedStyle,\n useScrollViewOffset,\n useSharedValue,\n} from \"react-native-reanimated\";\n\nimport {\n useFocusedInputHandler,\n useReanimatedFocusedInput,\n useWindowDimensions,\n} from \"react-native-keyboard-controller\";\n\nimport { useSmoothKeyboardHandler } from \"./useSmoothKeyboardHandler\";\nimport { debounce, scrollDistanceWithRespectToSnapPoints } from \"./utils\";\n\nimport type {\n LayoutChangeEvent,\n ScrollView,\n ScrollViewProps,\n} from \"react-native\";\nimport type {\n FocusedInputLayoutChangedEvent,\n FocusedInputSelectionChangedEvent,\n} from \"react-native-keyboard-controller\";\n\nexport type KeyboardAwareScrollViewProps = {\n /** The distance between keyboard and focused `TextInput` when keyboard is shown. Default is `0`. */\n bottomOffset?: number;\n /** Prevents automatic scrolling of the `ScrollView` when the keyboard gets hidden, maintaining the current screen position. Default is `false`. */\n disableScrollOnKeyboardHide?: boolean;\n /** Controls whether this `KeyboardAwareScrollView` instance should take effect. Default is `true` */\n enabled?: boolean;\n /** Adjusting the bottom spacing of KeyboardAwareScrollView. Default is `0` */\n extraKeyboardSpace?: number;\n} & ScrollViewProps;\n\n/*\n * Everything begins from `onStart` handler. This handler is called every time,\n * when keyboard changes its size or when focused `TextInput` was changed. In\n * this handler we are calculating/memoizing values which later will be used\n * during layout movement. For that we calculate:\n * - layout of focused field (`layout`) - to understand whether there will be overlap\n * - initial keyboard size (`initialKeyboardSize`) - used in scroll interpolation\n * - future keyboard height (`keyboardHeight`) - used in scroll interpolation\n * - current scroll position (`scrollPosition`) - used to scroll from this point\n *\n * Once we've calculated all necessary variables - we can actually start to use them.\n * It happens in `onMove` handler - this function simply calls `maybeScroll` with\n * current keyboard frame height. This functions makes the smooth transition.\n *\n * When the transition has finished we go to `onEnd` handler. In this handler\n * we verify, that the current field is not overlapped within a keyboard frame.\n * For full `onStart`/`onMove`/`onEnd` flow it may look like a redundant thing,\n * however there could be some cases, when `onMove` is not called:\n * - on iOS when TextInput was changed - keyboard transition is instant\n * - on Android when TextInput was changed and keyboard size wasn't changed\n * So `onEnd` handler handle the case, when `onMove` wasn't triggered.\n *\n * ====================================================================================================================+\n * -----------------------------------------------------Flow chart-----------------------------------------------------+\n * ====================================================================================================================+\n *\n * +============================+ +============================+ +==================================+\n * + User Press on TextInput + => + Keyboard starts showing + => + As keyboard moves frame by frame + =>\n * + + + (run `onStart`) + + `onMove` is getting called +\n * +============================+ +============================+ +==================================+\n *\n *\n * +============================+ +============================+ +=====================================+\n * + Keyboard is shown and we + => + User moved focus to + => + Only `onStart`/`onEnd` maybe called +\n * + call `onEnd` handler + + another `TextInput` + + (without involving `onMove`) +\n * +============================+ +============================+ +=====================================+\n *\n */\nconst KeyboardAwareScrollView = forwardRef<\n ScrollView,\n React.PropsWithChildren<KeyboardAwareScrollViewProps>\n>(\n (\n {\n children,\n onLayout,\n bottomOffset = 0,\n disableScrollOnKeyboardHide = false,\n enabled = true,\n extraKeyboardSpace = 0,\n snapToOffsets,\n ...rest\n },\n ref,\n ) => {\n const scrollViewAnimatedRef = useAnimatedRef<Reanimated.ScrollView>();\n const scrollViewTarget = useSharedValue<number | null>(null);\n const scrollPosition = useSharedValue(0);\n const position = useScrollViewOffset(scrollViewAnimatedRef);\n const currentKeyboardFrameHeight = useSharedValue(0);\n const keyboardHeight = useSharedValue(0);\n const keyboardWillAppear = useSharedValue(false);\n const tag = useSharedValue(-1);\n const initialKeyboardSize = useSharedValue(0);\n const scrollBeforeKeyboardMovement = useSharedValue(0);\n const { input } = useReanimatedFocusedInput();\n const layout = useSharedValue<FocusedInputLayoutChangedEvent | null>(null);\n\n const { height } = useWindowDimensions();\n\n const onRef = useCallback((assignedRef: Reanimated.ScrollView) => {\n if (typeof ref === \"function\") {\n ref(assignedRef);\n } else if (ref) {\n ref.current = assignedRef;\n }\n\n scrollViewAnimatedRef(assignedRef);\n }, []);\n const onScrollViewLayout = useCallback(\n (e: LayoutChangeEvent) => {\n scrollViewTarget.value = findNodeHandle(scrollViewAnimatedRef.current);\n\n onLayout?.(e);\n },\n [onLayout],\n );\n\n /**\n * Function that will scroll a ScrollView as keyboard gets moving\n */\n const maybeScroll = useCallback(\n (e: number, animated: boolean = false) => {\n \"worklet\";\n\n if (!enabled) {\n return 0;\n }\n\n // input belongs to ScrollView\n if (layout.value?.parentScrollViewTarget !== scrollViewTarget.value) {\n return 0;\n }\n\n const visibleRect = height - keyboardHeight.value;\n const absoluteY = layout.value?.layout.absoluteY || 0;\n const inputHeight = layout.value?.layout.height || 0;\n const point = absoluteY + inputHeight;\n\n if (visibleRect - point <= bottomOffset) {\n const relativeScrollTo =\n keyboardHeight.value - (height - point) + bottomOffset;\n const interpolatedScrollTo = interpolate(\n e,\n [initialKeyboardSize.value, keyboardHeight.value],\n [\n 0,\n scrollDistanceWithRespectToSnapPoints(\n relativeScrollTo + scrollPosition.value,\n snapToOffsets,\n ) - scrollPosition.value,\n ],\n );\n const targetScrollY =\n Math.max(interpolatedScrollTo, 0) + scrollPosition.value;\n\n scrollTo(scrollViewAnimatedRef, 0, targetScrollY, animated);\n\n return interpolatedScrollTo;\n }\n\n if (absoluteY < 0) {\n const positionOnScreen = visibleRect - inputHeight - bottomOffset;\n const topOfScreen = scrollPosition.value + absoluteY;\n\n scrollTo(\n scrollViewAnimatedRef,\n 0,\n topOfScreen - positionOnScreen,\n animated,\n );\n }\n\n return 0;\n },\n [bottomOffset, enabled, height, snapToOffsets],\n );\n\n const scrollFromCurrentPosition = useCallback(\n (customHeight?: number) => {\n \"worklet\";\n\n const prevScrollPosition = scrollPosition.value;\n const prevLayout = layout.value;\n\n if (!input.value?.layout) {\n return;\n }\n\n // eslint-disable-next-line react-compiler/react-compiler\n layout.value = {\n ...input.value,\n layout: {\n ...input.value.layout,\n height: customHeight ?? input.value.layout.height,\n },\n };\n scrollPosition.value = position.value;\n maybeScroll(keyboardHeight.value, true);\n scrollPosition.value = prevScrollPosition;\n layout.value = prevLayout;\n },\n [maybeScroll],\n );\n const onChangeText = useCallback(() => {\n \"worklet\";\n\n // if typing a text caused layout shift, then we need to ignore this handler\n // because this event will be handled in `useAnimatedReaction` below\n if (layout.value?.layout.height !== input.value?.layout.height) {\n return;\n }\n\n scrollFromCurrentPosition();\n }, [scrollFromCurrentPosition]);\n const onSelectionChange = useCallback(\n (e: FocusedInputSelectionChangedEvent) => {\n \"worklet\";\n\n if (e.selection.start.position !== e.selection.end.position) {\n scrollFromCurrentPosition(e.selection.end.y);\n }\n },\n [scrollFromCurrentPosition],\n );\n\n const onChangeTextHandler = useMemo(\n () => debounce(onChangeText, 200),\n [onChangeText],\n );\n\n useFocusedInputHandler(\n {\n onChangeText: onChangeTextHandler,\n onSelectionChange: onSelectionChange,\n },\n [onChangeTextHandler, onSelectionChange],\n );\n\n useSmoothKeyboardHandler(\n {\n onStart: (e) => {\n \"worklet\";\n\n const keyboardWillChangeSize =\n keyboardHeight.value !== e.height && e.height > 0;\n\n keyboardWillAppear.value = e.height > 0 && keyboardHeight.value === 0;\n\n const keyboardWillHide = e.height === 0;\n const focusWasChanged =\n (tag.value !== e.target && e.target !== -1) ||\n keyboardWillChangeSize;\n\n if (keyboardWillChangeSize) {\n initialKeyboardSize.value = keyboardHeight.value;\n }\n\n if (keyboardWillHide) {\n // on back transition need to interpolate as [0, keyboardHeight]\n initialKeyboardSize.value = 0;\n scrollPosition.value = scrollBeforeKeyboardMovement.value;\n }\n\n if (\n keyboardWillAppear.value ||\n keyboardWillChangeSize ||\n focusWasChanged\n ) {\n // persist scroll value\n scrollPosition.value = position.value;\n // just persist height - later will be used in interpolation\n keyboardHeight.value = e.height;\n }\n\n // focus was changed\n if (focusWasChanged) {\n tag.value = e.target;\n\n // save position of focused text input when keyboard starts to move\n layout.value = input.value;\n // save current scroll position - when keyboard will hide we'll reuse\n // this value to achieve smooth hide effect\n scrollBeforeKeyboardMovement.value = position.value;\n }\n\n if (focusWasChanged && !keyboardWillAppear.value) {\n // update position on scroll value, so `onEnd` handler\n // will pick up correct values\n position.value += maybeScroll(e.height, true);\n }\n },\n onMove: (e) => {\n \"worklet\";\n\n const keyboardFrame = interpolate(\n e.height,\n [0, keyboardHeight.value],\n [0, keyboardHeight.value + extraKeyboardSpace],\n );\n\n currentKeyboardFrameHeight.value = keyboardFrame;\n\n // if the user has set disableScrollOnKeyboardHide, only auto-scroll when the keyboard opens\n if (!disableScrollOnKeyboardHide || keyboardWillAppear.value) {\n maybeScroll(e.height);\n }\n },\n onEnd: (e) => {\n \"worklet\";\n\n keyboardHeight.value = e.height;\n scrollPosition.value = position.value;\n },\n },\n [maybeScroll, disableScrollOnKeyboardHide, extraKeyboardSpace],\n );\n\n useAnimatedReaction(\n () => input.value,\n (current, previous) => {\n if (\n current?.target === previous?.target &&\n current?.layout.height !== previous?.layout.height\n ) {\n const prevLayout = layout.value;\n\n layout.value = input.value;\n scrollPosition.value += maybeScroll(keyboardHeight.value, true);\n layout.value = prevLayout;\n }\n },\n [],\n );\n\n const view = useAnimatedStyle(\n () =>\n enabled\n ? {\n // animations become choppy when scrolling to the end of the `ScrollView` (when the last input is focused)\n // this happens because the layout recalculates on every frame. To avoid this we slightly increase padding\n // by `+1`. In this way we assure, that `scrollTo` will never scroll to the end, because it uses interpolation\n // from 0 to `keyboardHeight`, and here our padding is `keyboardHeight + 1`. It allows us not to re-run layout\n // re-calculation on every animation frame and it helps to achieve smooth animation.\n // see: https://github.com/kirillzyusko/react-native-keyboard-controller/pull/342\n paddingBottom: currentKeyboardFrameHeight.value + 1,\n }\n : {},\n [enabled],\n );\n\n return (\n <Reanimated.ScrollView\n ref={onRef}\n {...rest}\n scrollEventThrottle={16}\n onLayout={onScrollViewLayout}\n >\n {children}\n <Reanimated.View style={view} />\n </Reanimated.ScrollView>\n );\n },\n);\n\nexport default KeyboardAwareScrollView;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,sBAAA,GAAAH,uBAAA,CAAAC,OAAA;AAUA,IAAAG,8BAAA,GAAAH,OAAA;AAMA,IAAAI,yBAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA;AAA0E,SAAAM,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAR,wBAAAQ,CA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D,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAE8C,MAAM,OAAKK,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAEL,MAAM,KACpC,CAAA9C,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEN,MAAM,CAACC,MAAM,OAAKwD,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAEzD,MAAM,CAACC,MAAM,GAClD;MACA,MAAMiC,UAAU,GAAGlC,MAAM,CAACQ,KAAK;MAE/BR,MAAM,CAACQ,KAAK,GAAGV,KAAK,CAACU,KAAK;MAC1BnB,cAAc,CAACmB,KAAK,IAAIE,WAAW,CAACjB,cAAc,CAACe,KAAK,EAAE,IAAI,CAAC;MAC/DR,MAAM,CAACQ,KAAK,GAAG0B,UAAU;IAC3B;EACF,CAAC,EACD,EACF,CAAC;EAED,MAAMwB,IAAI,GAAG,IAAAC,uCAAgB,EAC3B,MACE/E,OAAO,GACH;IACE;IACA;IACA;IACA;IACA;IACA;IACAgF,aAAa,EAAEpE,0BAA0B,CAACgB,KAAK,GAAG;EACpD,CAAC,GACD,CAAC,CAAC,EACR,CAAC5B,OAAO,CACV,CAAC;EAED,oBACExC,MAAA,CAAAc,OAAA,CAAA2G,aAAA,CAACrH,sBAAA,CAAAU,OAAU,CAAC4G,UAAU,EAAA9F,QAAA;IACpBgB,GAAG,EAAEmB;EAAM,GACPpB,IAAI;IACRgF,mBAAmB,EAAE,EAAG;IACxBtF,QAAQ,EAAE8B;EAAmB,IAE5B/B,QAAQ,eACTpC,MAAA,CAAAc,OAAA,CAAA2G,aAAA,CAACrH,sBAAA,CAAAU,OAAU,CAAC8G,IAAI;IAACC,KAAK,EAAEP;EAAK,CAAE,CACV,CAAC;AAE5B,CACF,CAAC;AAAC,IAAAQ,QAAA,GAAAC,OAAA,CAAAjH,OAAA,GAEaoB,uBAAuB","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_reactNativeReanimated","_hooks","_useSmoothKeyboardHandler","_utils","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","_extends","assign","bind","arguments","length","apply","KeyboardAwareScrollView","forwardRef","children","onLayout","bottomOffset","disableScrollOnKeyboardHide","enabled","extraKeyboardSpace","snapToOffsets","rest","ref","scrollViewAnimatedRef","useAnimatedRef","scrollViewTarget","useSharedValue","scrollPosition","position","useScrollViewOffset","currentKeyboardFrameHeight","keyboardHeight","keyboardWillAppear","tag","initialKeyboardSize","scrollBeforeKeyboardMovement","input","useReanimatedFocusedInput","layout","height","useWindowDimensions","onRef","useCallback","assignedRef","current","onScrollViewLayout","value","findNodeHandle","maybeScroll","animated","_layout$value","_layout$value2","_layout$value3","parentScrollViewTarget","visibleRect","absoluteY","inputHeight","point","relativeScrollTo","interpolatedScrollTo","interpolate","scrollDistanceWithRespectToSnapPoints","targetScrollY","Math","max","scrollTo","positionOnScreen","topOfScreen","scrollFromCurrentPosition","customHeight","_input$value","prevScrollPosition","prevLayout","onChangeText","_layout$value4","_input$value2","onSelectionChange","selection","start","end","y","onChangeTextHandler","useMemo","debounce","useFocusedInputHandler","useSmoothKeyboardHandler","onStart","keyboardWillChangeSize","keyboardWillHide","focusWasChanged","target","onMove","keyboardFrame","onEnd","useAnimatedReaction","previous","view","useAnimatedStyle","paddingBottom","createElement","ScrollView","scrollEventThrottle","View","style","_default","exports"],"sources":["index.tsx"],"sourcesContent":["import React, { forwardRef, useCallback, useMemo } from \"react\";\nimport { findNodeHandle } from \"react-native\";\nimport Reanimated, {\n interpolate,\n scrollTo,\n useAnimatedReaction,\n useAnimatedRef,\n useAnimatedStyle,\n useScrollViewOffset,\n useSharedValue,\n} from \"react-native-reanimated\";\n\nimport {\n useFocusedInputHandler,\n useReanimatedFocusedInput,\n useWindowDimensions,\n} from \"../../hooks\";\n\nimport { useSmoothKeyboardHandler } from \"./useSmoothKeyboardHandler\";\nimport { debounce, scrollDistanceWithRespectToSnapPoints } from \"./utils\";\n\nimport type {\n LayoutChangeEvent,\n ScrollView,\n ScrollViewProps,\n} from \"react-native\";\nimport type {\n FocusedInputLayoutChangedEvent,\n FocusedInputSelectionChangedEvent,\n} from \"react-native-keyboard-controller\";\n\nexport type KeyboardAwareScrollViewProps = {\n /** The distance between keyboard and focused `TextInput` when keyboard is shown. Default is `0`. */\n bottomOffset?: number;\n /** Prevents automatic scrolling of the `ScrollView` when the keyboard gets hidden, maintaining the current screen position. Default is `false`. */\n disableScrollOnKeyboardHide?: boolean;\n /** Controls whether this `KeyboardAwareScrollView` instance should take effect. Default is `true` */\n enabled?: boolean;\n /** Adjusting the bottom spacing of KeyboardAwareScrollView. Default is `0` */\n extraKeyboardSpace?: number;\n} & ScrollViewProps;\n\n/*\n * Everything begins from `onStart` handler. This handler is called every time,\n * when keyboard changes its size or when focused `TextInput` was changed. In\n * this handler we are calculating/memoizing values which later will be used\n * during layout movement. For that we calculate:\n * - layout of focused field (`layout`) - to understand whether there will be overlap\n * - initial keyboard size (`initialKeyboardSize`) - used in scroll interpolation\n * - future keyboard height (`keyboardHeight`) - used in scroll interpolation\n * - current scroll position (`scrollPosition`) - used to scroll from this point\n *\n * Once we've calculated all necessary variables - we can actually start to use them.\n * It happens in `onMove` handler - this function simply calls `maybeScroll` with\n * current keyboard frame height. This functions makes the smooth transition.\n *\n * When the transition has finished we go to `onEnd` handler. In this handler\n * we verify, that the current field is not overlapped within a keyboard frame.\n * For full `onStart`/`onMove`/`onEnd` flow it may look like a redundant thing,\n * however there could be some cases, when `onMove` is not called:\n * - on iOS when TextInput was changed - keyboard transition is instant\n * - on Android when TextInput was changed and keyboard size wasn't changed\n * So `onEnd` handler handle the case, when `onMove` wasn't triggered.\n *\n * ====================================================================================================================+\n * -----------------------------------------------------Flow chart-----------------------------------------------------+\n * ====================================================================================================================+\n *\n * +============================+ +============================+ +==================================+\n * + User Press on TextInput + => + Keyboard starts showing + => + As keyboard moves frame by frame + =>\n * + + + (run `onStart`) + + `onMove` is getting called +\n * +============================+ +============================+ +==================================+\n *\n *\n * +============================+ +============================+ +=====================================+\n * + Keyboard is shown and we + => + User moved focus to + => + Only `onStart`/`onEnd` maybe called +\n * + call `onEnd` handler + + another `TextInput` + + (without involving `onMove`) +\n * +============================+ +============================+ +=====================================+\n *\n */\nconst KeyboardAwareScrollView = forwardRef<\n ScrollView,\n React.PropsWithChildren<KeyboardAwareScrollViewProps>\n>(\n (\n {\n children,\n onLayout,\n bottomOffset = 0,\n disableScrollOnKeyboardHide = false,\n enabled = true,\n extraKeyboardSpace = 0,\n snapToOffsets,\n ...rest\n },\n ref,\n ) => {\n const scrollViewAnimatedRef = useAnimatedRef<Reanimated.ScrollView>();\n const scrollViewTarget = useSharedValue<number | null>(null);\n const scrollPosition = useSharedValue(0);\n const position = useScrollViewOffset(scrollViewAnimatedRef);\n const currentKeyboardFrameHeight = useSharedValue(0);\n const keyboardHeight = useSharedValue(0);\n const keyboardWillAppear = useSharedValue(false);\n const tag = useSharedValue(-1);\n const initialKeyboardSize = useSharedValue(0);\n const scrollBeforeKeyboardMovement = useSharedValue(0);\n const { input } = useReanimatedFocusedInput();\n const layout = useSharedValue<FocusedInputLayoutChangedEvent | null>(null);\n\n const { height } = useWindowDimensions();\n\n const onRef = useCallback((assignedRef: Reanimated.ScrollView) => {\n if (typeof ref === \"function\") {\n ref(assignedRef);\n } else if (ref) {\n ref.current = assignedRef;\n }\n\n scrollViewAnimatedRef(assignedRef);\n }, []);\n const onScrollViewLayout = useCallback(\n (e: LayoutChangeEvent) => {\n scrollViewTarget.value = findNodeHandle(scrollViewAnimatedRef.current);\n\n onLayout?.(e);\n },\n [onLayout],\n );\n\n /**\n * Function that will scroll a ScrollView as keyboard gets moving\n */\n const maybeScroll = useCallback(\n (e: number, animated: boolean = false) => {\n \"worklet\";\n\n if (!enabled) {\n return 0;\n }\n\n // input belongs to ScrollView\n if (layout.value?.parentScrollViewTarget !== scrollViewTarget.value) {\n return 0;\n }\n\n const visibleRect = height - keyboardHeight.value;\n const absoluteY = layout.value?.layout.absoluteY || 0;\n const inputHeight = layout.value?.layout.height || 0;\n const point = absoluteY + inputHeight;\n\n if (visibleRect - point <= bottomOffset) {\n const relativeScrollTo =\n keyboardHeight.value - (height - point) + bottomOffset;\n const interpolatedScrollTo = interpolate(\n e,\n [initialKeyboardSize.value, keyboardHeight.value],\n [\n 0,\n scrollDistanceWithRespectToSnapPoints(\n relativeScrollTo + scrollPosition.value,\n snapToOffsets,\n ) - scrollPosition.value,\n ],\n );\n const targetScrollY =\n Math.max(interpolatedScrollTo, 0) + scrollPosition.value;\n\n scrollTo(scrollViewAnimatedRef, 0, targetScrollY, animated);\n\n return interpolatedScrollTo;\n }\n\n if (absoluteY < 0) {\n const positionOnScreen = visibleRect - inputHeight - bottomOffset;\n const topOfScreen = scrollPosition.value + absoluteY;\n\n scrollTo(\n scrollViewAnimatedRef,\n 0,\n topOfScreen - positionOnScreen,\n animated,\n );\n }\n\n return 0;\n },\n [bottomOffset, enabled, height, snapToOffsets],\n );\n\n const scrollFromCurrentPosition = useCallback(\n (customHeight?: number) => {\n \"worklet\";\n\n const prevScrollPosition = scrollPosition.value;\n const prevLayout = layout.value;\n\n if (!input.value?.layout) {\n return;\n }\n\n // eslint-disable-next-line react-compiler/react-compiler\n layout.value = {\n ...input.value,\n layout: {\n ...input.value.layout,\n height: customHeight ?? input.value.layout.height,\n },\n };\n scrollPosition.value = position.value;\n maybeScroll(keyboardHeight.value, true);\n scrollPosition.value = prevScrollPosition;\n layout.value = prevLayout;\n },\n [maybeScroll],\n );\n const onChangeText = useCallback(() => {\n \"worklet\";\n\n // if typing a text caused layout shift, then we need to ignore this handler\n // because this event will be handled in `useAnimatedReaction` below\n if (layout.value?.layout.height !== input.value?.layout.height) {\n return;\n }\n\n scrollFromCurrentPosition();\n }, [scrollFromCurrentPosition]);\n const onSelectionChange = useCallback(\n (e: FocusedInputSelectionChangedEvent) => {\n \"worklet\";\n\n if (e.selection.start.position !== e.selection.end.position) {\n scrollFromCurrentPosition(e.selection.end.y);\n }\n },\n [scrollFromCurrentPosition],\n );\n\n const onChangeTextHandler = useMemo(\n () => debounce(onChangeText, 200),\n [onChangeText],\n );\n\n useFocusedInputHandler(\n {\n onChangeText: onChangeTextHandler,\n onSelectionChange: onSelectionChange,\n },\n [onChangeTextHandler, onSelectionChange],\n );\n\n useSmoothKeyboardHandler(\n {\n onStart: (e) => {\n \"worklet\";\n\n const keyboardWillChangeSize =\n keyboardHeight.value !== e.height && e.height > 0;\n\n keyboardWillAppear.value = e.height > 0 && keyboardHeight.value === 0;\n\n const keyboardWillHide = e.height === 0;\n const focusWasChanged =\n (tag.value !== e.target && e.target !== -1) ||\n keyboardWillChangeSize;\n\n if (keyboardWillChangeSize) {\n initialKeyboardSize.value = keyboardHeight.value;\n }\n\n if (keyboardWillHide) {\n // on back transition need to interpolate as [0, keyboardHeight]\n initialKeyboardSize.value = 0;\n scrollPosition.value = scrollBeforeKeyboardMovement.value;\n }\n\n if (\n keyboardWillAppear.value ||\n keyboardWillChangeSize ||\n focusWasChanged\n ) {\n // persist scroll value\n scrollPosition.value = position.value;\n // just persist height - later will be used in interpolation\n keyboardHeight.value = e.height;\n }\n\n // focus was changed\n if (focusWasChanged) {\n tag.value = e.target;\n\n // save position of focused text input when keyboard starts to move\n layout.value = input.value;\n // save current scroll position - when keyboard will hide we'll reuse\n // this value to achieve smooth hide effect\n scrollBeforeKeyboardMovement.value = position.value;\n }\n\n if (focusWasChanged && !keyboardWillAppear.value) {\n // update position on scroll value, so `onEnd` handler\n // will pick up correct values\n position.value += maybeScroll(e.height, true);\n }\n },\n onMove: (e) => {\n \"worklet\";\n\n const keyboardFrame = interpolate(\n e.height,\n [0, keyboardHeight.value],\n [0, keyboardHeight.value + extraKeyboardSpace],\n );\n\n currentKeyboardFrameHeight.value = keyboardFrame;\n\n // if the user has set disableScrollOnKeyboardHide, only auto-scroll when the keyboard opens\n if (!disableScrollOnKeyboardHide || keyboardWillAppear.value) {\n maybeScroll(e.height);\n }\n },\n onEnd: (e) => {\n \"worklet\";\n\n keyboardHeight.value = e.height;\n scrollPosition.value = position.value;\n },\n },\n [maybeScroll, disableScrollOnKeyboardHide, extraKeyboardSpace],\n );\n\n useAnimatedReaction(\n () => input.value,\n (current, previous) => {\n if (\n current?.target === previous?.target &&\n current?.layout.height !== previous?.layout.height\n ) {\n const prevLayout = layout.value;\n\n layout.value = input.value;\n scrollPosition.value += maybeScroll(keyboardHeight.value, true);\n layout.value = prevLayout;\n }\n },\n [],\n );\n\n const view = useAnimatedStyle(\n () =>\n enabled\n ? {\n // animations become choppy when scrolling to the end of the `ScrollView` (when the last input is focused)\n // this happens because the layout recalculates on every frame. To avoid this we slightly increase padding\n // by `+1`. In this way we assure, that `scrollTo` will never scroll to the end, because it uses interpolation\n // from 0 to `keyboardHeight`, and here our padding is `keyboardHeight + 1`. It allows us not to re-run layout\n // re-calculation on every animation frame and it helps to achieve smooth animation.\n // see: https://github.com/kirillzyusko/react-native-keyboard-controller/pull/342\n paddingBottom: currentKeyboardFrameHeight.value + 1,\n }\n : {},\n [enabled],\n );\n\n return (\n <Reanimated.ScrollView\n ref={onRef}\n {...rest}\n scrollEventThrottle={16}\n onLayout={onScrollViewLayout}\n >\n {children}\n <Reanimated.View style={view} />\n </Reanimated.ScrollView>\n );\n },\n);\n\nexport default KeyboardAwareScrollView;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,sBAAA,GAAAH,uBAAA,CAAAC,OAAA;AAUA,IAAAG,MAAA,GAAAH,OAAA;AAMA,IAAAI,yBAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA;AAA0E,SAAAM,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAA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uB","ignoreList":[]}
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.useSmoothKeyboardHandler = void 0;
|
|
7
7
|
var _reactNative = require("react-native");
|
|
8
8
|
var _reactNativeReanimated = require("react-native-reanimated");
|
|
9
|
-
var
|
|
9
|
+
var _hooks = require("../../hooks");
|
|
10
10
|
const IS_ANDROID_ELEVEN_OR_HIGHER = _reactNative.Platform.OS === "android" && _reactNative.Platform.Version >= 30;
|
|
11
11
|
// on these platforms keyboard transitions will be smooth
|
|
12
12
|
const IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS = IS_ANDROID_ELEVEN_OR_HIGHER || _reactNative.Platform.OS === "ios";
|
|
@@ -59,7 +59,7 @@ const useSmoothKeyboardHandler = (handler, deps) => {
|
|
|
59
59
|
},
|
|
60
60
|
// REA uses own version of `DependencyList` and it's not compatible with the same type from React
|
|
61
61
|
deps);
|
|
62
|
-
(0,
|
|
62
|
+
(0, _hooks.useKeyboardHandler)({
|
|
63
63
|
onStart: e => {
|
|
64
64
|
"worklet";
|
|
65
65
|
|