react-native-keyboard-controller 1.12.4 → 1.12.6

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.
@@ -3,6 +3,7 @@ package com.reactnativekeyboardcontroller.extensions
3
3
  import android.util.Log
4
4
  import android.view.View
5
5
  import android.view.ViewGroup
6
+ import com.facebook.react.bridge.ReactContext
6
7
  import com.facebook.react.bridge.WritableMap
7
8
  import com.facebook.react.modules.core.DeviceEventManagerModule
8
9
  import com.facebook.react.uimanager.ThemedReactContext
@@ -25,7 +26,7 @@ fun ThemedReactContext.setupWindowDimensionsListener() {
25
26
 
26
27
  fun ThemedReactContext?.dispatchEvent(viewId: Int, event: Event<*>) {
27
28
  val eventDispatcher: EventDispatcher? =
28
- UIManagerHelper.getEventDispatcherForReactTag(this, viewId)
29
+ UIManagerHelper.getEventDispatcherForReactTag(this as ReactContext, viewId)
29
30
  eventDispatcher?.dispatchEvent(event)
30
31
  }
31
32
 
@@ -14,11 +14,11 @@ class WindowDimensionListener(private val context: ThemedReactContext?) {
14
14
  private var lastDispatchedDimensions = Dimensions(0.0, 0.0)
15
15
 
16
16
  init {
17
- // attach to content view only once
18
- if (!isListenerAttached) {
19
- isListenerAttached = true
17
+ // attach to content view only once per app instance
18
+ if (context != null && listenerID != context.hashCode()) {
19
+ listenerID = context.hashCode()
20
20
 
21
- val content = context?.content
21
+ val content = context.content
22
22
 
23
23
  updateWindowDimensions(content)
24
24
 
@@ -52,6 +52,6 @@ class WindowDimensionListener(private val context: ThemedReactContext?) {
52
52
  }
53
53
 
54
54
  companion object {
55
- private var isListenerAttached = false
55
+ private var listenerID = -1
56
56
  }
57
57
  }
@@ -74,10 +74,7 @@ RCT_EXPORT_METHOD(dismiss)
74
74
  #endif
75
75
  {
76
76
  dispatch_async(dispatch_get_main_queue(), ^{
77
- [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder)
78
- to:nil
79
- from:nil
80
- forEvent:nil];
77
+ [[UIResponder current] resignFirstResponder];
81
78
  });
82
79
  }
83
80
 
@@ -7,35 +7,36 @@
7
7
 
8
8
  import Foundation
9
9
 
10
- struct Selection {
11
- var start: Int
12
- var startX: CGFloat
13
- var startY: CGFloat
14
- var end: Int
15
- var endX: CGFloat
16
- var endY: CGFloat
17
- }
18
-
19
- func textSelection(in textInput: UITextInput) -> Selection? {
10
+ func textSelection(in textInput: UITextInput) -> NSDictionary? {
20
11
  if let selectedRange = textInput.selectedTextRange {
21
12
  let caretRectStart = textInput.caretRect(for: selectedRange.start)
22
13
  let caretRectEnd = textInput.caretRect(for: selectedRange.end)
23
14
 
24
- let coordinates = Selection(
25
- start: textInput.offset(from: textInput.beginningOfDocument, to: selectedRange.start),
26
- startX: caretRectStart.origin.x,
27
- startY: caretRectStart.origin.y,
28
- end: textInput.offset(from: textInput.beginningOfDocument, to: selectedRange.end),
29
- endX: caretRectEnd.origin.x + caretRectEnd.size.width,
30
- endY: caretRectEnd.origin.y + caretRectEnd.size.height
31
- )
32
-
33
- return coordinates
15
+ return [
16
+ "selection": [
17
+ "start": [
18
+ "x": caretRectStart.origin.x,
19
+ "y": caretRectStart.origin.y,
20
+ "position": textInput.offset(from: textInput.beginningOfDocument, to: selectedRange.start),
21
+ ],
22
+ "end": [
23
+ "x": caretRectEnd.origin.x + caretRectEnd.size.width,
24
+ "y": caretRectEnd.origin.y + caretRectEnd.size.height,
25
+ "position": textInput.offset(from: textInput.beginningOfDocument, to: selectedRange.end),
26
+ ],
27
+ ],
28
+ ]
34
29
  }
35
30
 
36
31
  return nil
37
32
  }
38
33
 
34
+ func updateSelectionPosition(textInput: UITextInput, sendEvent: (_ event: NSDictionary) -> Void) {
35
+ if let selection = textSelection(in: textInput) {
36
+ sendEvent(selection)
37
+ }
38
+ }
39
+
39
40
  /**
40
41
  * A delegate that is being set to any focused input
41
42
  * and intercepts some specific events that needs to be handled
@@ -79,7 +80,15 @@ class KCTextInputCompositeDelegate: NSObject, UITextViewDelegate, UITextFieldDel
79
80
 
80
81
  func textViewDidChangeSelection(_ textView: UITextView) {
81
82
  textViewDelegate?.textViewDidChangeSelection?(textView)
82
- updateSelectionPosition(textInput: textView)
83
+ if textView.canSelectionFitIntoLayout {
84
+ updateSelectionPosition(textInput: textView, sendEvent: onSelectionChange)
85
+ } else {
86
+ // when multiline input grows we need to wait for layout to be updated
87
+ // otherwise start/end positions will be incorrect (0/-1)
88
+ DispatchQueue.main.asyncAfter(deadline: .now() + UIUtils.nextFrame) {
89
+ updateSelectionPosition(textInput: textView, sendEvent: self.onSelectionChange)
90
+ }
91
+ }
83
92
  }
84
93
 
85
94
  func textViewDidChange(_ textView: UITextView) {
@@ -95,7 +104,7 @@ class KCTextInputCompositeDelegate: NSObject, UITextViewDelegate, UITextFieldDel
95
104
  @available(iOS 13.0, *)
96
105
  func textFieldDidChangeSelection(_ textField: UITextField) {
97
106
  textFieldDelegate?.textFieldDidChangeSelection?(textField)
98
- updateSelectionPosition(textInput: textField)
107
+ updateSelectionPosition(textInput: textField, sendEvent: onSelectionChange)
99
108
  }
100
109
 
101
110
  func textField(
@@ -125,25 +134,4 @@ class KCTextInputCompositeDelegate: NSObject, UITextViewDelegate, UITextFieldDel
125
134
  }
126
135
  return super.forwardingTarget(for: aSelector)
127
136
  }
128
-
129
- // MARK: Private functions
130
-
131
- private func updateSelectionPosition(textInput: UITextInput) {
132
- if let selection = textSelection(in: textInput) {
133
- onSelectionChange([
134
- "selection": [
135
- "start": [
136
- "x": selection.startX,
137
- "y": selection.startY,
138
- "position": selection.start,
139
- ],
140
- "end": [
141
- "x": selection.endX,
142
- "y": selection.endY,
143
- "position": selection.end,
144
- ],
145
- ],
146
- ])
147
- }
148
- }
149
137
  }
@@ -0,0 +1,23 @@
1
+ //
2
+ // CGFloat.swift
3
+ // KeyboardController
4
+ //
5
+ // Created by Kiryl Ziusko on 04/07/2024.
6
+ // Copyright © 2024 Facebook. All rights reserved.
7
+ //
8
+
9
+ import Foundation
10
+
11
+ public extension CGFloat {
12
+ static func interpolate(inputRange: [CGFloat], outputRange: [CGFloat], currentValue: CGFloat) -> CGFloat {
13
+ let inputMin = inputRange.min() ?? 0
14
+ let inputMax = inputRange.max() ?? 1
15
+ let outputMin = outputRange.min() ?? 0
16
+ let outputMax = outputRange.max() ?? 1
17
+
18
+ let normalizedValue = (currentValue - inputMin) / (inputMax - inputMin)
19
+ let interpolatedValue = outputMin + (outputMax - outputMin) * normalizedValue
20
+
21
+ return interpolatedValue
22
+ }
23
+ }
@@ -0,0 +1,15 @@
1
+ //
2
+ // Date.swift
3
+ // KeyboardController
4
+ //
5
+ // Created by Kiryl Ziusko on 04/07/2024.
6
+ // Copyright © 2024 Facebook. All rights reserved.
7
+ //
8
+
9
+ import Foundation
10
+
11
+ public extension Date {
12
+ static var currentTimeStamp: Int64 {
13
+ return Int64(Date().timeIntervalSince1970 * 1000)
14
+ }
15
+ }
@@ -1,34 +1,15 @@
1
1
  //
2
- // Extensions.swift
2
+ // UIResponder.swift
3
3
  // KeyboardController
4
4
  //
5
- // Created by Kiryl Ziusko on 10/06/2023.
6
- // Copyright © 2023 Facebook. All rights reserved.
5
+ // Created by Kiryl Ziusko on 04/07/2024.
6
+ // Copyright © 2024 Facebook. All rights reserved.
7
7
  //
8
8
 
9
9
  import Foundation
10
10
  import UIKit
11
11
 
12
- public extension CGFloat {
13
- static func interpolate(inputRange: [CGFloat], outputRange: [CGFloat], currentValue: CGFloat) -> CGFloat {
14
- let inputMin = inputRange.min() ?? 0
15
- let inputMax = inputRange.max() ?? 1
16
- let outputMin = outputRange.min() ?? 0
17
- let outputMax = outputRange.max() ?? 1
18
-
19
- let normalizedValue = (currentValue - inputMin) / (inputMax - inputMin)
20
- let interpolatedValue = outputMin + (outputMax - outputMin) * normalizedValue
21
-
22
- return interpolatedValue
23
- }
24
- }
25
-
26
- public extension Date {
27
- static var currentTimeStamp: Int64 {
28
- return Int64(Date().timeIntervalSince1970 * 1000)
29
- }
30
- }
31
-
12
+ @objc
32
13
  public extension UIResponder {
33
14
  private weak static var _currentFirstResponder: UIResponder?
34
15
 
@@ -38,8 +19,20 @@ public extension UIResponder {
38
19
  return UIResponder._currentFirstResponder
39
20
  }
40
21
 
41
- @objc internal func findFirstResponder(sender _: AnyObject) {
42
- UIResponder._currentFirstResponder = self
22
+ internal func findFirstResponder(sender _: AnyObject) {
23
+ let type = String(describing: type(of: self))
24
+ // handle `contextMenuHidden` prop - in this case the parent is considered as a first responder
25
+ // (but actually its children is an actual input), so we apply correction here and point out
26
+ // to the actual first responder (first children)
27
+ let isChildrenActuallyFirstResponder =
28
+ type == "RCTMultilineTextInputView" ||
29
+ type == "RCTSinglelineTextInputView" ||
30
+ type == "RCTTextInputComponentView"
31
+ if isChildrenActuallyFirstResponder {
32
+ UIResponder._currentFirstResponder = (self as? UIView)?.subviews[0]
33
+ } else {
34
+ UIResponder._currentFirstResponder = self
35
+ }
43
36
  }
44
37
  }
45
38
 
@@ -53,16 +46,6 @@ public extension Optional where Wrapped == UIResponder {
53
46
  }
54
47
  }
55
48
 
56
- public extension UIScrollView {
57
- var reactViewTag: NSNumber {
58
- #if KEYBOARD_CONTROLLER_NEW_ARCH_ENABLED
59
- return (superview?.tag ?? -1) as NSNumber
60
- #else
61
- return superview?.reactTag ?? -1
62
- #endif
63
- }
64
- }
65
-
66
49
  public extension Optional where Wrapped: UIResponder {
67
50
  var parentScrollViewTarget: NSNumber {
68
51
  var currentResponder: UIResponder? = self
@@ -87,10 +70,3 @@ public extension Optional where Wrapped: UIResponder {
87
70
  return -1
88
71
  }
89
72
  }
90
-
91
- public extension UIView {
92
- var globalFrame: CGRect? {
93
- let rootView = UIApplication.shared.keyWindow?.rootViewController?.view
94
- return superview?.convert(frame, to: rootView)
95
- }
96
- }
@@ -0,0 +1,20 @@
1
+ //
2
+ // UIScrollView.swift
3
+ // KeyboardController
4
+ //
5
+ // Created by Kiryl Ziusko on 04/07/2024.
6
+ // Copyright © 2024 Facebook. All rights reserved.
7
+ //
8
+
9
+ import Foundation
10
+ import UIKit
11
+
12
+ public extension UIScrollView {
13
+ var reactViewTag: NSNumber {
14
+ #if KEYBOARD_CONTROLLER_NEW_ARCH_ENABLED
15
+ return (superview?.tag ?? -1) as NSNumber
16
+ #else
17
+ return superview?.reactTag ?? -1
18
+ #endif
19
+ }
20
+ }
@@ -0,0 +1,21 @@
1
+ //
2
+ // UITextInput.swift
3
+ // KeyboardController
4
+ //
5
+ // Created by Kiryl Ziusko on 04/07/2024.
6
+ // Copyright © 2024 Facebook. All rights reserved.
7
+ //
8
+
9
+ import Foundation
10
+ import UIKit
11
+
12
+ public extension UITextInput {
13
+ var canSelectionFitIntoLayout: Bool {
14
+ guard let selectedRange = selectedTextRange else { return false }
15
+
16
+ guard let range = textRange(from: selectedRange.start, to: selectedRange.end) else { return false }
17
+ let rect = firstRect(for: range)
18
+
19
+ return rect.origin.x.isFinite && rect.origin.y.isFinite
20
+ }
21
+ }
@@ -0,0 +1,17 @@
1
+ //
2
+ // UIView.swift
3
+ // KeyboardController
4
+ //
5
+ // Created by Kiryl Ziusko on 04/07/2024.
6
+ // Copyright © 2024 Facebook. All rights reserved.
7
+ //
8
+
9
+ import Foundation
10
+ import UIKit
11
+
12
+ public extension UIView {
13
+ var globalFrame: CGRect? {
14
+ let rootView = UIApplication.shared.keyWindow?.rootViewController?.view
15
+ return superview?.convert(frame, to: rootView)
16
+ }
17
+ }
@@ -197,6 +197,10 @@ public class FocusedInputObserver: NSObject {
197
197
  (textView as? RCTUITextView)?.setForceDelegate(delegate)
198
198
  }
199
199
  }
200
+ // dispatch onSelectionChange on focus
201
+ if let textInput = input as? UITextInput {
202
+ updateSelectionPosition(textInput: textInput, sendEvent: onSelectionChange)
203
+ }
200
204
  }
201
205
 
202
206
  private func substituteDelegateBack(_ input: UIResponder?) {
@@ -57,14 +57,13 @@ const KeyboardAwareScrollView = /*#__PURE__*/(0, _react.forwardRef)(({
57
57
  bottomOffset = 0,
58
58
  disableScrollOnKeyboardHide = false,
59
59
  enabled = true,
60
- onScroll: onScrollProps,
61
60
  extraKeyboardSpace = 0,
62
61
  ...rest
63
62
  }, ref) => {
64
63
  const scrollViewAnimatedRef = (0, _reactNativeReanimated.useAnimatedRef)();
65
64
  const scrollViewTarget = (0, _reactNativeReanimated.useSharedValue)(null);
66
65
  const scrollPosition = (0, _reactNativeReanimated.useSharedValue)(0);
67
- const position = (0, _reactNativeReanimated.useSharedValue)(0);
66
+ const position = (0, _reactNativeReanimated.useScrollViewOffset)(scrollViewAnimatedRef);
68
67
  const currentKeyboardFrameHeight = (0, _reactNativeReanimated.useSharedValue)(0);
69
68
  const keyboardHeight = (0, _reactNativeReanimated.useSharedValue)(0);
70
69
  const keyboardWillAppear = (0, _reactNativeReanimated.useSharedValue)(false);
@@ -78,10 +77,6 @@ const KeyboardAwareScrollView = /*#__PURE__*/(0, _react.forwardRef)(({
78
77
  const {
79
78
  height
80
79
  } = (0, _reactNativeKeyboardController.useWindowDimensions)();
81
- const onScroll = (0, _react.useCallback)(event => {
82
- position.value = event.nativeEvent.contentOffset.y;
83
- onScrollProps === null || onScrollProps === void 0 || onScrollProps(event);
84
- }, [onScrollProps]);
85
80
  const onRef = (0, _react.useCallback)(assignedRef => {
86
81
  if (typeof ref === "function") {
87
82
  ref(assignedRef);
@@ -127,7 +122,7 @@ const KeyboardAwareScrollView = /*#__PURE__*/(0, _react.forwardRef)(({
127
122
  (0, _reactNativeReanimated.scrollTo)(scrollViewAnimatedRef, 0, topOfScreen - positionOnScreen, animated);
128
123
  }
129
124
  return 0;
130
- }, [bottomOffset, enabled, rest.snapToOffsets]);
125
+ }, [bottomOffset, enabled, height, rest.snapToOffsets]);
131
126
  const onChangeText = (0, _react.useCallback)(() => {
132
127
  "worklet";
133
128
 
@@ -205,7 +200,7 @@ const KeyboardAwareScrollView = /*#__PURE__*/(0, _react.forwardRef)(({
205
200
  keyboardHeight.value = e.height;
206
201
  scrollPosition.value = position.value;
207
202
  }
208
- }, [height, maybeScroll, disableScrollOnKeyboardHide, extraKeyboardSpace]);
203
+ }, [maybeScroll, disableScrollOnKeyboardHide, extraKeyboardSpace]);
209
204
  (0, _reactNativeReanimated.useAnimatedReaction)(() => input.value, (current, previous) => {
210
205
  if ((current === null || current === void 0 ? void 0 : current.target) === (previous === null || previous === void 0 ? void 0 : previous.target) && (current === null || current === void 0 ? void 0 : current.layout.height) !== (previous === null || previous === void 0 ? void 0 : previous.layout.height)) {
211
206
  const prevLayout = layout.value;
@@ -227,7 +222,6 @@ const KeyboardAwareScrollView = /*#__PURE__*/(0, _react.forwardRef)(({
227
222
  ref: onRef
228
223
  }, rest, {
229
224
  onLayout: onScrollViewLayout,
230
- onScroll: onScroll,
231
225
  scrollEventThrottle: 16
232
226
  }), children, /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.View, {
233
227
  style: view
@@ -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","prototype","hasOwnProperty","call","i","set","_extends","assign","bind","target","arguments","length","source","key","apply","KeyboardAwareScrollView","forwardRef","children","onLayout","bottomOffset","disableScrollOnKeyboardHide","enabled","onScroll","onScrollProps","extraKeyboardSpace","rest","ref","scrollViewAnimatedRef","useAnimatedRef","scrollViewTarget","useSharedValue","scrollPosition","position","currentKeyboardFrameHeight","keyboardHeight","keyboardWillAppear","tag","initialKeyboardSize","scrollBeforeKeyboardMovement","input","useReanimatedFocusedInput","layout","height","useWindowDimensions","useCallback","event","value","nativeEvent","contentOffset","y","onRef","assignedRef","current","onScrollViewLayout","findNodeHandle","maybeScroll","animated","_layout$value","_layout$value2","_layout$value3","parentScrollViewTarget","visibleRect","absoluteY","inputHeight","point","relativeScrollTo","interpolatedScrollTo","interpolate","scrollDistanceWithRespectToSnapPoints","snapToOffsets","targetScrollY","Math","max","scrollTo","positionOnScreen","topOfScreen","onChangeText","_layout$value4","_input$value","prevScrollPosition","prevLayout","onChangeTextHandler","useMemo","debounce","useFocusedInputHandler","useSmoothKeyboardHandler","onStart","keyboardWillChangeSize","keyboardWillHide","focusWasChanged","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 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 { FocusedInputLayoutChangedEvent } 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 onScroll: onScrollProps,\n extraKeyboardSpace = 0,\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 = useSharedValue(0);\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 onScroll = useCallback<NonNullable<ScrollViewProps[\"onScroll\"]>>(\n (event) => {\n position.value = event.nativeEvent.contentOffset.y;\n\n onScrollProps?.(event);\n },\n [onScrollProps],\n );\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 rest.snapToOffsets,\n ) - scrollPosition.value,\n ],\n );\n const targetScrollY =\n Math.max(interpolatedScrollTo, 0) + scrollPosition.value;\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, rest.snapToOffsets],\n );\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 const prevScrollPosition = scrollPosition.value;\n const prevLayout = layout.value;\n\n scrollPosition.value = position.value;\n layout.value = input.value;\n maybeScroll(keyboardHeight.value, true);\n scrollPosition.value = prevScrollPosition;\n layout.value = prevLayout;\n }, [maybeScroll]);\n\n const onChangeTextHandler = useMemo(\n () => debounce(onChangeText, 200),\n [onChangeText],\n );\n\n useFocusedInputHandler(\n {\n onChangeText: onChangeTextHandler,\n },\n [onChangeTextHandler],\n );\n\n useSmoothKeyboardHandler(\n {\n onStart: (e) => {\n \"worklet\";\n\n const keyboardWillChangeSize =\n keyboardHeight.value !== e.height && e.height > 0;\n keyboardWillAppear.value = e.height > 0 && keyboardHeight.value === 0;\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 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 [height, 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 onLayout={onScrollViewLayout}\n onScroll={onScroll}\n scrollEventThrottle={16}\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,sBA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CAACC,MAAM,OAAKoD,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAErD,MAAM,CAACC,MAAM,GAClD;MACA,MAAMsC,UAAU,GAAGvC,MAAM,CAACK,KAAK;MAE/BL,MAAM,CAACK,KAAK,GAAGP,KAAK,CAACO,KAAK;MAC1Bf,cAAc,CAACe,KAAK,IAAIS,WAAW,CAACrB,cAAc,CAACY,KAAK,EAAE,IAAI,CAAC;MAC/DL,MAAM,CAACK,KAAK,GAAGkC,UAAU;IAC3B;EACF,CAAC,EACD,EACF,CAAC;EAED,MAAMe,IAAI,GAAG,IAAAC,uCAAgB,EAC3B,MACE3E,OAAO,GACH;IACE;IACA;IACA;IACA;IACA;IACA;IACA4E,aAAa,EAAEhE,0BAA0B,CAACa,KAAK,GAAG;EACpD,CAAC,GACD,CAAC,CAAC,EACR,CAACzB,OAAO,CACV,CAAC;EAED,oBACE5C,MAAA,CAAAc,OAAA,CAAA2G,aAAA,CAACrH,sBAAA,CAAAU,OAAU,CAAC4G,UAAU,EAAA7F,QAAA;IACpBoB,GAAG,EAAEwB;EAAM,GACPzB,IAAI;IACRP,QAAQ,EAAEmC,kBAAmB;IAC7B/B,QAAQ,EAAEA,QAAS;IACnB8E,mBAAmB,EAAE;EAAG,IAEvBnF,QAAQ,eACTxC,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,GAEawB,uBAAuB","ignoreList":[]}
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","prototype","hasOwnProperty","call","i","set","_extends","assign","bind","target","arguments","length","source","key","apply","KeyboardAwareScrollView","forwardRef","children","onLayout","bottomOffset","disableScrollOnKeyboardHide","enabled","extraKeyboardSpace","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","snapToOffsets","targetScrollY","Math","max","scrollTo","positionOnScreen","topOfScreen","onChangeText","_layout$value4","_input$value","prevScrollPosition","prevLayout","onChangeTextHandler","useMemo","debounce","useFocusedInputHandler","useSmoothKeyboardHandler","onStart","keyboardWillChangeSize","keyboardWillHide","focusWasChanged","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 { FocusedInputLayoutChangedEvent } 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 ...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 rest.snapToOffsets,\n ) - scrollPosition.value,\n ],\n );\n const targetScrollY =\n Math.max(interpolatedScrollTo, 0) + scrollPosition.value;\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, rest.snapToOffsets],\n );\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 const prevScrollPosition = scrollPosition.value;\n const prevLayout = layout.value;\n\n scrollPosition.value = position.value;\n layout.value = input.value;\n maybeScroll(keyboardHeight.value, true);\n scrollPosition.value = prevScrollPosition;\n layout.value = prevLayout;\n }, [maybeScroll]);\n\n const onChangeTextHandler = useMemo(\n () => debounce(onChangeText, 200),\n [onChangeText],\n );\n\n useFocusedInputHandler(\n {\n onChangeText: onChangeTextHandler,\n },\n [onChangeTextHandler],\n );\n\n useSmoothKeyboardHandler(\n {\n onStart: (e) => {\n \"worklet\";\n\n const keyboardWillChangeSize =\n keyboardHeight.value !== e.height && e.height > 0;\n keyboardWillAppear.value = e.height > 0 && keyboardHeight.value === 0;\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 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 onLayout={onScrollViewLayout}\n scrollEventThrottle={16}\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,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAjB,CAAA,EAAAc,CAAA,SAAAI,CAAA,GAAAR,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OAAKgF,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAEhF,MAAM,KACpC,CAAAqC,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEN,MAAM,CAACC,MAAM,OAAKgD,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAEjD,MAAM,CAACC,MAAM,GAClD;MACA,MAAMkC,UAAU,GAAGnC,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,GAAG2B,UAAU;IAC3B;EACF,CAAC,EACD,EACF,CAAC;EAED,MAAMe,IAAI,GAAG,IAAAC,uCAAgB,EAC3B,MACEtE,OAAO,GACH;IACE;IACA;IACA;IACA;IACA;IACA;IACAuE,aAAa,EAAE5D,0BAA0B,CAACgB,KAAK,GAAG;EACpD,CAAC,GACD,CAAC,CAAC,EACR,CAAC3B,OAAO,CACV,CAAC;EAED,oBACE5C,MAAA,CAAAc,OAAA,CAAAsG,aAAA,CAAChH,sBAAA,CAAAU,OAAU,CAACuG,UAAU,EAAAxF,QAAA;IACpBkB,GAAG,EAAEmB;EAAM,GACPpB,IAAI;IACRL,QAAQ,EAAE6B,kBAAmB;IAC7BgD,mBAAmB,EAAE;EAAG,IAEvB9E,QAAQ,eACTxC,MAAA,CAAAc,OAAA,CAAAsG,aAAA,CAAChH,sBAAA,CAAAU,OAAU,CAACyG,IAAI;IAACC,KAAK,EAAEP;EAAK,CAAE,CACV,CAAC;AAE5B,CACF,CAAC;AAAC,IAAAQ,QAAA,GAAAC,OAAA,CAAA5G,OAAA,GAEawB,uBAAuB","ignoreList":[]}
@@ -1,7 +1,7 @@
1
1
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
2
  import React, { forwardRef, useCallback, useMemo } from "react";
3
3
  import { findNodeHandle } from "react-native";
4
- import Reanimated, { interpolate, scrollTo, useAnimatedReaction, useAnimatedRef, useAnimatedStyle, useSharedValue } from "react-native-reanimated";
4
+ import Reanimated, { interpolate, scrollTo, useAnimatedReaction, useAnimatedRef, useAnimatedStyle, useScrollViewOffset, useSharedValue } from "react-native-reanimated";
5
5
  import { useFocusedInputHandler, useReanimatedFocusedInput, useWindowDimensions } from "react-native-keyboard-controller";
6
6
  import { useSmoothKeyboardHandler } from "./useSmoothKeyboardHandler";
7
7
  import { debounce, scrollDistanceWithRespectToSnapPoints } from "./utils";
@@ -49,14 +49,13 @@ const KeyboardAwareScrollView = /*#__PURE__*/forwardRef(({
49
49
  bottomOffset = 0,
50
50
  disableScrollOnKeyboardHide = false,
51
51
  enabled = true,
52
- onScroll: onScrollProps,
53
52
  extraKeyboardSpace = 0,
54
53
  ...rest
55
54
  }, ref) => {
56
55
  const scrollViewAnimatedRef = useAnimatedRef();
57
56
  const scrollViewTarget = useSharedValue(null);
58
57
  const scrollPosition = useSharedValue(0);
59
- const position = useSharedValue(0);
58
+ const position = useScrollViewOffset(scrollViewAnimatedRef);
60
59
  const currentKeyboardFrameHeight = useSharedValue(0);
61
60
  const keyboardHeight = useSharedValue(0);
62
61
  const keyboardWillAppear = useSharedValue(false);
@@ -70,10 +69,6 @@ const KeyboardAwareScrollView = /*#__PURE__*/forwardRef(({
70
69
  const {
71
70
  height
72
71
  } = useWindowDimensions();
73
- const onScroll = useCallback(event => {
74
- position.value = event.nativeEvent.contentOffset.y;
75
- onScrollProps === null || onScrollProps === void 0 || onScrollProps(event);
76
- }, [onScrollProps]);
77
72
  const onRef = useCallback(assignedRef => {
78
73
  if (typeof ref === "function") {
79
74
  ref(assignedRef);
@@ -119,7 +114,7 @@ const KeyboardAwareScrollView = /*#__PURE__*/forwardRef(({
119
114
  scrollTo(scrollViewAnimatedRef, 0, topOfScreen - positionOnScreen, animated);
120
115
  }
121
116
  return 0;
122
- }, [bottomOffset, enabled, rest.snapToOffsets]);
117
+ }, [bottomOffset, enabled, height, rest.snapToOffsets]);
123
118
  const onChangeText = useCallback(() => {
124
119
  "worklet";
125
120
 
@@ -197,7 +192,7 @@ const KeyboardAwareScrollView = /*#__PURE__*/forwardRef(({
197
192
  keyboardHeight.value = e.height;
198
193
  scrollPosition.value = position.value;
199
194
  }
200
- }, [height, maybeScroll, disableScrollOnKeyboardHide, extraKeyboardSpace]);
195
+ }, [maybeScroll, disableScrollOnKeyboardHide, extraKeyboardSpace]);
201
196
  useAnimatedReaction(() => input.value, (current, previous) => {
202
197
  if ((current === null || current === void 0 ? void 0 : current.target) === (previous === null || previous === void 0 ? void 0 : previous.target) && (current === null || current === void 0 ? void 0 : current.layout.height) !== (previous === null || previous === void 0 ? void 0 : previous.layout.height)) {
203
198
  const prevLayout = layout.value;
@@ -219,7 +214,6 @@ const KeyboardAwareScrollView = /*#__PURE__*/forwardRef(({
219
214
  ref: onRef
220
215
  }, rest, {
221
216
  onLayout: onScrollViewLayout,
222
- onScroll: onScroll,
223
217
  scrollEventThrottle: 16
224
218
  }), children, /*#__PURE__*/React.createElement(Reanimated.View, {
225
219
  style: view
@@ -1 +1 @@
1
- {"version":3,"names":["React","forwardRef","useCallback","useMemo","findNodeHandle","Reanimated","interpolate","scrollTo","useAnimatedReaction","useAnimatedRef","useAnimatedStyle","useSharedValue","useFocusedInputHandler","useReanimatedFocusedInput","useWindowDimensions","useSmoothKeyboardHandler","debounce","scrollDistanceWithRespectToSnapPoints","KeyboardAwareScrollView","children","onLayout","bottomOffset","disableScrollOnKeyboardHide","enabled","onScroll","onScrollProps","extraKeyboardSpace","rest","ref","scrollViewAnimatedRef","scrollViewTarget","scrollPosition","position","currentKeyboardFrameHeight","keyboardHeight","keyboardWillAppear","tag","initialKeyboardSize","scrollBeforeKeyboardMovement","input","layout","height","event","value","nativeEvent","contentOffset","y","onRef","assignedRef","current","onScrollViewLayout","e","maybeScroll","animated","_layout$value","_layout$value2","_layout$value3","parentScrollViewTarget","visibleRect","absoluteY","inputHeight","point","relativeScrollTo","interpolatedScrollTo","snapToOffsets","targetScrollY","Math","max","positionOnScreen","topOfScreen","onChangeText","_layout$value4","_input$value","prevScrollPosition","prevLayout","onChangeTextHandler","onStart","keyboardWillChangeSize","keyboardWillHide","focusWasChanged","target","onMove","keyboardFrame","onEnd","previous","view","paddingBottom","createElement","ScrollView","_extends","scrollEventThrottle","View","style"],"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 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 { FocusedInputLayoutChangedEvent } 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 onScroll: onScrollProps,\n extraKeyboardSpace = 0,\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 = useSharedValue(0);\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 onScroll = useCallback<NonNullable<ScrollViewProps[\"onScroll\"]>>(\n (event) => {\n position.value = event.nativeEvent.contentOffset.y;\n\n onScrollProps?.(event);\n },\n [onScrollProps],\n );\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 rest.snapToOffsets,\n ) - scrollPosition.value,\n ],\n );\n const targetScrollY =\n Math.max(interpolatedScrollTo, 0) + scrollPosition.value;\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, rest.snapToOffsets],\n );\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 const prevScrollPosition = scrollPosition.value;\n const prevLayout = layout.value;\n\n scrollPosition.value = position.value;\n layout.value = input.value;\n maybeScroll(keyboardHeight.value, true);\n scrollPosition.value = prevScrollPosition;\n layout.value = prevLayout;\n }, [maybeScroll]);\n\n const onChangeTextHandler = useMemo(\n () => debounce(onChangeText, 200),\n [onChangeText],\n );\n\n useFocusedInputHandler(\n {\n onChangeText: onChangeTextHandler,\n },\n [onChangeTextHandler],\n );\n\n useSmoothKeyboardHandler(\n {\n onStart: (e) => {\n \"worklet\";\n\n const keyboardWillChangeSize =\n keyboardHeight.value !== e.height && e.height > 0;\n keyboardWillAppear.value = e.height > 0 && keyboardHeight.value === 0;\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 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 [height, 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 onLayout={onScrollViewLayout}\n onScroll={onScroll}\n scrollEventThrottle={16}\n >\n {children}\n <Reanimated.View style={view} />\n </Reanimated.ScrollView>\n );\n },\n);\n\nexport default KeyboardAw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B,cAAc,CAACS,KAAK,EAAE,IAAI,CAAC;MAC/DH,MAAM,CAACG,KAAK,GAAG+B,UAAU;IAC3B;EACF,CAAC,EACD,EACF,CAAC;EAED,MAAMW,IAAI,GAAG3E,gBAAgB,CAC3B,MACEa,OAAO,GACH;IACE;IACA;IACA;IACA;IACA;IACA;IACA+D,aAAa,EAAErD,0BAA0B,CAACU,KAAK,GAAG;EACpD,CAAC,GACD,CAAC,CAAC,EACR,CAACpB,OAAO,CACV,CAAC;EAED,oBACEvB,KAAA,CAAAuF,aAAA,CAAClF,UAAU,CAACmF,UAAU,EAAAC,QAAA;IACpB7D,GAAG,EAAEmB;EAAM,GACPpB,IAAI;IACRP,QAAQ,EAAE8B,kBAAmB;IAC7B1B,QAAQ,EAAEA,QAAS;IACnBkE,mBAAmB,EAAE;EAAG,IAEvBvE,QAAQ,eACTnB,KAAA,CAAAuF,aAAA,CAAClF,UAAU,CAACsF,IAAI;IAACC,KAAK,EAAEP;EAAK,CAAE,CACV,CAAC;AAE5B,CACF,CAAC;AAED,eAAenE,uBAAuB","ignoreList":[]}
1
+ {"version":3,"names":["React","forwardRef","useCallback","useMemo","findNodeHandle","Reanimated","interpolate","scrollTo","useAnimatedReaction","useAnimatedRef","useAnimatedStyle","useScrollViewOffset","useSharedValue","useFocusedInputHandler","useReanimatedFocusedInput","useWindowDimensions","useSmoothKeyboardHandler","debounce","scrollDistanceWithRespectToSnapPoints","KeyboardAwareScrollView","children","onLayout","bottomOffset","disableScrollOnKeyboardHide","enabled","extraKeyboardSpace","rest","ref","scrollViewAnimatedRef","scrollViewTarget","scrollPosition","position","currentKeyboardFrameHeight","keyboardHeight","keyboardWillAppear","tag","initialKeyboardSize","scrollBeforeKeyboardMovement","input","layout","height","onRef","assignedRef","current","onScrollViewLayout","e","value","maybeScroll","animated","_layout$value","_layout$value2","_layout$value3","parentScrollViewTarget","visibleRect","absoluteY","inputHeight","point","relativeScrollTo","interpolatedScrollTo","snapToOffsets","targetScrollY","Math","max","positionOnScreen","topOfScreen","onChangeText","_layout$value4","_input$value","prevScrollPosition","prevLayout","onChangeTextHandler","onStart","keyboardWillChangeSize","keyboardWillHide","focusWasChanged","target","onMove","keyboardFrame","onEnd","previous","view","paddingBottom","createElement","ScrollView","_extends","scrollEventThrottle","View","style"],"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 { FocusedInputLayoutChangedEvent } 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 ...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 rest.snapToOffsets,\n ) - scrollPosition.value,\n ],\n );\n const targetScrollY =\n Math.max(interpolatedScrollTo, 0) + scrollPosition.value;\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, rest.snapToOffsets],\n );\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 const prevScrollPosition = scrollPosition.value;\n const prevLayout = layout.value;\n\n scrollPosition.value = position.value;\n layout.value = input.value;\n maybeScroll(keyboardHeight.value, true);\n scrollPosition.value = prevScrollPosition;\n layout.value = prevLayout;\n }, [maybeScroll]);\n\n const onChangeTextHandler = useMemo(\n () => debounce(onChangeText, 200),\n [onChangeText],\n );\n\n useFocusedInputHandler(\n {\n onChangeText: onChangeTextHandler,\n },\n [onChangeTextHandler],\n );\n\n useSmoothKeyboardHandler(\n {\n onStart: (e) => {\n \"worklet\";\n\n const keyboardWillChangeSize =\n keyboardHeight.value !== e.height && e.height > 0;\n keyboardWillAppear.value = e.height > 0 && keyboardHeight.value === 0;\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 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 onLayout={onScrollViewLayout}\n scrollEventThrottle={16}\n >\n {children}\n <Reanimated.View style={view} />\n </Reanimated.ScrollView>\n );\n },\n);\n\nexport default KeyboardAwareScrollView;\n"],"mappings":";AAAA,OAAOA,KAAK,IAAIC,UAAU,EAAEC,WAAW,EAAEC,OAAO,QAAQ,OAAO;AAC/D,SAASC,cAAc,QAAQ,cAAc;AAC7C,OAAOC,UAAU,IACfC,WAAW,EACXC,QAAQ,EACRC,mBAAmB,EACnBC,cAAc,EACdC,gBAAgB,EAChBC,mBAAmB,EACnBC,cAAc,QACT,yBAAyB;AAEhC,SACEC,sBAAsB,EACtBC,yBAAyB,EACz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E,UAAU,CAACiF,IAAI;IAACC,KAAK,EAAEP;EAAK,CAAE,CACV,CAAC;AAE5B,CACF,CAAC;AAED,eAAe7D,uBAAuB","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-keyboard-controller",
3
- "version": "1.12.4",
3
+ "version": "1.12.6",
4
4
  "description": "Keyboard manager which works in identical way on both iOS and Android",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -69,7 +69,7 @@
69
69
  },
70
70
  "devDependencies": {
71
71
  "@commitlint/config-conventional": "^11.0.0",
72
- "@react-native/eslint-config": "^0.73.2",
72
+ "@react-native/eslint-config": "^0.74.85",
73
73
  "@release-it/conventional-changelog": "^2.0.0",
74
74
  "@types/jest": "^29.2.1",
75
75
  "@types/react": "^18.2.6",
@@ -88,7 +88,7 @@
88
88
  "pod-install": "^0.1.0",
89
89
  "prettier": "^2.8.8",
90
90
  "react": "18.2.0",
91
- "react-native": "0.74.0",
91
+ "react-native": "0.74.3",
92
92
  "react-native-builder-bob": "^0.18.0",
93
93
  "react-native-reanimated": "3.12.1",
94
94
  "release-it": "^14.2.2",
@@ -97,7 +97,7 @@
97
97
  "peerDependencies": {
98
98
  "react": "*",
99
99
  "react-native": "*",
100
- "react-native-reanimated": ">=2.3.0"
100
+ "react-native-reanimated": ">=2.11.0"
101
101
  },
102
102
  "jest": {
103
103
  "preset": "react-native",
@@ -6,6 +6,7 @@ import Reanimated, {
6
6
  useAnimatedReaction,
7
7
  useAnimatedRef,
8
8
  useAnimatedStyle,
9
+ useScrollViewOffset,
9
10
  useSharedValue,
10
11
  } from "react-native-reanimated";
11
12
 
@@ -85,7 +86,6 @@ const KeyboardAwareScrollView = forwardRef<
85
86
  bottomOffset = 0,
86
87
  disableScrollOnKeyboardHide = false,
87
88
  enabled = true,
88
- onScroll: onScrollProps,
89
89
  extraKeyboardSpace = 0,
90
90
  ...rest
91
91
  },
@@ -94,7 +94,7 @@ const KeyboardAwareScrollView = forwardRef<
94
94
  const scrollViewAnimatedRef = useAnimatedRef<Reanimated.ScrollView>();
95
95
  const scrollViewTarget = useSharedValue<number | null>(null);
96
96
  const scrollPosition = useSharedValue(0);
97
- const position = useSharedValue(0);
97
+ const position = useScrollViewOffset(scrollViewAnimatedRef);
98
98
  const currentKeyboardFrameHeight = useSharedValue(0);
99
99
  const keyboardHeight = useSharedValue(0);
100
100
  const keyboardWillAppear = useSharedValue(false);
@@ -106,15 +106,6 @@ const KeyboardAwareScrollView = forwardRef<
106
106
 
107
107
  const { height } = useWindowDimensions();
108
108
 
109
- const onScroll = useCallback<NonNullable<ScrollViewProps["onScroll"]>>(
110
- (event) => {
111
- position.value = event.nativeEvent.contentOffset.y;
112
-
113
- onScrollProps?.(event);
114
- },
115
- [onScrollProps],
116
- );
117
-
118
109
  const onRef = useCallback((assignedRef: Reanimated.ScrollView) => {
119
110
  if (typeof ref === "function") {
120
111
  ref(assignedRef);
@@ -189,7 +180,7 @@ const KeyboardAwareScrollView = forwardRef<
189
180
 
190
181
  return 0;
191
182
  },
192
- [bottomOffset, enabled, rest.snapToOffsets],
183
+ [bottomOffset, enabled, height, rest.snapToOffsets],
193
184
  );
194
185
 
195
186
  const onChangeText = useCallback(() => {
@@ -296,7 +287,7 @@ const KeyboardAwareScrollView = forwardRef<
296
287
  scrollPosition.value = position.value;
297
288
  },
298
289
  },
299
- [height, maybeScroll, disableScrollOnKeyboardHide, extraKeyboardSpace],
290
+ [maybeScroll, disableScrollOnKeyboardHide, extraKeyboardSpace],
300
291
  );
301
292
 
302
293
  useAnimatedReaction(
@@ -337,7 +328,6 @@ const KeyboardAwareScrollView = forwardRef<
337
328
  ref={onRef}
338
329
  {...rest}
339
330
  onLayout={onScrollViewLayout}
340
- onScroll={onScroll}
341
331
  scrollEventThrottle={16}
342
332
  >
343
333
  {children}