react-native-keyboard-controller 1.13.3 → 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 +4 -4
- 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/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/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/package.json +1 -1
- 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
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
|
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
|
|
|
@@ -24,7 +24,6 @@ var _react = require("react");
|
|
|
24
24
|
var _bindings = require("../bindings");
|
|
25
25
|
var _constants = require("../constants");
|
|
26
26
|
var _context = require("../context");
|
|
27
|
-
var _useSyncEffect = _interopRequireDefault(require("./useSyncEffect"));
|
|
28
27
|
var _useWindowDimensions = require("./useWindowDimensions");
|
|
29
28
|
Object.keys(_useWindowDimensions).forEach(function (key) {
|
|
30
29
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -37,7 +36,6 @@ Object.keys(_useWindowDimensions).forEach(function (key) {
|
|
|
37
36
|
}
|
|
38
37
|
});
|
|
39
38
|
});
|
|
40
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
41
39
|
const useResizeMode = () => {
|
|
42
40
|
(0, _react.useEffect)(() => {
|
|
43
41
|
_bindings.KeyboardController.setInputMode(_constants.AndroidSoftInputModes.SOFT_INPUT_ADJUST_RESIZE);
|
|
@@ -59,7 +57,7 @@ const useReanimatedKeyboardAnimation = () => {
|
|
|
59
57
|
exports.useReanimatedKeyboardAnimation = useReanimatedKeyboardAnimation;
|
|
60
58
|
function useGenericKeyboardHandler(handler, deps) {
|
|
61
59
|
const context = (0, _context.useKeyboardContext)();
|
|
62
|
-
(0,
|
|
60
|
+
(0, _react.useLayoutEffect)(() => {
|
|
63
61
|
const cleanup = context.setKeyboardHandlers(handler);
|
|
64
62
|
return () => cleanup();
|
|
65
63
|
}, deps);
|
|
@@ -83,7 +81,7 @@ function useReanimatedFocusedInput() {
|
|
|
83
81
|
}
|
|
84
82
|
function useFocusedInputHandler(handler, deps) {
|
|
85
83
|
const context = (0, _context.useKeyboardContext)();
|
|
86
|
-
(0,
|
|
84
|
+
(0, _react.useLayoutEffect)(() => {
|
|
87
85
|
const cleanup = context.setInputHandlers(handler);
|
|
88
86
|
return () => cleanup();
|
|
89
87
|
}, deps);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","_bindings","_constants","_context","
|
|
1
|
+
{"version":3,"names":["_react","require","_bindings","_constants","_context","_useWindowDimensions","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","useResizeMode","useEffect","KeyboardController","setInputMode","AndroidSoftInputModes","SOFT_INPUT_ADJUST_RESIZE","setDefaultMode","useKeyboardAnimation","context","useKeyboardContext","animated","useReanimatedKeyboardAnimation","reanimated","useGenericKeyboardHandler","handler","deps","useLayoutEffect","cleanup","setKeyboardHandlers","useKeyboardHandler","useKeyboardController","setEnabled","enabled","useReanimatedFocusedInput","input","layout","useFocusedInputHandler","setInputHandlers"],"sources":["index.ts"],"sourcesContent":["import { useEffect, useLayoutEffect } from \"react\";\n\nimport { KeyboardController } from \"../bindings\";\nimport { AndroidSoftInputModes } from \"../constants\";\nimport { useKeyboardContext } from \"../context\";\n\nimport type { AnimatedContext, ReanimatedContext } from \"../context\";\nimport type { FocusedInputHandler, KeyboardHandler } from \"../types\";\nimport type { DependencyList } from \"react\";\n\nexport const useResizeMode = () => {\n useEffect(() => {\n KeyboardController.setInputMode(\n AndroidSoftInputModes.SOFT_INPUT_ADJUST_RESIZE,\n );\n\n return () => KeyboardController.setDefaultMode();\n }, []);\n};\n\nexport const useKeyboardAnimation = (): AnimatedContext => {\n useResizeMode();\n const context = useKeyboardContext();\n\n return context.animated;\n};\n\nexport const useReanimatedKeyboardAnimation = (): ReanimatedContext => {\n useResizeMode();\n const context = useKeyboardContext();\n\n return context.reanimated;\n};\n\nexport function useGenericKeyboardHandler(\n handler: KeyboardHandler,\n deps?: DependencyList,\n) {\n const context = useKeyboardContext();\n\n useLayoutEffect(() => {\n const cleanup = context.setKeyboardHandlers(handler);\n\n return () => cleanup();\n }, deps);\n}\n\nexport function useKeyboardHandler(\n handler: KeyboardHandler,\n deps?: DependencyList,\n) {\n useResizeMode();\n useGenericKeyboardHandler(handler, deps);\n}\n\nexport function useKeyboardController() {\n const context = useKeyboardContext();\n\n return { setEnabled: context.setEnabled, enabled: context.enabled };\n}\n\nexport function useReanimatedFocusedInput() {\n const context = useKeyboardContext();\n\n return { input: context.layout };\n}\n\nexport function useFocusedInputHandler(\n handler: FocusedInputHandler,\n deps?: DependencyList,\n) {\n const context = useKeyboardContext();\n\n useLayoutEffect(() => {\n const cleanup = context.setInputHandlers(handler);\n\n return () => cleanup();\n }, deps);\n}\n\nexport * from \"./useWindowDimensions\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AA4EA,IAAAI,oBAAA,GAAAJ,OAAA;AAAAK,MAAA,CAAAC,IAAA,CAAAF,oBAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,oBAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,oBAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AAtEO,MAAMS,aAAa,GAAGA,CAAA,KAAM;EACjC,IAAAC,gBAAS,EAAC,MAAM;IACdC,4BAAkB,CAACC,YAAY,CAC7BC,gCAAqB,CAACC,wBACxB,CAAC;IAED,OAAO,MAAMH,4BAAkB,CAACI,cAAc,CAAC,CAAC;EAClD,CAAC,EAAE,EAAE,CAAC;AACR,CAAC;AAACV,OAAA,CAAAI,aAAA,GAAAA,aAAA;AAEK,MAAMO,oBAAoB,GAAGA,CAAA,KAAuB;EACzDP,aAAa,CAAC,CAAC;EACf,MAAMQ,OAAO,GAAG,IAAAC,2BAAkB,EAAC,CAAC;EAEpC,OAAOD,OAAO,CAACE,QAAQ;AACzB,CAAC;AAACd,OAAA,CAAAW,oBAAA,GAAAA,oBAAA;AAEK,MAAMI,8BAA8B,GAAGA,CAAA,KAAyB;EACrEX,aAAa,CAAC,CAAC;EACf,MAAMQ,OAAO,GAAG,IAAAC,2BAAkB,EAAC,CAAC;EAEpC,OAAOD,OAAO,CAACI,UAAU;AAC3B,CAAC;AAAChB,OAAA,CAAAe,8BAAA,GAAAA,8BAAA;AAEK,SAASE,yBAAyBA,CACvCC,OAAwB,EACxBC,IAAqB,EACrB;EACA,MAAMP,OAAO,GAAG,IAAAC,2BAAkB,EAAC,CAAC;EAEpC,IAAAO,sBAAe,EAAC,MAAM;IACpB,MAAMC,OAAO,GAAGT,OAAO,CAACU,mBAAmB,CAACJ,OAAO,CAAC;IAEpD,OAAO,MAAMG,OAAO,CAAC,CAAC;EACxB,CAAC,EAAEF,IAAI,CAAC;AACV;AAEO,SAASI,kBAAkBA,CAChCL,OAAwB,EACxBC,IAAqB,EACrB;EACAf,aAAa,CAAC,CAAC;EACfa,yBAAyB,CAACC,OAAO,EAAEC,IAAI,CAAC;AAC1C;AAEO,SAASK,qBAAqBA,CAAA,EAAG;EACtC,MAAMZ,OAAO,GAAG,IAAAC,2BAAkB,EAAC,CAAC;EAEpC,OAAO;IAAEY,UAAU,EAAEb,OAAO,CAACa,UAAU;IAAEC,OAAO,EAAEd,OAAO,CAACc;EAAQ,CAAC;AACrE;AAEO,SAASC,yBAAyBA,CAAA,EAAG;EAC1C,MAAMf,OAAO,GAAG,IAAAC,2BAAkB,EAAC,CAAC;EAEpC,OAAO;IAAEe,KAAK,EAAEhB,OAAO,CAACiB;EAAO,CAAC;AAClC;AAEO,SAASC,sBAAsBA,CACpCZ,OAA4B,EAC5BC,IAAqB,EACrB;EACA,MAAMP,OAAO,GAAG,IAAAC,2BAAkB,EAAC,CAAC;EAEpC,IAAAO,sBAAe,EAAC,MAAM;IACpB,MAAMC,OAAO,GAAGT,OAAO,CAACmB,gBAAgB,CAACb,OAAO,CAAC;IAEjD,OAAO,MAAMG,OAAO,CAAC,CAAC;EACxB,CAAC,EAAEF,IAAI,CAAC;AACV","ignoreList":[]}
|
package/lib/commonjs/internal.js
CHANGED
|
@@ -10,19 +10,31 @@ var _reactNative = require("react-native");
|
|
|
10
10
|
var _eventHandler = require("./event-handler");
|
|
11
11
|
function useEventHandlerRegistration(map, viewTagRef) {
|
|
12
12
|
const onRegisterHandler = handler => {
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return (0, _eventHandler.registerEventHandler)(event => {
|
|
19
|
-
"worklet";
|
|
20
|
-
|
|
21
|
-
functionToCall === null || functionToCall === void 0 || functionToCall(event);
|
|
22
|
-
}, eventName, viewTag);
|
|
13
|
+
const ids = [];
|
|
14
|
+
const attachWorkletHandlers = () => {
|
|
15
|
+
const viewTag = (0, _reactNative.findNodeHandle)(viewTagRef.current);
|
|
16
|
+
if (__DEV__ && !viewTag) {
|
|
17
|
+
console.warn("Can not attach worklet handlers for `react-native-keyboard-controller` because view tag can not be resolved. Be sure that `KeyboardProvider` is fully mounted before registering handlers. If you think it is a bug in library, please open an issue.");
|
|
23
18
|
}
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
ids.push(...Object.keys(handler).map(handlerName => {
|
|
20
|
+
const eventName = map.get(handlerName);
|
|
21
|
+
const functionToCall = handler[handlerName];
|
|
22
|
+
if (eventName && viewTag) {
|
|
23
|
+
return (0, _eventHandler.registerEventHandler)(event => {
|
|
24
|
+
"worklet";
|
|
25
|
+
|
|
26
|
+
functionToCall === null || functionToCall === void 0 || functionToCall(event);
|
|
27
|
+
}, eventName, viewTag);
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}));
|
|
31
|
+
};
|
|
32
|
+
if (viewTagRef.current) {
|
|
33
|
+
attachWorkletHandlers();
|
|
34
|
+
} else {
|
|
35
|
+
// view may not be mounted yet - defer registration to next event loop
|
|
36
|
+
setImmediate(attachWorkletHandlers);
|
|
37
|
+
}
|
|
26
38
|
return () => {
|
|
27
39
|
ids.forEach(id => id ? (0, _eventHandler.unregisterEventHandler)(id) : null);
|
|
28
40
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","_reactNative","_eventHandler","useEventHandlerRegistration","map","viewTagRef","onRegisterHandler","handler","viewTag","findNodeHandle","current","
|
|
1
|
+
{"version":3,"names":["_react","require","_reactNative","_eventHandler","useEventHandlerRegistration","map","viewTagRef","onRegisterHandler","handler","ids","attachWorkletHandlers","viewTag","findNodeHandle","current","__DEV__","console","warn","push","Object","keys","handlerName","eventName","get","functionToCall","registerEventHandler","event","setImmediate","forEach","id","unregisterEventHandler","useAnimatedValue","initialValue","config","ref","useRef","Animated","Value"],"sources":["internal.ts"],"sourcesContent":["import { useRef } from \"react\";\nimport { Animated, findNodeHandle } from \"react-native\";\n\nimport { registerEventHandler, unregisterEventHandler } from \"./event-handler\";\n\ntype EventHandler = (event: never) => void;\ntype ComponentOrHandle = Parameters<typeof findNodeHandle>[0];\n\nexport function useEventHandlerRegistration<\n H extends Partial<Record<string, EventHandler>>,\n>(\n map: Map<keyof H, string>,\n viewTagRef: React.MutableRefObject<ComponentOrHandle>,\n) {\n const onRegisterHandler = (handler: H) => {\n const ids: (number | null)[] = [];\n const attachWorkletHandlers = () => {\n const viewTag = findNodeHandle(viewTagRef.current);\n\n if (__DEV__ && !viewTag) {\n console.warn(\n \"Can not attach worklet handlers for `react-native-keyboard-controller` because view tag can not be resolved. Be sure that `KeyboardProvider` is fully mounted before registering handlers. If you think it is a bug in library, please open an issue.\",\n );\n }\n\n ids.push(\n ...Object.keys(handler).map((handlerName) => {\n const eventName = map.get(handlerName as keyof H);\n const functionToCall = handler[handlerName as keyof H];\n\n if (eventName && viewTag) {\n return registerEventHandler(\n (event: Parameters<NonNullable<H[keyof H]>>[0]) => {\n \"worklet\";\n\n functionToCall?.(event);\n },\n eventName,\n viewTag,\n );\n }\n\n return null;\n }),\n );\n };\n\n if (viewTagRef.current) {\n attachWorkletHandlers();\n } else {\n // view may not be mounted yet - defer registration to next event loop\n setImmediate(attachWorkletHandlers);\n }\n\n return () => {\n ids.forEach((id) => (id ? unregisterEventHandler(id) : null));\n };\n };\n\n return onRegisterHandler;\n}\n\n/**\n * TS variant of `useAnimatedValue` hook which is added in RN 0.71\n * A better alternative of storing animated values in refs, since\n * it doesn't recreate a new `Animated.Value` object on every re-render\n * and therefore consumes less memory. We can not use a variant from\n * RN, since this library supports earlier versions of RN.\n *\n * @see https://github.com/facebook/react-native/commit/e22217fe8b9455e32695f88ca835e11442b0a937\n */\nexport function useAnimatedValue(\n initialValue: number,\n config?: Animated.AnimatedConfig,\n): Animated.Value {\n const ref = useRef<Animated.Value | null>(null);\n\n if (ref.current === null) {\n ref.current = new Animated.Value(initialValue, config);\n }\n\n return ref.current;\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAEA,IAAAE,aAAA,GAAAF,OAAA;AAKO,SAASG,2BAA2BA,CAGzCC,GAAyB,EACzBC,UAAqD,EACrD;EACA,MAAMC,iBAAiB,GAAIC,OAAU,IAAK;IACxC,MAAMC,GAAsB,GAAG,EAAE;IACjC,MAAMC,qBAAqB,GAAGA,CAAA,KAAM;MAClC,MAAMC,OAAO,GAAG,IAAAC,2BAAc,EAACN,UAAU,CAACO,OAAO,CAAC;MAElD,IAAIC,OAAO,IAAI,CAACH,OAAO,EAAE;QACvBI,OAAO,CAACC,IAAI,CACV,uPACF,CAAC;MACH;MAEAP,GAAG,CAACQ,IAAI,CACN,GAAGC,MAAM,CAACC,IAAI,CAACX,OAAO,CAAC,CAACH,GAAG,CAAEe,WAAW,IAAK;QAC3C,MAAMC,SAAS,GAAGhB,GAAG,CAACiB,GAAG,CAACF,WAAsB,CAAC;QACjD,MAAMG,cAAc,GAAGf,OAAO,CAACY,WAAW,CAAY;QAEtD,IAAIC,SAAS,IAAIV,OAAO,EAAE;UACxB,OAAO,IAAAa,kCAAoB,EACxBC,KAA6C,IAAK;YACjD,SAAS;;YAETF,cAAc,aAAdA,cAAc,eAAdA,cAAc,CAAGE,KAAK,CAAC;UACzB,CAAC,EACDJ,SAAS,EACTV,OACF,CAAC;QACH;QAEA,OAAO,IAAI;MACb,CAAC,CACH,CAAC;IACH,CAAC;IAED,IAAIL,UAAU,CAACO,OAAO,EAAE;MACtBH,qBAAqB,CAAC,CAAC;IACzB,CAAC,MAAM;MACL;MACAgB,YAAY,CAAChB,qBAAqB,CAAC;IACrC;IAEA,OAAO,MAAM;MACXD,GAAG,CAACkB,OAAO,CAAEC,EAAE,IAAMA,EAAE,GAAG,IAAAC,oCAAsB,EAACD,EAAE,CAAC,GAAG,IAAK,CAAC;IAC/D,CAAC;EACH,CAAC;EAED,OAAOrB,iBAAiB;AAC1B;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASuB,gBAAgBA,CAC9BC,YAAoB,EACpBC,MAAgC,EAChB;EAChB,MAAMC,GAAG,GAAG,IAAAC,aAAM,EAAwB,IAAI,CAAC;EAE/C,IAAID,GAAG,CAACpB,OAAO,KAAK,IAAI,EAAE;IACxBoB,GAAG,CAACpB,OAAO,GAAG,IAAIsB,qBAAQ,CAACC,KAAK,CAACL,YAAY,EAAEC,MAAM,CAAC;EACxD;EAEA,OAAOC,GAAG,CAACpB,OAAO;AACpB","ignoreList":[]}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { useEffect } from "react";
|
|
1
|
+
import { useEffect, useLayoutEffect } from "react";
|
|
2
2
|
import { KeyboardController } from "../bindings";
|
|
3
3
|
import { AndroidSoftInputModes } from "../constants";
|
|
4
4
|
import { useKeyboardContext } from "../context";
|
|
5
|
-
import useSyncEffect from "./useSyncEffect";
|
|
6
5
|
export const useResizeMode = () => {
|
|
7
6
|
useEffect(() => {
|
|
8
7
|
KeyboardController.setInputMode(AndroidSoftInputModes.SOFT_INPUT_ADJUST_RESIZE);
|
|
@@ -21,7 +20,7 @@ export const useReanimatedKeyboardAnimation = () => {
|
|
|
21
20
|
};
|
|
22
21
|
export function useGenericKeyboardHandler(handler, deps) {
|
|
23
22
|
const context = useKeyboardContext();
|
|
24
|
-
|
|
23
|
+
useLayoutEffect(() => {
|
|
25
24
|
const cleanup = context.setKeyboardHandlers(handler);
|
|
26
25
|
return () => cleanup();
|
|
27
26
|
}, deps);
|
|
@@ -45,7 +44,7 @@ export function useReanimatedFocusedInput() {
|
|
|
45
44
|
}
|
|
46
45
|
export function useFocusedInputHandler(handler, deps) {
|
|
47
46
|
const context = useKeyboardContext();
|
|
48
|
-
|
|
47
|
+
useLayoutEffect(() => {
|
|
49
48
|
const cleanup = context.setInputHandlers(handler);
|
|
50
49
|
return () => cleanup();
|
|
51
50
|
}, deps);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useEffect","KeyboardController","AndroidSoftInputModes","useKeyboardContext","
|
|
1
|
+
{"version":3,"names":["useEffect","useLayoutEffect","KeyboardController","AndroidSoftInputModes","useKeyboardContext","useResizeMode","setInputMode","SOFT_INPUT_ADJUST_RESIZE","setDefaultMode","useKeyboardAnimation","context","animated","useReanimatedKeyboardAnimation","reanimated","useGenericKeyboardHandler","handler","deps","cleanup","setKeyboardHandlers","useKeyboardHandler","useKeyboardController","setEnabled","enabled","useReanimatedFocusedInput","input","layout","useFocusedInputHandler","setInputHandlers"],"sources":["index.ts"],"sourcesContent":["import { useEffect, useLayoutEffect } from \"react\";\n\nimport { KeyboardController } from \"../bindings\";\nimport { AndroidSoftInputModes } from \"../constants\";\nimport { useKeyboardContext } from \"../context\";\n\nimport type { AnimatedContext, ReanimatedContext } from \"../context\";\nimport type { FocusedInputHandler, KeyboardHandler } from \"../types\";\nimport type { DependencyList } from \"react\";\n\nexport const useResizeMode = () => {\n useEffect(() => {\n KeyboardController.setInputMode(\n AndroidSoftInputModes.SOFT_INPUT_ADJUST_RESIZE,\n );\n\n return () => KeyboardController.setDefaultMode();\n }, []);\n};\n\nexport const useKeyboardAnimation = (): AnimatedContext => {\n useResizeMode();\n const context = useKeyboardContext();\n\n return context.animated;\n};\n\nexport const useReanimatedKeyboardAnimation = (): ReanimatedContext => {\n useResizeMode();\n const context = useKeyboardContext();\n\n return context.reanimated;\n};\n\nexport function useGenericKeyboardHandler(\n handler: KeyboardHandler,\n deps?: DependencyList,\n) {\n const context = useKeyboardContext();\n\n useLayoutEffect(() => {\n const cleanup = context.setKeyboardHandlers(handler);\n\n return () => cleanup();\n }, deps);\n}\n\nexport function useKeyboardHandler(\n handler: KeyboardHandler,\n deps?: DependencyList,\n) {\n useResizeMode();\n useGenericKeyboardHandler(handler, deps);\n}\n\nexport function useKeyboardController() {\n const context = useKeyboardContext();\n\n return { setEnabled: context.setEnabled, enabled: context.enabled };\n}\n\nexport function useReanimatedFocusedInput() {\n const context = useKeyboardContext();\n\n return { input: context.layout };\n}\n\nexport function useFocusedInputHandler(\n handler: FocusedInputHandler,\n deps?: DependencyList,\n) {\n const context = useKeyboardContext();\n\n useLayoutEffect(() => {\n const cleanup = context.setInputHandlers(handler);\n\n return () => cleanup();\n }, deps);\n}\n\nexport * from \"./useWindowDimensions\";\n"],"mappings":"AAAA,SAASA,SAAS,EAAEC,eAAe,QAAQ,OAAO;AAElD,SAASC,kBAAkB,QAAQ,aAAa;AAChD,SAASC,qBAAqB,QAAQ,cAAc;AACpD,SAASC,kBAAkB,QAAQ,YAAY;AAM/C,OAAO,MAAMC,aAAa,GAAGA,CAAA,KAAM;EACjCL,SAAS,CAAC,MAAM;IACdE,kBAAkB,CAACI,YAAY,CAC7BH,qBAAqB,CAACI,wBACxB,CAAC;IAED,OAAO,MAAML,kBAAkB,CAACM,cAAc,CAAC,CAAC;EAClD,CAAC,EAAE,EAAE,CAAC;AACR,CAAC;AAED,OAAO,MAAMC,oBAAoB,GAAGA,CAAA,KAAuB;EACzDJ,aAAa,CAAC,CAAC;EACf,MAAMK,OAAO,GAAGN,kBAAkB,CAAC,CAAC;EAEpC,OAAOM,OAAO,CAACC,QAAQ;AACzB,CAAC;AAED,OAAO,MAAMC,8BAA8B,GAAGA,CAAA,KAAyB;EACrEP,aAAa,CAAC,CAAC;EACf,MAAMK,OAAO,GAAGN,kBAAkB,CAAC,CAAC;EAEpC,OAAOM,OAAO,CAACG,UAAU;AAC3B,CAAC;AAED,OAAO,SAASC,yBAAyBA,CACvCC,OAAwB,EACxBC,IAAqB,EACrB;EACA,MAAMN,OAAO,GAAGN,kBAAkB,CAAC,CAAC;EAEpCH,eAAe,CAAC,MAAM;IACpB,MAAMgB,OAAO,GAAGP,OAAO,CAACQ,mBAAmB,CAACH,OAAO,CAAC;IAEpD,OAAO,MAAME,OAAO,CAAC,CAAC;EACxB,CAAC,EAAED,IAAI,CAAC;AACV;AAEA,OAAO,SAASG,kBAAkBA,CAChCJ,OAAwB,EACxBC,IAAqB,EACrB;EACAX,aAAa,CAAC,CAAC;EACfS,yBAAyB,CAACC,OAAO,EAAEC,IAAI,CAAC;AAC1C;AAEA,OAAO,SAASI,qBAAqBA,CAAA,EAAG;EACtC,MAAMV,OAAO,GAAGN,kBAAkB,CAAC,CAAC;EAEpC,OAAO;IAAEiB,UAAU,EAAEX,OAAO,CAACW,UAAU;IAAEC,OAAO,EAAEZ,OAAO,CAACY;EAAQ,CAAC;AACrE;AAEA,OAAO,SAASC,yBAAyBA,CAAA,EAAG;EAC1C,MAAMb,OAAO,GAAGN,kBAAkB,CAAC,CAAC;EAEpC,OAAO;IAAEoB,KAAK,EAAEd,OAAO,CAACe;EAAO,CAAC;AAClC;AAEA,OAAO,SAASC,sBAAsBA,CACpCX,OAA4B,EAC5BC,IAAqB,EACrB;EACA,MAAMN,OAAO,GAAGN,kBAAkB,CAAC,CAAC;EAEpCH,eAAe,CAAC,MAAM;IACpB,MAAMgB,OAAO,GAAGP,OAAO,CAACiB,gBAAgB,CAACZ,OAAO,CAAC;IAEjD,OAAO,MAAME,OAAO,CAAC,CAAC;EACxB,CAAC,EAAED,IAAI,CAAC;AACV;AAEA,cAAc,uBAAuB","ignoreList":[]}
|
package/lib/module/internal.js
CHANGED
|
@@ -3,19 +3,31 @@ import { Animated, findNodeHandle } from "react-native";
|
|
|
3
3
|
import { registerEventHandler, unregisterEventHandler } from "./event-handler";
|
|
4
4
|
export function useEventHandlerRegistration(map, viewTagRef) {
|
|
5
5
|
const onRegisterHandler = handler => {
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return registerEventHandler(event => {
|
|
12
|
-
"worklet";
|
|
13
|
-
|
|
14
|
-
functionToCall === null || functionToCall === void 0 || functionToCall(event);
|
|
15
|
-
}, eventName, viewTag);
|
|
6
|
+
const ids = [];
|
|
7
|
+
const attachWorkletHandlers = () => {
|
|
8
|
+
const viewTag = findNodeHandle(viewTagRef.current);
|
|
9
|
+
if (__DEV__ && !viewTag) {
|
|
10
|
+
console.warn("Can not attach worklet handlers for `react-native-keyboard-controller` because view tag can not be resolved. Be sure that `KeyboardProvider` is fully mounted before registering handlers. If you think it is a bug in library, please open an issue.");
|
|
16
11
|
}
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
ids.push(...Object.keys(handler).map(handlerName => {
|
|
13
|
+
const eventName = map.get(handlerName);
|
|
14
|
+
const functionToCall = handler[handlerName];
|
|
15
|
+
if (eventName && viewTag) {
|
|
16
|
+
return registerEventHandler(event => {
|
|
17
|
+
"worklet";
|
|
18
|
+
|
|
19
|
+
functionToCall === null || functionToCall === void 0 || functionToCall(event);
|
|
20
|
+
}, eventName, viewTag);
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}));
|
|
24
|
+
};
|
|
25
|
+
if (viewTagRef.current) {
|
|
26
|
+
attachWorkletHandlers();
|
|
27
|
+
} else {
|
|
28
|
+
// view may not be mounted yet - defer registration to next event loop
|
|
29
|
+
setImmediate(attachWorkletHandlers);
|
|
30
|
+
}
|
|
19
31
|
return () => {
|
|
20
32
|
ids.forEach(id => id ? unregisterEventHandler(id) : null);
|
|
21
33
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useRef","Animated","findNodeHandle","registerEventHandler","unregisterEventHandler","useEventHandlerRegistration","map","viewTagRef","onRegisterHandler","handler","viewTag","current","
|
|
1
|
+
{"version":3,"names":["useRef","Animated","findNodeHandle","registerEventHandler","unregisterEventHandler","useEventHandlerRegistration","map","viewTagRef","onRegisterHandler","handler","ids","attachWorkletHandlers","viewTag","current","__DEV__","console","warn","push","Object","keys","handlerName","eventName","get","functionToCall","event","setImmediate","forEach","id","useAnimatedValue","initialValue","config","ref","Value"],"sources":["internal.ts"],"sourcesContent":["import { useRef } from \"react\";\nimport { Animated, findNodeHandle } from \"react-native\";\n\nimport { registerEventHandler, unregisterEventHandler } from \"./event-handler\";\n\ntype EventHandler = (event: never) => void;\ntype ComponentOrHandle = Parameters<typeof findNodeHandle>[0];\n\nexport function useEventHandlerRegistration<\n H extends Partial<Record<string, EventHandler>>,\n>(\n map: Map<keyof H, string>,\n viewTagRef: React.MutableRefObject<ComponentOrHandle>,\n) {\n const onRegisterHandler = (handler: H) => {\n const ids: (number | null)[] = [];\n const attachWorkletHandlers = () => {\n const viewTag = findNodeHandle(viewTagRef.current);\n\n if (__DEV__ && !viewTag) {\n console.warn(\n \"Can not attach worklet handlers for `react-native-keyboard-controller` because view tag can not be resolved. Be sure that `KeyboardProvider` is fully mounted before registering handlers. If you think it is a bug in library, please open an issue.\",\n );\n }\n\n ids.push(\n ...Object.keys(handler).map((handlerName) => {\n const eventName = map.get(handlerName as keyof H);\n const functionToCall = handler[handlerName as keyof H];\n\n if (eventName && viewTag) {\n return registerEventHandler(\n (event: Parameters<NonNullable<H[keyof H]>>[0]) => {\n \"worklet\";\n\n functionToCall?.(event);\n },\n eventName,\n viewTag,\n );\n }\n\n return null;\n }),\n );\n };\n\n if (viewTagRef.current) {\n attachWorkletHandlers();\n } else {\n // view may not be mounted yet - defer registration to next event loop\n setImmediate(attachWorkletHandlers);\n }\n\n return () => {\n ids.forEach((id) => (id ? unregisterEventHandler(id) : null));\n };\n };\n\n return onRegisterHandler;\n}\n\n/**\n * TS variant of `useAnimatedValue` hook which is added in RN 0.71\n * A better alternative of storing animated values in refs, since\n * it doesn't recreate a new `Animated.Value` object on every re-render\n * and therefore consumes less memory. We can not use a variant from\n * RN, since this library supports earlier versions of RN.\n *\n * @see https://github.com/facebook/react-native/commit/e22217fe8b9455e32695f88ca835e11442b0a937\n */\nexport function useAnimatedValue(\n initialValue: number,\n config?: Animated.AnimatedConfig,\n): Animated.Value {\n const ref = useRef<Animated.Value | null>(null);\n\n if (ref.current === null) {\n ref.current = new Animated.Value(initialValue, config);\n }\n\n return ref.current;\n}\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,OAAO;AAC9B,SAASC,QAAQ,EAAEC,cAAc,QAAQ,cAAc;AAEvD,SAASC,oBAAoB,EAAEC,sBAAsB,QAAQ,iBAAiB;AAK9E,OAAO,SAASC,2BAA2BA,CAGzCC,GAAyB,EACzBC,UAAqD,EACrD;EACA,MAAMC,iBAAiB,GAAIC,OAAU,IAAK;IACxC,MAAMC,GAAsB,GAAG,EAAE;IACjC,MAAMC,qBAAqB,GAAGA,CAAA,KAAM;MAClC,MAAMC,OAAO,GAAGV,cAAc,CAACK,UAAU,CAACM,OAAO,CAAC;MAElD,IAAIC,OAAO,IAAI,CAACF,OAAO,EAAE;QACvBG,OAAO,CAACC,IAAI,CACV,uPACF,CAAC;MACH;MAEAN,GAAG,CAACO,IAAI,CACN,GAAGC,MAAM,CAACC,IAAI,CAACV,OAAO,CAAC,CAACH,GAAG,CAAEc,WAAW,IAAK;QAC3C,MAAMC,SAAS,GAAGf,GAAG,CAACgB,GAAG,CAACF,WAAsB,CAAC;QACjD,MAAMG,cAAc,GAAGd,OAAO,CAACW,WAAW,CAAY;QAEtD,IAAIC,SAAS,IAAIT,OAAO,EAAE;UACxB,OAAOT,oBAAoB,CACxBqB,KAA6C,IAAK;YACjD,SAAS;;YAETD,cAAc,aAAdA,cAAc,eAAdA,cAAc,CAAGC,KAAK,CAAC;UACzB,CAAC,EACDH,SAAS,EACTT,OACF,CAAC;QACH;QAEA,OAAO,IAAI;MACb,CAAC,CACH,CAAC;IACH,CAAC;IAED,IAAIL,UAAU,CAACM,OAAO,EAAE;MACtBF,qBAAqB,CAAC,CAAC;IACzB,CAAC,MAAM;MACL;MACAc,YAAY,CAACd,qBAAqB,CAAC;IACrC;IAEA,OAAO,MAAM;MACXD,GAAG,CAACgB,OAAO,CAAEC,EAAE,IAAMA,EAAE,GAAGvB,sBAAsB,CAACuB,EAAE,CAAC,GAAG,IAAK,CAAC;IAC/D,CAAC;EACH,CAAC;EAED,OAAOnB,iBAAiB;AAC1B;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASoB,gBAAgBA,CAC9BC,YAAoB,EACpBC,MAAgC,EAChB;EAChB,MAAMC,GAAG,GAAG/B,MAAM,CAAwB,IAAI,CAAC;EAE/C,IAAI+B,GAAG,CAAClB,OAAO,KAAK,IAAI,EAAE;IACxBkB,GAAG,CAAClB,OAAO,GAAG,IAAIZ,QAAQ,CAAC+B,KAAK,CAACH,YAAY,EAAEC,MAAM,CAAC;EACxD;EAEA,OAAOC,GAAG,CAAClB,OAAO;AACpB","ignoreList":[]}
|
package/package.json
CHANGED
package/src/hooks/index.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { useEffect } from "react";
|
|
1
|
+
import { useEffect, useLayoutEffect } from "react";
|
|
2
2
|
|
|
3
3
|
import { KeyboardController } from "../bindings";
|
|
4
4
|
import { AndroidSoftInputModes } from "../constants";
|
|
5
5
|
import { useKeyboardContext } from "../context";
|
|
6
6
|
|
|
7
|
-
import useSyncEffect from "./useSyncEffect";
|
|
8
|
-
|
|
9
7
|
import type { AnimatedContext, ReanimatedContext } from "../context";
|
|
10
8
|
import type { FocusedInputHandler, KeyboardHandler } from "../types";
|
|
11
9
|
import type { DependencyList } from "react";
|
|
@@ -40,7 +38,7 @@ export function useGenericKeyboardHandler(
|
|
|
40
38
|
) {
|
|
41
39
|
const context = useKeyboardContext();
|
|
42
40
|
|
|
43
|
-
|
|
41
|
+
useLayoutEffect(() => {
|
|
44
42
|
const cleanup = context.setKeyboardHandlers(handler);
|
|
45
43
|
|
|
46
44
|
return () => cleanup();
|
|
@@ -73,7 +71,7 @@ export function useFocusedInputHandler(
|
|
|
73
71
|
) {
|
|
74
72
|
const context = useKeyboardContext();
|
|
75
73
|
|
|
76
|
-
|
|
74
|
+
useLayoutEffect(() => {
|
|
77
75
|
const cleanup = context.setInputHandlers(handler);
|
|
78
76
|
|
|
79
77
|
return () => cleanup();
|
package/src/internal.ts
CHANGED
|
@@ -13,25 +13,44 @@ export function useEventHandlerRegistration<
|
|
|
13
13
|
viewTagRef: React.MutableRefObject<ComponentOrHandle>,
|
|
14
14
|
) {
|
|
15
15
|
const onRegisterHandler = (handler: H) => {
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const functionToCall = handler[handlerName as keyof H];
|
|
16
|
+
const ids: (number | null)[] = [];
|
|
17
|
+
const attachWorkletHandlers = () => {
|
|
18
|
+
const viewTag = findNodeHandle(viewTagRef.current);
|
|
20
19
|
|
|
21
|
-
if (
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"worklet";
|
|
25
|
-
|
|
26
|
-
functionToCall?.(event);
|
|
27
|
-
},
|
|
28
|
-
eventName,
|
|
29
|
-
viewTag,
|
|
20
|
+
if (__DEV__ && !viewTag) {
|
|
21
|
+
console.warn(
|
|
22
|
+
"Can not attach worklet handlers for `react-native-keyboard-controller` because view tag can not be resolved. Be sure that `KeyboardProvider` is fully mounted before registering handlers. If you think it is a bug in library, please open an issue.",
|
|
30
23
|
);
|
|
31
24
|
}
|
|
32
25
|
|
|
33
|
-
|
|
34
|
-
|
|
26
|
+
ids.push(
|
|
27
|
+
...Object.keys(handler).map((handlerName) => {
|
|
28
|
+
const eventName = map.get(handlerName as keyof H);
|
|
29
|
+
const functionToCall = handler[handlerName as keyof H];
|
|
30
|
+
|
|
31
|
+
if (eventName && viewTag) {
|
|
32
|
+
return registerEventHandler(
|
|
33
|
+
(event: Parameters<NonNullable<H[keyof H]>>[0]) => {
|
|
34
|
+
"worklet";
|
|
35
|
+
|
|
36
|
+
functionToCall?.(event);
|
|
37
|
+
},
|
|
38
|
+
eventName,
|
|
39
|
+
viewTag,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return null;
|
|
44
|
+
}),
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
if (viewTagRef.current) {
|
|
49
|
+
attachWorkletHandlers();
|
|
50
|
+
} else {
|
|
51
|
+
// view may not be mounted yet - defer registration to next event loop
|
|
52
|
+
setImmediate(attachWorkletHandlers);
|
|
53
|
+
}
|
|
35
54
|
|
|
36
55
|
return () => {
|
|
37
56
|
ids.forEach((id) => (id ? unregisterEventHandler(id) : null));
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
/**
|
|
9
|
-
* @description
|
|
10
|
-
* Equivalent to `useEffect` but will run the effect synchronously, i. e. before render.
|
|
11
|
-
*
|
|
12
|
-
* @param {effect} - imperative function
|
|
13
|
-
* @param {deps} - if present, effect will only activate if the values in the list change
|
|
14
|
-
*
|
|
15
|
-
* @author Kiryl Ziusko
|
|
16
|
-
* @since 1.13.0
|
|
17
|
-
* @version 1.0.0
|
|
18
|
-
*/
|
|
19
|
-
const useSyncEffect = (effect, deps) => {
|
|
20
|
-
const cachedDeps = (0, _react.useRef)(null);
|
|
21
|
-
const areDepsEqual = deps === null || deps === void 0 ? void 0 : deps.every((el, index) => cachedDeps.current && el === cachedDeps.current[index]);
|
|
22
|
-
const cleanupRef = (0, _react.useRef)();
|
|
23
|
-
if (!areDepsEqual || !cachedDeps.current) {
|
|
24
|
-
var _cleanupRef$current;
|
|
25
|
-
(_cleanupRef$current = cleanupRef.current) === null || _cleanupRef$current === void 0 || _cleanupRef$current.call(cleanupRef);
|
|
26
|
-
cleanupRef.current = effect();
|
|
27
|
-
cachedDeps.current = deps;
|
|
28
|
-
}
|
|
29
|
-
(0, _react.useEffect)(() => {
|
|
30
|
-
return () => {
|
|
31
|
-
var _cleanupRef$current2;
|
|
32
|
-
(_cleanupRef$current2 = cleanupRef.current) === null || _cleanupRef$current2 === void 0 || _cleanupRef$current2.call(cleanupRef);
|
|
33
|
-
};
|
|
34
|
-
}, []);
|
|
35
|
-
};
|
|
36
|
-
var _default = exports.default = useSyncEffect;
|
|
37
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","useSyncEffect","effect","deps","cachedDeps","useRef","areDepsEqual","every","el","index","current","cleanupRef","_cleanupRef$current","call","useEffect","_cleanupRef$current2","_default","exports","default"],"sources":["index.ts"],"sourcesContent":["import { useEffect, useRef } from \"react\";\n\nimport type { DependencyList } from \"react\";\n\n/**\n * @description\n * Equivalent to `useEffect` but will run the effect synchronously, i. e. before render.\n *\n * @param {effect} - imperative function\n * @param {deps} - if present, effect will only activate if the values in the list change\n *\n * @author Kiryl Ziusko\n * @since 1.13.0\n * @version 1.0.0\n */\nconst useSyncEffect: typeof useEffect = (effect, deps) => {\n const cachedDeps = useRef<DependencyList | undefined | null>(null);\n const areDepsEqual = deps?.every(\n (el, index) => cachedDeps.current && el === cachedDeps.current[index],\n );\n const cleanupRef = useRef<(() => void) | void>();\n\n if (!areDepsEqual || !cachedDeps.current) {\n cleanupRef.current?.();\n cleanupRef.current = effect();\n cachedDeps.current = deps;\n }\n\n useEffect(() => {\n return () => {\n cleanupRef.current?.();\n };\n }, []);\n};\n\nexport default useSyncEffect;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,aAA+B,GAAGA,CAACC,MAAM,EAAEC,IAAI,KAAK;EACxD,MAAMC,UAAU,GAAG,IAAAC,aAAM,EAAoC,IAAI,CAAC;EAClE,MAAMC,YAAY,GAAGH,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAEI,KAAK,CAC9B,CAACC,EAAE,EAAEC,KAAK,KAAKL,UAAU,CAACM,OAAO,IAAIF,EAAE,KAAKJ,UAAU,CAACM,OAAO,CAACD,KAAK,CACtE,CAAC;EACD,MAAME,UAAU,GAAG,IAAAN,aAAM,EAAsB,CAAC;EAEhD,IAAI,CAACC,YAAY,IAAI,CAACF,UAAU,CAACM,OAAO,EAAE;IAAA,IAAAE,mBAAA;IACxC,CAAAA,mBAAA,GAAAD,UAAU,CAACD,OAAO,cAAAE,mBAAA,eAAlBA,mBAAA,CAAAC,IAAA,CAAAF,UAAqB,CAAC;IACtBA,UAAU,CAACD,OAAO,GAAGR,MAAM,CAAC,CAAC;IAC7BE,UAAU,CAACM,OAAO,GAAGP,IAAI;EAC3B;EAEA,IAAAW,gBAAS,EAAC,MAAM;IACd,OAAO,MAAM;MAAA,IAAAC,oBAAA;MACX,CAAAA,oBAAA,GAAAJ,UAAU,CAACD,OAAO,cAAAK,oBAAA,eAAlBA,oBAAA,CAAAF,IAAA,CAAAF,UAAqB,CAAC;IACxB,CAAC;EACH,CAAC,EAAE,EAAE,CAAC;AACR,CAAC;AAAC,IAAAK,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEajB,aAAa","ignoreList":[]}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef } from "react";
|
|
2
|
-
/**
|
|
3
|
-
* @description
|
|
4
|
-
* Equivalent to `useEffect` but will run the effect synchronously, i. e. before render.
|
|
5
|
-
*
|
|
6
|
-
* @param {effect} - imperative function
|
|
7
|
-
* @param {deps} - if present, effect will only activate if the values in the list change
|
|
8
|
-
*
|
|
9
|
-
* @author Kiryl Ziusko
|
|
10
|
-
* @since 1.13.0
|
|
11
|
-
* @version 1.0.0
|
|
12
|
-
*/
|
|
13
|
-
const useSyncEffect = (effect, deps) => {
|
|
14
|
-
const cachedDeps = useRef(null);
|
|
15
|
-
const areDepsEqual = deps === null || deps === void 0 ? void 0 : deps.every((el, index) => cachedDeps.current && el === cachedDeps.current[index]);
|
|
16
|
-
const cleanupRef = useRef();
|
|
17
|
-
if (!areDepsEqual || !cachedDeps.current) {
|
|
18
|
-
var _cleanupRef$current;
|
|
19
|
-
(_cleanupRef$current = cleanupRef.current) === null || _cleanupRef$current === void 0 || _cleanupRef$current.call(cleanupRef);
|
|
20
|
-
cleanupRef.current = effect();
|
|
21
|
-
cachedDeps.current = deps;
|
|
22
|
-
}
|
|
23
|
-
useEffect(() => {
|
|
24
|
-
return () => {
|
|
25
|
-
var _cleanupRef$current2;
|
|
26
|
-
(_cleanupRef$current2 = cleanupRef.current) === null || _cleanupRef$current2 === void 0 || _cleanupRef$current2.call(cleanupRef);
|
|
27
|
-
};
|
|
28
|
-
}, []);
|
|
29
|
-
};
|
|
30
|
-
export default useSyncEffect;
|
|
31
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["useEffect","useRef","useSyncEffect","effect","deps","cachedDeps","areDepsEqual","every","el","index","current","cleanupRef","_cleanupRef$current","call","_cleanupRef$current2"],"sources":["index.ts"],"sourcesContent":["import { useEffect, useRef } from \"react\";\n\nimport type { DependencyList } from \"react\";\n\n/**\n * @description\n * Equivalent to `useEffect` but will run the effect synchronously, i. e. before render.\n *\n * @param {effect} - imperative function\n * @param {deps} - if present, effect will only activate if the values in the list change\n *\n * @author Kiryl Ziusko\n * @since 1.13.0\n * @version 1.0.0\n */\nconst useSyncEffect: typeof useEffect = (effect, deps) => {\n const cachedDeps = useRef<DependencyList | undefined | null>(null);\n const areDepsEqual = deps?.every(\n (el, index) => cachedDeps.current && el === cachedDeps.current[index],\n );\n const cleanupRef = useRef<(() => void) | void>();\n\n if (!areDepsEqual || !cachedDeps.current) {\n cleanupRef.current?.();\n cleanupRef.current = effect();\n cachedDeps.current = deps;\n }\n\n useEffect(() => {\n return () => {\n cleanupRef.current?.();\n };\n }, []);\n};\n\nexport default useSyncEffect;\n"],"mappings":"AAAA,SAASA,SAAS,EAAEC,MAAM,QAAQ,OAAO;AAIzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,aAA+B,GAAGA,CAACC,MAAM,EAAEC,IAAI,KAAK;EACxD,MAAMC,UAAU,GAAGJ,MAAM,CAAoC,IAAI,CAAC;EAClE,MAAMK,YAAY,GAAGF,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAEG,KAAK,CAC9B,CAACC,EAAE,EAAEC,KAAK,KAAKJ,UAAU,CAACK,OAAO,IAAIF,EAAE,KAAKH,UAAU,CAACK,OAAO,CAACD,KAAK,CACtE,CAAC;EACD,MAAME,UAAU,GAAGV,MAAM,CAAsB,CAAC;EAEhD,IAAI,CAACK,YAAY,IAAI,CAACD,UAAU,CAACK,OAAO,EAAE;IAAA,IAAAE,mBAAA;IACxC,CAAAA,mBAAA,GAAAD,UAAU,CAACD,OAAO,cAAAE,mBAAA,eAAlBA,mBAAA,CAAAC,IAAA,CAAAF,UAAqB,CAAC;IACtBA,UAAU,CAACD,OAAO,GAAGP,MAAM,CAAC,CAAC;IAC7BE,UAAU,CAACK,OAAO,GAAGN,IAAI;EAC3B;EAEAJ,SAAS,CAAC,MAAM;IACd,OAAO,MAAM;MAAA,IAAAc,oBAAA;MACX,CAAAA,oBAAA,GAAAH,UAAU,CAACD,OAAO,cAAAI,oBAAA,eAAlBA,oBAAA,CAAAD,IAAA,CAAAF,UAAqB,CAAC;IACxB,CAAC;EACH,CAAC,EAAE,EAAE,CAAC;AACR,CAAC;AAED,eAAeT,aAAa","ignoreList":[]}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { useEffect } from "react";
|
|
2
|
-
/**
|
|
3
|
-
* @description
|
|
4
|
-
* Equivalent to `useEffect` but will run the effect synchronously, i. e. before render.
|
|
5
|
-
*
|
|
6
|
-
* @param {effect} - imperative function
|
|
7
|
-
* @param {deps} - if present, effect will only activate if the values in the list change
|
|
8
|
-
*
|
|
9
|
-
* @author Kiryl Ziusko
|
|
10
|
-
* @since 1.13.0
|
|
11
|
-
* @version 1.0.0
|
|
12
|
-
*/
|
|
13
|
-
declare const useSyncEffect: typeof useEffect;
|
|
14
|
-
export default useSyncEffect;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef } from "react";
|
|
2
|
-
|
|
3
|
-
import type { DependencyList } from "react";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @description
|
|
7
|
-
* Equivalent to `useEffect` but will run the effect synchronously, i. e. before render.
|
|
8
|
-
*
|
|
9
|
-
* @param {effect} - imperative function
|
|
10
|
-
* @param {deps} - if present, effect will only activate if the values in the list change
|
|
11
|
-
*
|
|
12
|
-
* @author Kiryl Ziusko
|
|
13
|
-
* @since 1.13.0
|
|
14
|
-
* @version 1.0.0
|
|
15
|
-
*/
|
|
16
|
-
const useSyncEffect: typeof useEffect = (effect, deps) => {
|
|
17
|
-
const cachedDeps = useRef<DependencyList | undefined | null>(null);
|
|
18
|
-
const areDepsEqual = deps?.every(
|
|
19
|
-
(el, index) => cachedDeps.current && el === cachedDeps.current[index],
|
|
20
|
-
);
|
|
21
|
-
const cleanupRef = useRef<(() => void) | void>();
|
|
22
|
-
|
|
23
|
-
if (!areDepsEqual || !cachedDeps.current) {
|
|
24
|
-
cleanupRef.current?.();
|
|
25
|
-
cleanupRef.current = effect();
|
|
26
|
-
cachedDeps.current = deps;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
useEffect(() => {
|
|
30
|
-
return () => {
|
|
31
|
-
cleanupRef.current?.();
|
|
32
|
-
};
|
|
33
|
-
}, []);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export default useSyncEffect;
|