react-native-keyboard-controller 1.4.1 → 1.4.3

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.
Files changed (37) hide show
  1. package/android/src/fabric/java/com/reactnativekeyboardcontroller/KeyboardControllerModule.kt +1 -0
  2. package/android/src/fabric/java/com/reactnativekeyboardcontroller/KeyboardControllerViewManager.kt +1 -0
  3. package/android/src/fabric/java/com/reactnativekeyboardcontroller/StatusBarManagerCompatModule.kt +3 -2
  4. package/android/src/main/java/com/reactnativekeyboardcontroller/KeyboardAnimationCallback.kt +8 -16
  5. package/android/src/main/java/com/reactnativekeyboardcontroller/KeyboardControllerPackage.kt +8 -6
  6. package/android/src/main/java/com/reactnativekeyboardcontroller/extensions/Float.kt +8 -0
  7. package/android/src/main/java/com/reactnativekeyboardcontroller/extensions/View.kt +29 -0
  8. package/android/src/main/java/com/reactnativekeyboardcontroller/{KeyboardControllerViewManagerImpl.kt → managers/KeyboardControllerViewManagerImpl.kt} +16 -10
  9. package/android/src/main/java/com/reactnativekeyboardcontroller/{KeyboardControllerModuleImpl.kt → modules/KeyboardControllerModuleImpl.kt} +1 -1
  10. package/android/src/main/java/com/reactnativekeyboardcontroller/{StatusBarManagerCompatImpl.kt → modules/StatusBarManagerCompatModuleImpl.kt} +3 -3
  11. package/android/src/main/java/com/reactnativekeyboardcontroller/{EdgeToEdgeReactViewGroup.kt → views/EdgeToEdgeReactViewGroup.kt} +2 -2
  12. package/android/src/paper/java/com/reactnativekeyboardcontroller/KeyboardControllerModule.kt +1 -0
  13. package/android/src/paper/java/com/reactnativekeyboardcontroller/KeyboardControllerViewManager.kt +1 -0
  14. package/android/src/paper/java/com/reactnativekeyboardcontroller/StatusBarManagerCompatModule.kt +3 -2
  15. package/ios/.swiftlint.yml +1 -0
  16. package/jest/index.js +35 -0
  17. package/lib/commonjs/animated.js +3 -5
  18. package/lib/commonjs/animated.js.map +1 -1
  19. package/lib/commonjs/internal.js +23 -0
  20. package/lib/commonjs/internal.js.map +1 -1
  21. package/lib/commonjs/native.js.map +1 -1
  22. package/lib/commonjs/types.js.map +1 -1
  23. package/lib/module/animated.js +5 -5
  24. package/lib/module/animated.js.map +1 -1
  25. package/lib/module/internal.js +20 -0
  26. package/lib/module/internal.js.map +1 -1
  27. package/lib/module/native.js.map +1 -1
  28. package/lib/module/types.js.map +1 -1
  29. package/lib/typescript/animated.d.ts +0 -6
  30. package/lib/typescript/internal.d.ts +11 -0
  31. package/lib/typescript/native.d.ts +3 -2
  32. package/lib/typescript/types.d.ts +1 -1
  33. package/package.json +6 -2
  34. package/src/animated.tsx +9 -5
  35. package/src/internal.ts +23 -0
  36. package/src/native.ts +2 -1
  37. package/src/types.ts +1 -1
@@ -1,6 +1,7 @@
1
1
  package com.reactnativekeyboardcontroller
2
2
 
3
3
  import com.facebook.react.bridge.ReactApplicationContext
4
+ import com.reactnativekeyboardcontroller.modules.KeyboardControllerModuleImpl
4
5
 
5
6
  class KeyboardControllerModule(mReactContext: ReactApplicationContext) : NativeKeyboardControllerSpec(mReactContext) {
6
7
  private val module = KeyboardControllerModuleImpl(mReactContext)
@@ -7,6 +7,7 @@ import com.facebook.react.viewmanagers.KeyboardControllerViewManagerDelegate
7
7
  import com.facebook.react.viewmanagers.KeyboardControllerViewManagerInterface
8
8
  import com.facebook.react.views.view.ReactViewGroup
9
9
  import com.facebook.react.views.view.ReactViewManager
10
+ import com.reactnativekeyboardcontroller.managers.KeyboardControllerViewManagerImpl
10
11
 
11
12
  class KeyboardControllerViewManager(mReactContext: ReactApplicationContext) : ReactViewManager(), KeyboardControllerViewManagerInterface<ReactViewGroup> {
12
13
  private val manager = KeyboardControllerViewManagerImpl(mReactContext)
@@ -1,11 +1,12 @@
1
1
  package com.reactnativekeyboardcontroller
2
2
 
3
3
  import com.facebook.react.bridge.ReactApplicationContext
4
+ import com.reactnativekeyboardcontroller.modules.StatusBarManagerCompatModuleImpl
4
5
 
5
6
  class StatusBarManagerCompatModule(private val mReactContext: ReactApplicationContext) : NativeStatusBarManagerCompatSpec(mReactContext) {
6
- private val module = StatusBarManagerCompatImpl(mReactContext)
7
+ private val module = StatusBarManagerCompatModuleImpl(mReactContext)
7
8
 
8
- override fun getName(): String = StatusBarManagerCompatImpl.NAME
9
+ override fun getName(): String = StatusBarManagerCompatModuleImpl.NAME
9
10
 
10
11
  override fun setHidden(hidden: Boolean) {
11
12
  module.setHidden(hidden)
@@ -1,7 +1,6 @@
1
1
  package com.reactnativekeyboardcontroller
2
2
 
3
3
  import android.animation.ValueAnimator
4
- import android.content.Context
5
4
  import android.os.Build
6
5
  import android.util.Log
7
6
  import android.view.View
@@ -12,30 +11,23 @@ import androidx.core.view.ViewCompat
12
11
  import androidx.core.view.WindowInsetsAnimationCompat
13
12
  import androidx.core.view.WindowInsetsCompat
14
13
  import com.facebook.react.bridge.Arguments
15
- import com.facebook.react.bridge.ReactApplicationContext
16
14
  import com.facebook.react.bridge.WritableMap
17
15
  import com.facebook.react.modules.core.DeviceEventManagerModule
16
+ import com.facebook.react.uimanager.ThemedReactContext
18
17
  import com.facebook.react.uimanager.UIManagerHelper
19
18
  import com.facebook.react.uimanager.events.Event
20
19
  import com.facebook.react.uimanager.events.EventDispatcher
21
20
  import com.facebook.react.views.view.ReactViewGroup
22
21
  import com.reactnativekeyboardcontroller.events.KeyboardTransitionEvent
23
-
24
- fun toDp(px: Float, context: Context?): Int {
25
- if (context == null) {
26
- return 0
27
- }
28
-
29
- return (px / context.resources.displayMetrics.density).toInt()
30
- }
22
+ import com.reactnativekeyboardcontroller.extensions.dp
31
23
 
32
24
  class KeyboardAnimationCallback(
33
25
  val view: ReactViewGroup,
34
26
  val persistentInsetTypes: Int,
35
27
  val deferredInsetTypes: Int,
36
28
  dispatchMode: Int = DISPATCH_MODE_STOP,
37
- val context: ReactApplicationContext?,
38
- val onApplyWindowInsetsListener: OnApplyWindowInsetsListener
29
+ val context: ThemedReactContext?,
30
+ val onApplyWindowInsetsListener: OnApplyWindowInsetsListener,
39
31
  ) : WindowInsetsAnimationCompat.Callback(dispatchMode), OnApplyWindowInsetsListener {
40
32
  private val TAG = KeyboardAnimationCallback::class.qualifiedName
41
33
  private var persistentKeyboardHeight = 0
@@ -96,7 +88,7 @@ class KeyboardAnimationCallback(
96
88
 
97
89
  override fun onStart(
98
90
  animation: WindowInsetsAnimationCompat,
99
- bounds: WindowInsetsAnimationCompat.BoundsCompat
91
+ bounds: WindowInsetsAnimationCompat.BoundsCompat,
100
92
  ): WindowInsetsAnimationCompat.BoundsCompat {
101
93
  isTransitioning = true
102
94
  isKeyboardVisible = isKeyboardVisible()
@@ -117,7 +109,7 @@ class KeyboardAnimationCallback(
117
109
 
118
110
  override fun onProgress(
119
111
  insets: WindowInsetsCompat,
120
- runningAnimations: List<WindowInsetsAnimationCompat>
112
+ runningAnimations: List<WindowInsetsAnimationCompat>,
121
113
  ): WindowInsetsCompat {
122
114
  // onProgress() is called when any of the running animations progress...
123
115
 
@@ -132,7 +124,7 @@ class KeyboardAnimationCallback(
132
124
  Insets.max(it, Insets.NONE)
133
125
  }
134
126
  val diffY = (diff.bottom - diff.top).toFloat()
135
- val height = toDp(diffY, context)
127
+ val height = diffY.dp
136
128
 
137
129
  var progress = 0.0
138
130
  try {
@@ -168,7 +160,7 @@ class KeyboardAnimationCallback(
168
160
  val navigationBar = insets?.getInsets(WindowInsetsCompat.Type.navigationBars())?.bottom ?: 0
169
161
 
170
162
  // on hide it will be negative value, so we are using max function
171
- return Math.max(toDp((keyboardHeight - navigationBar).toFloat(), context), 0)
163
+ return Math.max((keyboardHeight - navigationBar).toFloat().dp, 0)
172
164
  }
173
165
 
174
166
  private fun sendEventToJS(event: Event<*>) {
@@ -7,6 +7,8 @@ import com.facebook.react.bridge.ReactApplicationContext
7
7
  import com.facebook.react.module.model.ReactModuleInfo
8
8
  import com.facebook.react.module.model.ReactModuleInfoProvider
9
9
  import com.facebook.react.uimanager.ViewManager
10
+ import com.reactnativekeyboardcontroller.modules.KeyboardControllerModuleImpl
11
+ import com.reactnativekeyboardcontroller.modules.StatusBarManagerCompatModuleImpl
10
12
 
11
13
  class KeyboardControllerPackage : TurboReactPackage() {
12
14
  @Nullable
@@ -15,7 +17,7 @@ class KeyboardControllerPackage : TurboReactPackage() {
15
17
  KeyboardControllerModuleImpl.NAME -> {
16
18
  KeyboardControllerModule(reactContext)
17
19
  }
18
- StatusBarManagerCompatImpl.NAME -> {
20
+ StatusBarManagerCompatModuleImpl.NAME -> {
19
21
  StatusBarManagerCompatModule(reactContext)
20
22
  }
21
23
  else -> {
@@ -36,16 +38,16 @@ class KeyboardControllerPackage : TurboReactPackage() {
36
38
  false, // needsEagerInit
37
39
  true, // hasConstants
38
40
  false, // isCxxModule
39
- isTurboModule // isTurboModule
41
+ isTurboModule, // isTurboModule
40
42
  )
41
- moduleInfos[StatusBarManagerCompatImpl.NAME] = ReactModuleInfo(
42
- StatusBarManagerCompatImpl.NAME,
43
- StatusBarManagerCompatImpl.NAME,
43
+ moduleInfos[StatusBarManagerCompatModuleImpl.NAME] = ReactModuleInfo(
44
+ StatusBarManagerCompatModuleImpl.NAME,
45
+ StatusBarManagerCompatModuleImpl.NAME,
44
46
  false, // canOverrideExistingModule
45
47
  false, // needsEagerInit
46
48
  true, // hasConstants
47
49
  false, // isCxxModule
48
- isTurboModule // isTurboModule
50
+ isTurboModule, // isTurboModule
49
51
  )
50
52
  moduleInfos
51
53
  }
@@ -0,0 +1,8 @@
1
+ package com.reactnativekeyboardcontroller.extensions
2
+
3
+ import android.content.res.Resources
4
+
5
+ val Float.dp: Int
6
+ get() = (this / Resources.getSystem().displayMetrics.density).toInt()
7
+ val Float.px: Int
8
+ get() = (this * Resources.getSystem().displayMetrics.density).toInt()
@@ -0,0 +1,29 @@
1
+ package com.reactnativekeyboardcontroller.extensions
2
+
3
+ import android.os.Build
4
+ import android.view.View
5
+
6
+ /**
7
+ * Call this everytime when using [ViewCompat.setOnApplyWindowInsetsListener]
8
+ * to ensure that insets are always received.
9
+ * @see https://stackoverflow.com/a/61909205/9272042
10
+ */
11
+ fun View.requestApplyInsetsWhenAttached() {
12
+ // https://chris.banes.dev/2019/04/12/insets-listeners-to-layouts/
13
+ if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT && isAttachedToWindow) {
14
+ // We're already attached, just request as normal
15
+ requestApplyInsets()
16
+ } else {
17
+ // We're not attached to the hierarchy, add a listener to request when we are
18
+ addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener {
19
+ override fun onViewAttachedToWindow(v: View) {
20
+ v.removeOnAttachStateChangeListener(this)
21
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
22
+ v.requestApplyInsets()
23
+ }
24
+ }
25
+
26
+ override fun onViewDetachedFromWindow(v: View) = Unit
27
+ })
28
+ }
29
+ }
@@ -1,4 +1,4 @@
1
- package com.reactnativekeyboardcontroller
1
+ package com.reactnativekeyboardcontroller.managers
2
2
 
3
3
  import android.util.Log
4
4
  import androidx.appcompat.widget.FitWindowsLinearLayout
@@ -9,15 +9,18 @@ import com.facebook.react.bridge.ReactApplicationContext
9
9
  import com.facebook.react.common.MapBuilder
10
10
  import com.facebook.react.uimanager.ThemedReactContext
11
11
  import com.facebook.react.views.view.ReactViewGroup
12
+ import com.reactnativekeyboardcontroller.KeyboardAnimationCallback
13
+ import com.reactnativekeyboardcontroller.R
14
+ import com.reactnativekeyboardcontroller.extensions.requestApplyInsetsWhenAttached
15
+ import com.reactnativekeyboardcontroller.views.EdgeToEdgeReactViewGroup
12
16
 
13
- class KeyboardControllerViewManagerImpl(reactContext: ReactApplicationContext) {
17
+ class KeyboardControllerViewManagerImpl(private val mReactContext: ReactApplicationContext) {
14
18
  private val TAG = KeyboardControllerViewManagerImpl::class.qualifiedName
15
- private var mReactContext = reactContext
16
19
  private var isStatusBarTranslucent = false
17
20
 
18
21
  fun createViewInstance(reactContext: ThemedReactContext): ReactViewGroup {
19
22
  val view = EdgeToEdgeReactViewGroup(reactContext)
20
- val activity = mReactContext.currentActivity
23
+ val activity = reactContext.currentActivity
21
24
 
22
25
  if (activity == null) {
23
26
  Log.w(TAG, "Can not setup keyboard animation listener, since `currentActivity` is null")
@@ -31,22 +34,25 @@ class KeyboardControllerViewManagerImpl(reactContext: ReactApplicationContext) {
31
34
  // We explicitly allow dispatch to continue down to binding.messageHolder's
32
35
  // child views, so that step 2.5 below receives the call
33
36
  dispatchMode = WindowInsetsAnimationCompat.Callback.DISPATCH_MODE_CONTINUE_ON_SUBTREE,
34
- context = mReactContext,
37
+ context = reactContext,
35
38
  onApplyWindowInsetsListener = { v, insets ->
36
39
  val content =
37
- mReactContext.currentActivity?.window?.decorView?.rootView?.findViewById<FitWindowsLinearLayout>(
38
- R.id.action_bar_root
40
+ reactContext.currentActivity?.window?.decorView?.rootView?.findViewById<FitWindowsLinearLayout>(
41
+ R.id.action_bar_root,
39
42
  )
40
43
  content?.setPadding(
41
- 0, if (this.isStatusBarTranslucent) 0 else insets?.getInsets(WindowInsetsCompat.Type.systemBars())?.top ?: 0, 0,
42
- insets?.getInsets(WindowInsetsCompat.Type.navigationBars())?.bottom ?: 0
44
+ 0,
45
+ if (this.isStatusBarTranslucent) 0 else insets?.getInsets(WindowInsetsCompat.Type.systemBars())?.top ?: 0,
46
+ 0,
47
+ insets?.getInsets(WindowInsetsCompat.Type.navigationBars())?.bottom ?: 0,
43
48
  )
44
49
 
45
50
  insets
46
- }
51
+ },
47
52
  )
48
53
  ViewCompat.setWindowInsetsAnimationCallback(view, callback)
49
54
  ViewCompat.setOnApplyWindowInsetsListener(view, callback)
55
+ view.requestApplyInsetsWhenAttached()
50
56
 
51
57
  return view
52
58
  }
@@ -1,4 +1,4 @@
1
- package com.reactnativekeyboardcontroller
1
+ package com.reactnativekeyboardcontroller.modules
2
2
 
3
3
  import android.view.WindowManager
4
4
  import com.facebook.react.bridge.ReactApplicationContext
@@ -1,4 +1,4 @@
1
- package com.reactnativekeyboardcontroller
1
+ package com.reactnativekeyboardcontroller.modules
2
2
 
3
3
  import android.animation.ArgbEvaluator
4
4
  import android.animation.ValueAnimator
@@ -10,8 +10,8 @@ import androidx.core.view.WindowInsetsControllerCompat
10
10
  import com.facebook.react.bridge.ReactApplicationContext
11
11
  import com.facebook.react.bridge.UiThreadUtil
12
12
 
13
- class StatusBarManagerCompatImpl(private val mReactContext: ReactApplicationContext) {
14
- private val TAG = StatusBarManagerCompatImpl::class.qualifiedName
13
+ class StatusBarManagerCompatModuleImpl(private val mReactContext: ReactApplicationContext) {
14
+ private val TAG = StatusBarManagerCompatModuleImpl::class.qualifiedName
15
15
  private var controller: WindowInsetsControllerCompat? = null
16
16
 
17
17
  fun setHidden(hidden: Boolean) {
@@ -1,4 +1,4 @@
1
- package com.reactnativekeyboardcontroller
1
+ package com.reactnativekeyboardcontroller.views
2
2
 
3
3
  import android.annotation.SuppressLint
4
4
  import androidx.core.view.WindowCompat
@@ -13,7 +13,7 @@ class EdgeToEdgeReactViewGroup(private val reactContext: ThemedReactContext) : R
13
13
  reactContext.currentActivity?.let {
14
14
  WindowCompat.setDecorFitsSystemWindows(
15
15
  it.window,
16
- false
16
+ false,
17
17
  )
18
18
  }
19
19
  }
@@ -3,6 +3,7 @@ package com.reactnativekeyboardcontroller
3
3
  import com.facebook.react.bridge.ReactApplicationContext
4
4
  import com.facebook.react.bridge.ReactContextBaseJavaModule
5
5
  import com.facebook.react.bridge.ReactMethod
6
+ import com.reactnativekeyboardcontroller.modules.KeyboardControllerModuleImpl
6
7
 
7
8
  class KeyboardControllerModule(mReactContext: ReactApplicationContext) : ReactContextBaseJavaModule(mReactContext) {
8
9
  private val module = KeyboardControllerModuleImpl(mReactContext)
@@ -5,6 +5,7 @@ import com.facebook.react.uimanager.ThemedReactContext
5
5
  import com.facebook.react.uimanager.annotations.ReactProp
6
6
  import com.facebook.react.views.view.ReactViewGroup
7
7
  import com.facebook.react.views.view.ReactViewManager
8
+ import com.reactnativekeyboardcontroller.managers.KeyboardControllerViewManagerImpl
8
9
 
9
10
  class KeyboardControllerViewManager(mReactContext: ReactApplicationContext) : ReactViewManager() {
10
11
  private val manager = KeyboardControllerViewManagerImpl(mReactContext)
@@ -5,11 +5,12 @@ import androidx.annotation.RequiresApi
5
5
  import com.facebook.react.bridge.ReactApplicationContext
6
6
  import com.facebook.react.bridge.ReactContextBaseJavaModule
7
7
  import com.facebook.react.bridge.ReactMethod
8
+ import com.reactnativekeyboardcontroller.modules.StatusBarManagerCompatModuleImpl
8
9
 
9
10
  class StatusBarManagerCompatModule(private val mReactContext: ReactApplicationContext) : ReactContextBaseJavaModule(mReactContext) {
10
- private val module = StatusBarManagerCompatImpl(mReactContext)
11
+ private val module = StatusBarManagerCompatModuleImpl(mReactContext)
11
12
 
12
- override fun getName(): String = StatusBarManagerCompatImpl.NAME
13
+ override fun getName(): String = StatusBarManagerCompatModuleImpl.NAME
13
14
 
14
15
  @ReactMethod
15
16
  private fun setHidden(hidden: Boolean) {
@@ -1,5 +1,6 @@
1
1
  disabled_rules:
2
2
  - trailing_comma
3
+ - for_where
3
4
 
4
5
  line_length:
5
6
  warning: 120
package/jest/index.js ADDED
@@ -0,0 +1,35 @@
1
+ import { Animated } from 'react-native';
2
+
3
+ const values = {
4
+ animated: {
5
+ progress: new Animated.Value(0),
6
+ height: new Animated.Value(0),
7
+ },
8
+ reanimated: {
9
+ progress: { value: 0 },
10
+ height: { value: 0 },
11
+ },
12
+ };
13
+
14
+ const mock = {
15
+ // hooks
16
+ useKeyboardAnimation: jest.fn().mockReturnValue(values.animated),
17
+ useReanimatedKeyboardAnimation: jest.fn().mockReturnValue(values.reanimated),
18
+ useResizeMode: jest.fn(),
19
+ useGenericKeyboardHandler: jest.fn(),
20
+ useKeyboardHandler: jest.fn(),
21
+ // modules
22
+ KeyboardController: {
23
+ setInputMode: jest.fn(),
24
+ setDefaultMode: jest.fn(),
25
+ },
26
+ KeyboardEvents: {
27
+ addListener: jest.fn(() => ({ remove: jest.fn() })),
28
+ },
29
+ // views
30
+ KeyboardControllerView: 'KeyboardControllerView',
31
+ // providers
32
+ KeyboardProvider: 'KeyboardProvider',
33
+ };
34
+
35
+ module.exports = mock;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.styles = exports.KeyboardProvider = void 0;
6
+ exports.KeyboardProvider = void 0;
7
7
 
8
8
  var _react = _interopRequireWildcard(require("react"));
9
9
 
@@ -33,16 +33,14 @@ const styles = _reactNative.StyleSheet.create({
33
33
  }
34
34
  });
35
35
 
36
- exports.styles = styles;
37
-
38
36
  const KeyboardProvider = _ref => {
39
37
  let {
40
38
  children,
41
39
  statusBarTranslucent
42
40
  } = _ref;
43
41
  // animated values
44
- const progress = (0, _react.useRef)(new _reactNative.Animated.Value(0)).current;
45
- const height = (0, _react.useRef)(new _reactNative.Animated.Value(0)).current; // shared values
42
+ const progress = (0, _internal.useAnimatedValue)(0);
43
+ const height = (0, _internal.useAnimatedValue)(0); // shared values
46
44
 
47
45
  const progressSV = (0, _reactNativeReanimated.useSharedValue)(0);
48
46
  const heightSV = (0, _reactNativeReanimated.useSharedValue)(0);
@@ -1 +1 @@
1
- {"version":3,"names":["KeyboardControllerViewAnimated","Reanimated","createAnimatedComponent","Animated","KeyboardControllerView","styles","StyleSheet","create","container","flex","hidden","display","position","KeyboardProvider","children","statusBarTranslucent","progress","useRef","Value","current","height","progressSV","useSharedValue","heightSV","setHandlers","broadcast","useSharedHandlers","context","useMemo","animated","multiply","reanimated","style","transform","translateX","translateY","onKeyboardMove","event","nativeEvent","useNativeDriver","updateSharedValues","platforms","includes","Platform","OS","value","handler","useAnimatedKeyboardHandler","onKeyboardMoveStart","onKeyboardMoveEnd","undefined"],"sources":["animated.tsx"],"sourcesContent":["import React, { useMemo, useRef } from 'react';\nimport { Animated, Platform, StyleSheet, ViewStyle } from 'react-native';\nimport Reanimated, { useSharedValue } from 'react-native-reanimated';\n\nimport { KeyboardContext } from './context';\nimport { useAnimatedKeyboardHandler, useSharedHandlers } from './internal';\nimport { KeyboardControllerView } from './native';\n\nimport type {\n KeyboardControllerProps,\n KeyboardHandler,\n NativeEvent,\n} from './types';\n\nconst KeyboardControllerViewAnimated = Reanimated.createAnimatedComponent(\n Animated.createAnimatedComponent(\n KeyboardControllerView\n ) as React.FC<KeyboardControllerProps>\n);\n\ntype Styles = {\n container: ViewStyle;\n hidden: ViewStyle;\n};\n\nexport const styles = StyleSheet.create<Styles>({\n container: {\n flex: 1,\n },\n hidden: {\n display: 'none',\n position: 'absolute',\n },\n});\n\ntype KeyboardProviderProps = {\n children: React.ReactNode;\n /**\n * Set the value to `true`, if you use translucent status bar on Android.\n * If you already control status bar translucency via `react-native-screens`\n * or `StatusBar` component from `react-native`, you can ignore it.\n * Defaults to `false`.\n *\n * @see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/14\n * @platform android\n */\n statusBarTranslucent?: boolean;\n};\n\nexport const KeyboardProvider = ({\n children,\n statusBarTranslucent,\n}: KeyboardProviderProps) => {\n // animated values\n const progress = useRef(new Animated.Value(0)).current;\n const height = useRef(new Animated.Value(0)).current;\n // shared values\n const progressSV = useSharedValue(0);\n const heightSV = useSharedValue(0);\n const { setHandlers, broadcast } = useSharedHandlers<KeyboardHandler>();\n // memo\n const context = useMemo(\n () => ({\n animated: { progress: progress, height: Animated.multiply(height, -1) },\n reanimated: { progress: progressSV, height: heightSV },\n setHandlers,\n }),\n []\n );\n const style = useMemo(\n () => [\n styles.hidden,\n { transform: [{ translateX: height }, { translateY: progress }] },\n ],\n []\n );\n const onKeyboardMove = useMemo(\n () =>\n Animated.event(\n [\n {\n nativeEvent: {\n progress,\n height,\n },\n },\n ],\n { useNativeDriver: true }\n ),\n []\n );\n // handlers\n const updateSharedValues = (event: NativeEvent, platforms: string[]) => {\n 'worklet';\n\n if (platforms.includes(Platform.OS)) {\n progressSV.value = event.progress;\n heightSV.value = -event.height;\n }\n };\n const handler = useAnimatedKeyboardHandler(\n {\n onKeyboardMoveStart: (event: NativeEvent) => {\n 'worklet';\n\n broadcast('onStart', event);\n updateSharedValues(event, ['ios']);\n },\n onKeyboardMove: (event: NativeEvent) => {\n 'worklet';\n\n broadcast('onMove', event);\n updateSharedValues(event, ['android']);\n },\n onKeyboardMoveEnd: (event: NativeEvent) => {\n 'worklet';\n\n broadcast('onEnd', event);\n },\n },\n []\n );\n\n return (\n <KeyboardContext.Provider value={context}>\n <KeyboardControllerViewAnimated\n onKeyboardMoveReanimated={handler}\n onKeyboardMoveStart={Platform.OS === 'ios' ? onKeyboardMove : undefined}\n onKeyboardMove={Platform.OS === 'android' ? onKeyboardMove : undefined}\n statusBarTranslucent={statusBarTranslucent}\n style={styles.container}\n >\n <>\n <Animated.View\n // we are using this small hack, because if the component (where\n // animated value has been used) is unmounted, then animation will\n // stop receiving events (seems like it's react-native optimization).\n // So we need to keep a reference to the animated value, to keep it's\n // always mounted (keep a reference to an animated value).\n //\n // To test why it's needed, try to open screen which consumes Animated.Value\n // then close it and open it again (for example 'Animated transition').\n style={style}\n />\n {children}\n </>\n </KeyboardControllerViewAnimated>\n </KeyboardContext.Provider>\n );\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAEA;;AACA;;AACA;;;;;;AAQA,MAAMA,8BAA8B,GAAGC,8BAAA,CAAWC,uBAAX,CACrCC,qBAAA,CAASD,uBAAT,CACEE,8BADF,CADqC,CAAvC;;AAWO,MAAMC,MAAM,GAAGC,uBAAA,CAAWC,MAAX,CAA0B;EAC9CC,SAAS,EAAE;IACTC,IAAI,EAAE;EADG,CADmC;EAI9CC,MAAM,EAAE;IACNC,OAAO,EAAE,MADH;IAENC,QAAQ,EAAE;EAFJ;AAJsC,CAA1B,CAAf;;;;AAwBA,MAAMC,gBAAgB,GAAG,QAGH;EAAA,IAHI;IAC/BC,QAD+B;IAE/BC;EAF+B,CAGJ;EAC3B;EACA,MAAMC,QAAQ,GAAG,IAAAC,aAAA,EAAO,IAAId,qBAAA,CAASe,KAAb,CAAmB,CAAnB,CAAP,EAA8BC,OA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AAU,CAACwB,KAAX,GAAmBR,KAAK,CAACrB,QAAzB;MACAO,QAAQ,CAACsB,KAAT,GAAiB,CAACR,KAAK,CAACjB,MAAxB;IACD;EACF,CAPD;;EAQA,MAAM0B,OAAO,GAAG,IAAAC,oCAAA,EACd;IACEC,mBAAmB,EAAGX,KAAD,IAAwB;MAC3C;;MAEAZ,SAAS,CAAC,SAAD,EAAYY,KAAZ,CAAT;MACAG,kBAAkB,CAACH,KAAD,EAAQ,CAAC,KAAD,CAAR,CAAlB;IACD,CANH;IAOED,cAAc,EAAGC,KAAD,IAAwB;MACtC;;MAEAZ,SAAS,CAAC,QAAD,EAAWY,KAAX,CAAT;MACAG,kBAAkB,CAACH,KAAD,EAAQ,CAAC,SAAD,CAAR,CAAlB;IACD,CAZH;IAaEY,iBAAiB,EAAGZ,KAAD,IAAwB;MACzC;;MAEAZ,SAAS,CAAC,OAAD,EAAUY,KAAV,CAAT;IACD;EAjBH,CADc,EAoBd,EApBc,CAAhB;EAuBA,oBACE,6BAAC,wBAAD,CAAiB,QAAjB;IAA0B,KAAK,EAAEV;EAAjC,gBACE,6BAAC,8BAAD;IACE,wBAAwB,EAAEmB,OAD5B;IAEE,mBAAmB,EAAEH,qBAAA,CAASC,EAAT,KAAgB,KAAhB,GAAwBR,cAAxB,GAAyCc,SAFhE;IAGE,cAAc,EAAEP,qBAAA,CAASC,EAAT,KAAgB,SAAhB,GAA4BR,cAA5B,GAA6Cc,SAH/D;IAIE,oBAAoB,EAAEnC,oBAJxB;IAKE,KAAK,EAAEV,MAAM,CAACG;EALhB,gBAOE,yEACE,6BAAC,qBAAD,CAAU,IAAV;IACE;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,KAAK,EAAEwB;EATT,EADF,EAYGlB,QAZH,CAPF,CADF,CADF;AA0BD,CApGM"}
1
+ {"version":3,"names":["KeyboardControllerViewAnimated","Reanimated","createAnimatedComponent","Animated","KeyboardControllerView","styles","StyleSheet","create","container","flex","hidden","display","position","KeyboardProvider","children","statusBarTranslucent","progress","useAnimatedValue","height","progressSV","useSharedValue","heightSV","setHandlers","broadcast","useSharedHandlers","context","useMemo","animated","multiply","reanimated","style","transform","translateX","translateY","onKeyboardMove","event","nativeEvent","useNativeDriver","updateSharedValues","platforms","includes","Platform","OS","value","handler","useAnimatedKeyboardHandler","onKeyboardMoveStart","onKeyboardMoveEnd","undefined"],"sources":["animated.tsx"],"sourcesContent":["import React, { useMemo } from 'react';\nimport { Animated, Platform, StyleSheet, ViewStyle } from 'react-native';\nimport Reanimated, { useSharedValue } from 'react-native-reanimated';\n\nimport { KeyboardContext } from './context';\nimport {\n useAnimatedKeyboardHandler,\n useSharedHandlers,\n useAnimatedValue,\n} from './internal';\nimport { KeyboardControllerView } from './native';\n\nimport type {\n KeyboardControllerProps,\n KeyboardHandler,\n NativeEvent,\n} from './types';\n\nconst KeyboardControllerViewAnimated = Reanimated.createAnimatedComponent(\n Animated.createAnimatedComponent(\n KeyboardControllerView\n ) as React.FC<KeyboardControllerProps>\n);\n\ntype Styles = {\n container: ViewStyle;\n hidden: ViewStyle;\n};\n\nconst styles = StyleSheet.create<Styles>({\n container: {\n flex: 1,\n },\n hidden: {\n display: 'none',\n position: 'absolute',\n },\n});\n\ntype KeyboardProviderProps = {\n children: React.ReactNode;\n /**\n * Set the value to `true`, if you use translucent status bar on Android.\n * If you already control status bar translucency via `react-native-screens`\n * or `StatusBar` component from `react-native`, you can ignore it.\n * Defaults to `false`.\n *\n * @see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/14\n * @platform android\n */\n statusBarTranslucent?: boolean;\n};\n\nexport const KeyboardProvider = ({\n children,\n statusBarTranslucent,\n}: KeyboardProviderProps) => {\n // animated values\n const progress = useAnimatedValue(0);\n const height = useAnimatedValue(0);\n // shared values\n const progressSV = useSharedValue(0);\n const heightSV = useSharedValue(0);\n const { setHandlers, broadcast } = useSharedHandlers<KeyboardHandler>();\n // memo\n const context = useMemo(\n () => ({\n animated: { progress: progress, height: Animated.multiply(height, -1) },\n reanimated: { progress: progressSV, height: heightSV },\n setHandlers,\n }),\n []\n );\n const style = useMemo(\n () => [\n styles.hidden,\n { transform: [{ translateX: height }, { translateY: progress }] },\n ],\n []\n );\n const onKeyboardMove = useMemo(\n () =>\n Animated.event(\n [\n {\n nativeEvent: {\n progress,\n height,\n },\n },\n ],\n { useNativeDriver: true }\n ),\n []\n );\n // handlers\n const updateSharedValues = (event: NativeEvent, platforms: string[]) => {\n 'worklet';\n\n if (platforms.includes(Platform.OS)) {\n progressSV.value = event.progress;\n heightSV.value = -event.height;\n }\n };\n const handler = useAnimatedKeyboardHandler(\n {\n onKeyboardMoveStart: (event: NativeEvent) => {\n 'worklet';\n\n broadcast('onStart', event);\n updateSharedValues(event, ['ios']);\n },\n onKeyboardMove: (event: NativeEvent) => {\n 'worklet';\n\n broadcast('onMove', event);\n updateSharedValues(event, ['android']);\n },\n onKeyboardMoveEnd: (event: NativeEvent) => {\n 'worklet';\n\n broadcast('onEnd', event);\n },\n },\n []\n );\n\n return (\n <KeyboardContext.Provider value={context}>\n <KeyboardControllerViewAnimated\n onKeyboardMoveReanimated={handler}\n onKeyboardMoveStart={Platform.OS === 'ios' ? onKeyboardMove : undefined}\n onKeyboardMove={Platform.OS === 'android' ? onKeyboardMove : undefined}\n statusBarTranslucent={statusBarTranslucent}\n style={styles.container}\n >\n <>\n <Animated.View\n // we are using this small hack, because if the component (where\n // animated value has been used) is unmounted, then animation will\n // stop receiving events (seems like it's react-native optimization).\n // So we need to keep a reference to the animated value, to keep it's\n // always mounted (keep a reference to an animated value).\n //\n // To test why it's needed, try to open screen which consumes Animated.Value\n // then close it and open it again (for example 'Animated transition').\n style={style}\n />\n {children}\n </>\n </KeyboardControllerViewAnimated>\n </KeyboardContext.Provider>\n );\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAEA;;AACA;;AAKA;;;;;;AAQA,MAAMA,8BAA8B,GAAGC,8BAAA,CAAWC,uBAAX,CACrCC,qBAAA,CAASD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D;IAIE,oBAAoB,EAAEjC,oBAJxB;IAKE,KAAK,EAAEV,MAAM,CAACG;EALhB,gBAOE,yEACE,6BAAC,qBAAD,CAAU,IAAV;IACE;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,KAAK,EAAEsB;EATT,EADF,EAYGhB,QAZH,CAPF,CADF,CADF;AA0BD,CApGM"}
@@ -4,10 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.useAnimatedKeyboardHandler = useAnimatedKeyboardHandler;
7
+ exports.useAnimatedValue = useAnimatedValue;
7
8
  exports.useSharedHandlers = useSharedHandlers;
8
9
 
9
10
  var _react = require("react");
10
11
 
12
+ var _reactNative = require("react-native");
13
+
11
14
  var _reactNativeReanimated = require("react-native-reanimated");
12
15
 
13
16
  function useAnimatedKeyboardHandler(handlers, dependencies) {
@@ -88,4 +91,24 @@ function useSharedHandlers() {
88
91
  broadcast
89
92
  };
90
93
  }
94
+ /**
95
+ * TS variant of `useAnimatedValue` hook which is added in RN 0.71
96
+ * A better alternative of storing animated values in refs, since
97
+ * it doesn't recreate a new `Animated.Value` object on every re-render
98
+ * and therefore consumes less memory. We can not use a variant from
99
+ * RN, since this library supports earlier versions of RN.
100
+ *
101
+ * @see https://github.com/facebook/react-native/commit/e22217fe8b9455e32695f88ca835e11442b0a937
102
+ */
103
+
104
+
105
+ function useAnimatedValue(initialValue, config) {
106
+ const ref = (0, _react.useRef)(null);
107
+
108
+ if (ref.current == null) {
109
+ ref.current = new _reactNative.Animated.Value(initialValue, config);
110
+ }
111
+
112
+ return ref.current;
113
+ }
91
114
  //# sourceMappingURL=internal.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["useAnimatedKeyboardHandler","handlers","dependencies","context","doDependenciesDiffer","useHandler","useEvent","event","onKeyboardMoveStart","onKeyboardMove","onKeyboardMoveEnd","eventName","endsWith","useSharedHandlers","useSharedValue","jsHandlers","useRef","updateSharedHandlers","value","current","setHandlers","useCallback","handler","broadcast","type","Object","keys","forEach","key"],"sources":["internal.ts"],"sourcesContent":["import { useCallback, useRef } from 'react';\nimport { useEvent, useHandler, useSharedValue } from 'react-native-reanimated';\n\nimport type { EventWithName, Handlers, NativeEvent } from './types';\n\nexport function useAnimatedKeyboardHandler<\n TContext extends Record<string, unknown>\n>(\n handlers: {\n onKeyboardMoveStart?: (e: NativeEvent, context: TContext) => void;\n onKeyboardMove?: (e: NativeEvent, context: TContext) => void;\n onKeyboardMoveEnd?: (e: NativeEvent, context: TContext) => void;\n },\n dependencies?: ReadonlyArray<unknown>\n) {\n const { context, doDependenciesDiffer } = useHandler(handlers, dependencies);\n\n return useEvent(\n (event: EventWithName<NativeEvent>) => {\n 'worklet';\n const { onKeyboardMoveStart, onKeyboardMove, onKeyboardMoveEnd } =\n handlers;\n\n if (\n onKeyboardMoveStart &&\n event.eventName.endsWith('onKeyboardMoveStart')\n ) {\n onKeyboardMoveStart(event, context);\n }\n\n if (onKeyboardMove && event.eventName.endsWith('onKeyboardMove')) {\n onKeyboardMove(event, context);\n }\n\n if (onKeyboardMoveEnd && event.eventName.endsWith('onKeyboardMoveEnd')) {\n onKeyboardMoveEnd(event, context);\n }\n },\n ['onKeyboardMoveStart', 'onKeyboardMove', 'onKeyboardMoveEnd'],\n doDependenciesDiffer\n );\n}\n\n/**\n * Hook for storing worklet handlers (objects with keys, where values are worklets).\n * Returns methods for setting handlers and broadcasting events in them.\n *\n * T is a generic that looks like:\n * @example\n * {\n * onEvent: () => {},\n * onEvent2: () => {},\n * }\n */\nexport function useSharedHandlers<T extends Record<string, Function>>() {\n const handlers = useSharedValue<Handlers<T>>({});\n const jsHandlers = useRef<Handlers<T>>({});\n\n // since js -> worklet -> js call is asynchronous, we can not write handlers\n // straight into shared variable (using current shared value as a previous result),\n // since there may be a race condition in a call, and closure may have out-of-dated\n // values. As a result, some of handlers may be not written to \"all handlers\" object.\n // Below we are writing all handlers to `ref` and afterwards synchronize them with\n // shared value (since `refs` are not referring to actual value in worklets).\n // This approach allow us to update synchronously handlers in js thread (and it assures,\n // that it will have all of them) and then update them in worklet thread (calls are\n // happening in FIFO order, so we will always have actual value).\n const updateSharedHandlers = () => {\n handlers.value = jsHandlers.current;\n };\n const setHandlers = useCallback((handler: Handlers<T>) => {\n jsHandlers.current = {\n ...jsHandlers.current,\n ...handler,\n };\n updateSharedHandlers();\n }, []);\n const broadcast = (type: keyof T, event: NativeEvent) => {\n 'worklet';\n\n Object.keys(handlers.value).forEach((key) =>\n handlers.value[key]?.[type]?.(event)\n );\n };\n\n return { setHandlers, broadcast };\n}\n"],"mappings":";;;;;;;;AAAA;;AACA;;AAIO,SAASA,0BAAT,CAGLC,QAHK,EAQLC,YARK,EASL;EACA,MAAM;IAAEC,OAAF;IAAWC;EAAX,IAAoC,IAAAC,iCAAA,EAAWJ,QAAX,EAAqBC,YAArB,CAA1C;EAEA,OAAO,IAAAI,+BAAA,EACJC,KAAD,IAAuC;IACrC;;IACA,MAAM;MAAEC,mBAAF;MAAuBC,cAAvB;MAAuCC;IAAvC,IACJT,QADF;;IAGA,IACEO,mBAAmB,IACnBD,KAAK,CAACI,SAAN,CAAgBC,QAAhB,CAAyB,qBAAzB,CAFF,EAGE;MACAJ,mBAAmB,CAACD,KAAD,EAAQJ,OAAR,CAAnB;IACD;;IAED,IAAIM,cAAc,IAAIF,KAAK,CAACI,SAAN,CAAgBC,QAAhB,CAAyB,gBAAzB,CAAtB,EAAkE;MAChEH,cAAc,CAACF,KAAD,EAAQJ,OAAR,CAAd;IACD;;IAED,IAAIO,iBAAiB,IAAIH,KAAK,CAACI,SAAN,CAAgBC,QAAhB,CAAyB,mBAAzB,CAAzB,EAAwE;MACtEF,iBAAiB,CAACH,KAAD,EAAQJ,OAAR,CAAjB;IACD;EACF,CApBI,EAqBL,CAAC,qBAAD,EAAwB,gBAAxB,EAA0C,mBAA1C,CArBK,EAsBLC,oBAtBK,CAAP;AAwBD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASS,iBAAT,GAAiE;EACtE,MAAMZ,QAAQ,GAAG,IAAAa,qCAAA,EAA4B,EAA5B,CAAjB;EACA,MAAMC,UAAU,GAAG,IAAAC,aAAA,EAAoB,EAApB,CAAnB,CAFsE,CAItE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EACA,MAAMC,oBAAoB,GAAG,MAAM;IACjChB,QAAQ,CAACiB,KAAT,GAAiBH,UAAU,CAACI,OAA5B;EACD,CAFD;;EAGA,MAAMC,WAAW,GAAG,IAAAC,kBAAA,EAAaC,OAAD,IAA0B;IACxDP,UAAU,CAACI,OAAX,GAAqB,EACnB,GAAGJ,UAAU,CAACI,OADK;MAEnB,GAAGG;IAFgB,CAArB;IAIAL,oBAAoB;EACrB,CANmB,EAMjB,EANiB,CAApB;;EAOA,MAAMM,SAAS,GAAG,CAACC,IAAD,EAAgBjB,KAAhB,KAAuC;IACvD;;IAEAkB,MAAM,CAACC,IAAP,CAAYzB,QAAQ,CAACiB,KAArB,EAA4BS,OAA5B,CAAqCC,GAAD;MAAA;;MAAA,8BAClC3B,QAAQ,CAACiB,KAAT,CAAeU,GAAf,CADkC,iFAClC,oBAAsBJ,IAAtB,CADkC,0DAClC,gDAA8BjB,KAA9B,CADkC;IAAA,CAApC;EAGD,CAND;;EAQA,OAAO;IAAEa,WAAF;IAAeG;EAAf,CAAP;AACD"}
1
+ {"version":3,"names":["useAnimatedKeyboardHandler","handlers","dependencies","context","doDependenciesDiffer","useHandler","useEvent","event","onKeyboardMoveStart","onKeyboardMove","onKeyboardMoveEnd","eventName","endsWith","useSharedHandlers","useSharedValue","jsHandlers","useRef","updateSharedHandlers","value","current","setHandlers","useCallback","handler","broadcast","type","Object","keys","forEach","key","useAnimatedValue","initialValue","config","ref","Animated","Value"],"sources":["internal.ts"],"sourcesContent":["import { useCallback, useRef } from 'react';\nimport { Animated } from 'react-native';\nimport { useEvent, useHandler, useSharedValue } from 'react-native-reanimated';\n\nimport type { EventWithName, Handlers, NativeEvent } from './types';\n\nexport function useAnimatedKeyboardHandler<\n TContext extends Record<string, unknown>\n>(\n handlers: {\n onKeyboardMoveStart?: (e: NativeEvent, context: TContext) => void;\n onKeyboardMove?: (e: NativeEvent, context: TContext) => void;\n onKeyboardMoveEnd?: (e: NativeEvent, context: TContext) => void;\n },\n dependencies?: ReadonlyArray<unknown>\n) {\n const { context, doDependenciesDiffer } = useHandler(handlers, dependencies);\n\n return useEvent(\n (event: EventWithName<NativeEvent>) => {\n 'worklet';\n const { onKeyboardMoveStart, onKeyboardMove, onKeyboardMoveEnd } =\n handlers;\n\n if (\n onKeyboardMoveStart &&\n event.eventName.endsWith('onKeyboardMoveStart')\n ) {\n onKeyboardMoveStart(event, context);\n }\n\n if (onKeyboardMove && event.eventName.endsWith('onKeyboardMove')) {\n onKeyboardMove(event, context);\n }\n\n if (onKeyboardMoveEnd && event.eventName.endsWith('onKeyboardMoveEnd')) {\n onKeyboardMoveEnd(event, context);\n }\n },\n ['onKeyboardMoveStart', 'onKeyboardMove', 'onKeyboardMoveEnd'],\n doDependenciesDiffer\n );\n}\n\n/**\n * Hook for storing worklet handlers (objects with keys, where values are worklets).\n * Returns methods for setting handlers and broadcasting events in them.\n *\n * T is a generic that looks like:\n * @example\n * {\n * onEvent: () => {},\n * onEvent2: () => {},\n * }\n */\nexport function useSharedHandlers<T extends Record<string, Function>>() {\n const handlers = useSharedValue<Handlers<T>>({});\n const jsHandlers = useRef<Handlers<T>>({});\n\n // since js -> worklet -> js call is asynchronous, we can not write handlers\n // straight into shared variable (using current shared value as a previous result),\n // since there may be a race condition in a call, and closure may have out-of-dated\n // values. As a result, some of handlers may be not written to \"all handlers\" object.\n // Below we are writing all handlers to `ref` and afterwards synchronize them with\n // shared value (since `refs` are not referring to actual value in worklets).\n // This approach allow us to update synchronously handlers in js thread (and it assures,\n // that it will have all of them) and then update them in worklet thread (calls are\n // happening in FIFO order, so we will always have actual value).\n const updateSharedHandlers = () => {\n handlers.value = jsHandlers.current;\n };\n const setHandlers = useCallback((handler: Handlers<T>) => {\n jsHandlers.current = {\n ...jsHandlers.current,\n ...handler,\n };\n updateSharedHandlers();\n }, []);\n const broadcast = (type: keyof T, event: NativeEvent) => {\n 'worklet';\n\n Object.keys(handlers.value).forEach((key) =>\n handlers.value[key]?.[type]?.(event)\n );\n };\n\n return { setHandlers, broadcast };\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;;AACA;;AACA;;AAIO,SAASA,0BAAT,CAGLC,QAHK,EAQLC,YARK,EASL;EACA,MAAM;IAAEC,OAAF;IAAWC;EAAX,IAAoC,IAAAC,iCAAA,EAAWJ,QAAX,EAAqBC,YAArB,CAA1C;EAEA,OAAO,IAAAI,+BAAA,EACJC,KAAD,IAAuC;IACrC;;IACA,MAAM;MAAEC,mBAAF;MAAuBC,cAAvB;MAAuCC;IAAvC,IACJT,QADF;;IAGA,IACEO,mBAAmB,IACnBD,KAAK,CAACI,SAAN,CAAgBC,QAAhB,CAAyB,qBAAzB,CAFF,EAGE;MACAJ,mBAAmB,CAACD,KAAD,EAAQJ,OAAR,CAAnB;IACD;;IAED,IAAIM,cAAc,IAAIF,KAAK,CAACI,SAAN,CAAgBC,QAAhB,CAAyB,gBAAzB,CAAtB,EAAkE;MAChEH,cAAc,CAACF,KAAD,EAAQJ,OAAR,CAAd;IACD;;IAED,IAAIO,iBAAiB,IAAIH,KAAK,CAACI,SAAN,CAA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A,EAA8B,IAA9B,CAAZ;;EAEA,IAAIgB,GAAG,CAACb,OAAJ,IAAe,IAAnB,EAAyB;IACvBa,GAAG,CAACb,OAAJ,GAAc,IAAIc,qBAAA,CAASC,KAAb,CAAmBJ,YAAnB,EAAiCC,MAAjC,CAAd;EACD;;EAED,OAAOC,GAAG,CAACb,OAAX;AACD"}
@@ -1 +1 @@
1
- {"version":3,"names":["LINKING_ERROR","Platform","select","ios","default","AndroidSoftInputModes","RCTKeyboardController","require","KeyboardController","Proxy","get","Error","eventEmitter","NativeEventEmitter","KeyboardEvents","addListener","name","cb","KeyboardControllerView"],"sources":["native.ts"],"sourcesContent":["import { Platform, NativeEventEmitter } from 'react-native';\n\nimport type {\n KeyboardControllerEvents,\n KeyboardControllerModule,\n KeyboardEventData,\n} from './types';\n\nconst LINKING_ERROR =\n `The package 'react-native-keyboard-controller' doesn't seem to be linked. Make sure: \\n\\n` +\n Platform.select({ ios: \"- You have run 'pod install'\\n\", default: '' }) +\n '- You rebuilt the app after installing the package\\n' +\n '- You are not using Expo Go\\n';\n\n// copied from `android.view.WindowManager.LayoutParams`\nexport enum AndroidSoftInputModes {\n SOFT_INPUT_ADJUST_NOTHING = 48,\n SOFT_INPUT_ADJUST_PAN = 32,\n SOFT_INPUT_ADJUST_RESIZE = 16,\n SOFT_INPUT_ADJUST_UNSPECIFIED = 0,\n SOFT_INPUT_IS_FORWARD_NAVIGATION = 256,\n SOFT_INPUT_MASK_ADJUST = 240,\n SOFT_INPUT_MASK_STATE = 15,\n SOFT_INPUT_MODE_CHANGED = 512,\n SOFT_INPUT_STATE_ALWAYS_HIDDEN = 3,\n SOFT_INPUT_STATE_ALWAYS_VISIBLE = 5,\n SOFT_INPUT_STATE_HIDDEN = 2,\n SOFT_INPUT_STATE_UNCHANGED = 1,\n SOFT_INPUT_STATE_UNSPECIFIED = 0,\n SOFT_INPUT_STATE_VISIBLE = 4,\n}\n\nconst RCTKeyboardController =\n require('./specs/NativeKeyboardController').default;\nexport const KeyboardController = (\n RCTKeyboardController\n ? RCTKeyboardController\n : new Proxy(\n {},\n {\n get() {\n throw new Error(LINKING_ERROR);\n },\n }\n )\n) as KeyboardControllerModule;\n\nconst eventEmitter = new NativeEventEmitter(KeyboardController);\n\nexport const KeyboardEvents = {\n addListener: (\n name: KeyboardControllerEvents,\n cb: (e: KeyboardEventData) => void\n ) => eventEmitter.addListener('KeyboardController::' + name, cb),\n};\nexport const KeyboardControllerView =\n require('./specs/KeyboardControllerViewNativeComponent').default;\n"],"mappings":";;;;;;;AAAA;;AAQA,MAAMA,aAAa,GAChB,2FAAD,GACAC,qBAAA,CAASC,MAAT,CAAgB;EAAEC,GAAG,EAAE,gCAAP;EAAyCC,OAAO,EAAE;AAAlD,CAAhB,CADA,GAEA,sDAFA,GAGA,+BAJF,C,CAMA;;IACYC,qB;;;WAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;GAAAA,qB,qCAAAA,qB;;AAiBZ,MAAMC,qBAAqB,GACzBC,OAAO,CAAC,kCAAD,CAAP,CAA4CH,OAD9C;;AAEO,MAAMI,kBAAkB,GAC7BF,qBAAqB,GACjBA,qBADiB,GAEjB,IAAIG,KAAJ,CACE,EADF,EAEE;EACEC,GAAG,GAAG;IACJ,MAAM,IAAIC,KAAJ,CAAUX,aAAV,CAAN;EACD;;AAHH,CAFF,CAHC;;AAaP,MAAMY,YAAY,GAAG,IAAIC,+BAAJ,CAAuBL,kBAAvB,CAArB;AAEO,MAAMM,cAAc,GAAG;EAC5BC,WAAW,EAAE,CACXC,IADW,EAEXC,EAFW,KAGRL,YAAY,CAACG,WAAb,CAAyB,yBAAyBC,IAAlD,EAAwDC,EAAxD;AAJuB,CAAvB;;;AAMA,MAAMC,sBAAsB,GACjCX,OAAO,CAAC,+CAAD,CAAP,CAAyDH,OADpD"}
1
+ {"version":3,"names":["LINKING_ERROR","Platform","select","ios","default","AndroidSoftInputModes","RCTKeyboardController","require","KeyboardController","Proxy","get","Error","eventEmitter","NativeEventEmitter","KeyboardEvents","addListener","name","cb","KeyboardControllerView"],"sources":["native.ts"],"sourcesContent":["import { Platform, NativeEventEmitter } from 'react-native';\n\nimport type {\n KeyboardControllerEvents,\n KeyboardControllerModule,\n KeyboardControllerProps,\n KeyboardEventData,\n} from './types';\n\nconst LINKING_ERROR =\n `The package 'react-native-keyboard-controller' doesn't seem to be linked. Make sure: \\n\\n` +\n Platform.select({ ios: \"- You have run 'pod install'\\n\", default: '' }) +\n '- You rebuilt the app after installing the package\\n' +\n '- You are not using Expo Go\\n';\n\n// copied from `android.view.WindowManager.LayoutParams`\nexport enum AndroidSoftInputModes {\n SOFT_INPUT_ADJUST_NOTHING = 48,\n SOFT_INPUT_ADJUST_PAN = 32,\n SOFT_INPUT_ADJUST_RESIZE = 16,\n SOFT_INPUT_ADJUST_UNSPECIFIED = 0,\n SOFT_INPUT_IS_FORWARD_NAVIGATION = 256,\n SOFT_INPUT_MASK_ADJUST = 240,\n SOFT_INPUT_MASK_STATE = 15,\n SOFT_INPUT_MODE_CHANGED = 512,\n SOFT_INPUT_STATE_ALWAYS_HIDDEN = 3,\n SOFT_INPUT_STATE_ALWAYS_VISIBLE = 5,\n SOFT_INPUT_STATE_HIDDEN = 2,\n SOFT_INPUT_STATE_UNCHANGED = 1,\n SOFT_INPUT_STATE_UNSPECIFIED = 0,\n SOFT_INPUT_STATE_VISIBLE = 4,\n}\n\nconst RCTKeyboardController =\n require('./specs/NativeKeyboardController').default;\nexport const KeyboardController = (\n RCTKeyboardController\n ? RCTKeyboardController\n : new Proxy(\n {},\n {\n get() {\n throw new Error(LINKING_ERROR);\n },\n }\n )\n) as KeyboardControllerModule;\n\nconst eventEmitter = new NativeEventEmitter(KeyboardController);\n\nexport const KeyboardEvents = {\n addListener: (\n name: KeyboardControllerEvents,\n cb: (e: KeyboardEventData) => void\n ) => eventEmitter.addListener('KeyboardController::' + name, cb),\n};\nexport const KeyboardControllerView: React.FC<KeyboardControllerProps> =\n require('./specs/KeyboardControllerViewNativeComponent').default;\n"],"mappings":";;;;;;;AAAA;;AASA,MAAMA,aAAa,GAChB,2FAAD,GACAC,qBAAA,CAASC,MAAT,CAAgB;EAAEC,GAAG,EAAE,gCAAP;EAAyCC,OAAO,EAAE;AAAlD,CAAhB,CADA,GAEA,sDAFA,GAGA,+BAJF,C,CAMA;;IACYC,qB;;;WAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;GAAAA,qB,qCAAAA,qB;;AAiBZ,MAAMC,qBAAqB,GACzBC,OAAO,CAAC,kCAAD,CAAP,CAA4CH,OAD9C;;AAEO,MAAMI,kBAAkB,GAC7BF,qBAAqB,GACjBA,qBADiB,GAEjB,IAAIG,KAAJ,CACE,EADF,EAEE;EACEC,GAAG,GAAG;IACJ,MAAM,IAAIC,KAAJ,CAAUX,aAAV,CAAN;EACD;;AAHH,CAFF,CAHC;;AAaP,MAAMY,YAAY,GAAG,IAAIC,+BAAJ,CAAuBL,kBAAvB,CAArB;AAEO,MAAMM,cAAc,GAAG;EAC5BC,WAAW,EAAE,CACXC,IADW,EAEXC,EAFW,KAGRL,YAAY,CAACG,WAAb,CAAyB,yBAAyBC,IAAlD,EAAwDC,EAAxD;AAJuB,CAAvB;;;AAMA,MAAMC,sBAAyD,GACpEX,OAAO,CAAC,+CAAD,CAAP,CAAyDH,OADpD"}
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { NativeSyntheticEvent, ViewProps } from 'react-native';\n\n// DirectEventHandler events declaration\n\nexport type NativeEvent = {\n progress: number;\n height: number;\n};\nexport type EventWithName<T> = {\n eventName: string;\n} & T;\n\n// native View/Module declarations\n\nexport type KeyboardControllerProps = {\n onKeyboardMoveStart?: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n onKeyboardMove?: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n onKeyboardMoveEnd?: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n // fake prop used to activate reanimated bindings\n onKeyboardMoveReanimated: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n statusBarTranslucent?: boolean;\n} & ViewProps;\n\nexport type KeyboardControllerModule = {\n // android only\n setDefaultMode: () => void;\n setInputMode: (mode: number) => void;\n // native event module stuff\n addListener: (eventName: string) => void;\n removeListeners: (count: number) => void;\n};\n\n// Event module declarations\n\nexport type KeyboardControllerEvents =\n | 'keyboardWillShow'\n | 'keyboardDidShow'\n | 'keyboardWillHide'\n | 'keyboardDidHide';\nexport type KeyboardEventData = {\n height: number;\n};\n\n// package types\n\nexport type Handlers<T> = Record<string, T | undefined>;\nexport type KeyboardHandler = {\n onStart?: (e: NativeEvent) => void;\n onMove?: (e: NativeEvent) => void;\n onEnd?: (e: NativeEvent) => void;\n};\nexport type KeyboardHandlers = Handlers<KeyboardHandler>;\n"],"mappings":""}
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { NativeSyntheticEvent, ViewProps } from 'react-native';\n\n// DirectEventHandler events declaration\n\nexport type NativeEvent = {\n progress: number;\n height: number;\n};\nexport type EventWithName<T> = {\n eventName: string;\n} & T;\n\n// native View/Module declarations\n\nexport type KeyboardControllerProps = {\n onKeyboardMoveStart?: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n onKeyboardMove?: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n onKeyboardMoveEnd?: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n // fake prop used to activate reanimated bindings\n onKeyboardMoveReanimated?: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n statusBarTranslucent?: boolean;\n} & ViewProps;\n\nexport type KeyboardControllerModule = {\n // android only\n setDefaultMode: () => void;\n setInputMode: (mode: number) => void;\n // native event module stuff\n addListener: (eventName: string) => void;\n removeListeners: (count: number) => void;\n};\n\n// Event module declarations\n\nexport type KeyboardControllerEvents =\n | 'keyboardWillShow'\n | 'keyboardDidShow'\n | 'keyboardWillHide'\n | 'keyboardDidHide';\nexport type KeyboardEventData = {\n height: number;\n};\n\n// package types\n\nexport type Handlers<T> = Record<string, T | undefined>;\nexport type KeyboardHandler = {\n onStart?: (e: NativeEvent) => void;\n onMove?: (e: NativeEvent) => void;\n onEnd?: (e: NativeEvent) => void;\n};\nexport type KeyboardHandlers = Handlers<KeyboardHandler>;\n"],"mappings":""}
@@ -1,11 +1,11 @@
1
- import React, { useMemo, useRef } from 'react';
1
+ import React, { useMemo } from 'react';
2
2
  import { Animated, Platform, StyleSheet } from 'react-native';
3
3
  import Reanimated, { useSharedValue } from 'react-native-reanimated';
4
4
  import { KeyboardContext } from './context';
5
- import { useAnimatedKeyboardHandler, useSharedHandlers } from './internal';
5
+ import { useAnimatedKeyboardHandler, useSharedHandlers, useAnimatedValue } from './internal';
6
6
  import { KeyboardControllerView } from './native';
7
7
  const KeyboardControllerViewAnimated = Reanimated.createAnimatedComponent(Animated.createAnimatedComponent(KeyboardControllerView));
8
- export const styles = StyleSheet.create({
8
+ const styles = StyleSheet.create({
9
9
  container: {
10
10
  flex: 1
11
11
  },
@@ -20,8 +20,8 @@ export const KeyboardProvider = _ref => {
20
20
  statusBarTranslucent
21
21
  } = _ref;
22
22
  // animated values
23
- const progress = useRef(new Animated.Value(0)).current;
24
- const height = useRef(new Animated.Value(0)).current; // shared values
23
+ const progress = useAnimatedValue(0);
24
+ const height = useAnimatedValue(0); // shared values
25
25
 
26
26
  const progressSV = useSharedValue(0);
27
27
  const heightSV = useSharedValue(0);
@@ -1 +1 @@
1
- {"version":3,"names":["React","useMemo","useRef","Animated","Platform","StyleSheet","Reanimated","useSharedValue","KeyboardContext","useAnimatedKeyboardHandler","useSharedHandlers","KeyboardControllerView","KeyboardControllerViewAnimated","createAnimatedComponent","styles","create","container","flex","hidden","display","position","KeyboardProvider","children","statusBarTranslucent","progress","Value","current","height","progressSV","heightSV","setHandlers","broadcast","context","animated","multiply","reanimated","style","transform","translateX","translateY","onKeyboardMove","event","nativeEvent","useNativeDriver","updateSharedValues","platforms","includes","OS","value","handler","onKeyboardMoveStart","onKeyboardMoveEnd","undefined"],"sources":["animated.tsx"],"sourcesContent":["import React, { useMemo, useRef } from 'react';\nimport { Animated, Platform, StyleSheet, ViewStyle } from 'react-native';\nimport Reanimated, { useSharedValue } from 'react-native-reanimated';\n\nimport { KeyboardContext } from './context';\nimport { useAnimatedKeyboardHandler, useSharedHandlers } from './internal';\nimport { KeyboardControllerView } from './native';\n\nimport type {\n KeyboardControllerProps,\n KeyboardHandler,\n NativeEvent,\n} from './types';\n\nconst KeyboardControllerViewAnimated = Reanimated.createAnimatedComponent(\n Animated.createAnimatedComponent(\n KeyboardControllerView\n ) as React.FC<KeyboardControllerProps>\n);\n\ntype Styles = {\n container: ViewStyle;\n hidden: ViewStyle;\n};\n\nexport const styles = StyleSheet.create<Styles>({\n container: {\n flex: 1,\n },\n hidden: {\n display: 'none',\n position: 'absolute',\n },\n});\n\ntype KeyboardProviderProps = {\n children: React.ReactNode;\n /**\n * Set the value to `true`, if you use translucent status bar on Android.\n * If you already control status bar translucency via `react-native-screens`\n * or `StatusBar` component from `react-native`, you can ignore it.\n * Defaults to `false`.\n *\n * @see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/14\n * @platform android\n */\n statusBarTranslucent?: boolean;\n};\n\nexport const KeyboardProvider = ({\n children,\n statusBarTranslucent,\n}: KeyboardProviderProps) => {\n // animated values\n const progress = useRef(new Animated.Value(0)).current;\n const height = useRef(new Animated.Value(0)).current;\n // shared values\n const progressSV = useSharedValue(0);\n const heightSV = useSharedValue(0);\n const { setHandlers, broadcast } = useSharedHandlers<KeyboardHandler>();\n // memo\n const context = useMemo(\n () => ({\n animated: { progress: progress, height: Animated.multiply(height, -1) },\n reanimated: { progress: progressSV, height: heightSV },\n setHandlers,\n }),\n []\n );\n const style = useMemo(\n () => [\n styles.hidden,\n { transform: [{ translateX: height }, { translateY: progress }] },\n ],\n []\n );\n const onKeyboardMove = useMemo(\n () =>\n Animated.event(\n [\n {\n nativeEvent: {\n progress,\n height,\n },\n },\n ],\n { useNativeDriver: true }\n ),\n []\n );\n // handlers\n const updateSharedValues = (event: NativeEvent, platforms: string[]) => {\n 'worklet';\n\n if (platforms.includes(Platform.OS)) {\n progressSV.value = event.progress;\n heightSV.value = -event.height;\n }\n };\n const handler = useAnimatedKeyboardHandler(\n {\n onKeyboardMoveStart: (event: NativeEvent) => {\n 'worklet';\n\n broadcast('onStart', event);\n updateSharedValues(event, ['ios']);\n },\n onKeyboardMove: (event: NativeEvent) => {\n 'worklet';\n\n broadcast('onMove', event);\n updateSharedValues(event, ['android']);\n },\n onKeyboardMoveEnd: (event: NativeEvent) => {\n 'worklet';\n\n broadcast('onEnd', event);\n },\n },\n []\n );\n\n return (\n <KeyboardContext.Provider value={context}>\n <KeyboardControllerViewAnimated\n onKeyboardMoveReanimated={handler}\n onKeyboardMoveStart={Platform.OS === 'ios' ? onKeyboardMove : undefined}\n onKeyboardMove={Platform.OS === 'android' ? onKeyboardMove : undefined}\n statusBarTranslucent={statusBarTranslucent}\n style={styles.container}\n >\n <>\n <Animated.View\n // we are using this small hack, because if the component (where\n // animated value has been used) is unmounted, then animation will\n // stop receiving events (seems like it's react-native optimization).\n // So we need to keep a reference to the animated value, to keep it's\n // always mounted (keep a reference to an animated value).\n //\n // To test why it's needed, try to open screen which consumes Animated.Value\n // then close it and open it again (for example 'Animated transition').\n style={style}\n />\n {children}\n </>\n </KeyboardControllerViewAnimated>\n </KeyboardContext.Provider>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,OAAhB,EAAyBC,MAAzB,QAAuC,OAAvC;AACA,SAASC,QAAT,EAAmBC,QAAnB,EAA6BC,UAA7B,QAA0D,cAA1D;AACA,OAAOC,UAAP,IAAqBC,cAArB,QAA2C,yBAA3C;AAEA,SAASC,eAAT,QAAgC,WAAhC;AACA,SAASC,0BAAT,EAAqCC,iBAArC,QAA8D,YAA9D;AACA,SAASC,sBAAT,QAAuC,UAAvC;AAQA,MAAMC,8BAA8B,GAAGN,UAAU,CAACO,uBAAX,CACrCV,QAAQ,CAACU,uBAAT,CACEF,sBADF,CADqC,CAAvC;AAWA,OAAO,MAAMG,MAAM,GAAGT,UAAU,CAACU,MAAX,CAA0B;EAC9CC,SAAS,EAAE;IACTC,IAAI,EAAE;EADG,CADmC;EAI9CC,MAAM,EAAE;IACNC,OAAO,EAAE,MADH;IAENC,QAAQ,EAAE;EAFJ;AAJsC,CAA1B,CAAf;AAwBP,OAAO,MAAMC,gBAAgB,GAAG,QAGH;EAAA,IAHI;IAC/BC,QAD+B;IAE/BC;EAF+B,CAGJ;EAC3B;EACA,MAAMC,QAAQ,GAAGtB,MAAM,CAAC,IAAIC,QAAQ,CAACsB,KAAb,CAAmB,CAAnB,CAAD,CAAN,CAA8BC,OAA/C;EACA,MAAMC,MAAM,GAAGzB,MAAM,CAAC,IAAIC,QAAQ,CAACsB,KAAb,CAAmB,CAAnB,CAAD,CAAN,CAA8BC,OAA7C,CAH2B,CAI3B;;EACA,MAAME,UAAU,GAA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ACEyC,mBAAmB,EAAGT,KAAD,IAAwB;MAC3C;;MAEAV,SAAS,CAAC,SAAD,EAAYU,KAAZ,CAAT;MACAG,kBAAkB,CAACH,KAAD,EAAQ,CAAC,KAAD,CAAR,CAAlB;IACD,CANH;IAOED,cAAc,EAAGC,KAAD,IAAwB;MACtC;;MAEAV,SAAS,CAAC,QAAD,EAAWU,KAAX,CAAT;MACAG,kBAAkB,CAACH,KAAD,EAAQ,CAAC,SAAD,CAAR,CAAlB;IACD,CAZH;IAaEU,iBAAiB,EAAGV,KAAD,IAAwB;MACzC;;MAEAV,SAAS,CAAC,OAAD,EAAUU,KAAV,CAAT;IACD;EAjBH,CADwC,EAoBxC,EApBwC,CAA1C;EAuBA,oBACE,oBAAC,eAAD,CAAiB,QAAjB;IAA0B,KAAK,EAAET;EAAjC,gBACE,oBAAC,8BAAD;IACE,wBAAwB,EAAEiB,OAD5B;IAEE,mBAAmB,EAAE7C,QAAQ,CAAC2C,EAAT,KAAgB,KAAhB,GAAwBP,cAAxB,GAAyCY,SAFhE;IAGE,cAAc,EAAEhD,QAAQ,CAAC2C,EAAT,KAAgB,SAAhB,GAA4BP,cAA5B,GAA6CY,SAH/D;IAIE,oBAAoB,EAAE7B,oBAJxB;IAKE,KAAK,EAAET,MAAM,CAACE;EALhB,gBAOE,uDACE,oBAAC,QAAD,CAAU,IAAV;IACE;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,KAAK,EAAEoB;EATT,EADF,EAYGd,QAZH,CAPF,CADF,CADF;AA0BD,CApGM"}
1
+ {"version":3,"names":["React","useMemo","Animated","Platform","StyleSheet","Reanimated","useSharedValue","KeyboardContext","useAnimatedKeyboardHandler","useSharedHandlers","useAnimatedValue","KeyboardControllerView","KeyboardControllerViewAnimated","createAnimatedComponent","styles","create","container","flex","hidden","display","position","KeyboardProvider","children","statusBarTranslucent","progress","height","progressSV","heightSV","setHandlers","broadcast","context","animated","multiply","reanimated","style","transform","translateX","translateY","onKeyboardMove","event","nativeEvent","useNativeDriver","updateSharedValues","platforms","includes","OS","value","handler","onKeyboardMoveStart","onKeyboardMoveEnd","undefined"],"sources":["animated.tsx"],"sourcesContent":["import React, { useMemo } from 'react';\nimport { Animated, Platform, StyleSheet, ViewStyle } from 'react-native';\nimport Reanimated, { useSharedValue } from 'react-native-reanimated';\n\nimport { KeyboardContext } from './context';\nimport {\n useAnimatedKeyboardHandler,\n useSharedHandlers,\n useAnimatedValue,\n} from './internal';\nimport { KeyboardControllerView } from './native';\n\nimport type {\n KeyboardControllerProps,\n KeyboardHandler,\n NativeEvent,\n} from './types';\n\nconst KeyboardControllerViewAnimated = Reanimated.createAnimatedComponent(\n Animated.createAnimatedComponent(\n KeyboardControllerView\n ) as React.FC<KeyboardControllerProps>\n);\n\ntype Styles = {\n container: ViewStyle;\n hidden: ViewStyle;\n};\n\nconst styles = StyleSheet.create<Styles>({\n container: {\n flex: 1,\n },\n hidden: {\n display: 'none',\n position: 'absolute',\n },\n});\n\ntype KeyboardProviderProps = {\n children: React.ReactNode;\n /**\n * Set the value to `true`, if you use translucent status bar on Android.\n * If you already control status bar translucency via `react-native-screens`\n * or `StatusBar` component from `react-native`, you can ignore it.\n * Defaults to `false`.\n *\n * @see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/14\n * @platform android\n */\n statusBarTranslucent?: boolean;\n};\n\nexport const KeyboardProvider = ({\n children,\n statusBarTranslucent,\n}: KeyboardProviderProps) => {\n // animated values\n const progress = useAnimatedValue(0);\n const height = useAnimatedValue(0);\n // shared values\n const progressSV = useSharedValue(0);\n const heightSV = useSharedValue(0);\n const { setHandlers, broadcast } = useSharedHandlers<KeyboardHandler>();\n // memo\n const context = useMemo(\n () => ({\n animated: { progress: progress, height: Animated.multiply(height, -1) },\n reanimated: { progress: progressSV, height: heightSV },\n setHandlers,\n }),\n []\n );\n const style = useMemo(\n () => [\n styles.hidden,\n { transform: [{ translateX: height }, { translateY: progress }] },\n ],\n []\n );\n const onKeyboardMove = useMemo(\n () =>\n Animated.event(\n [\n {\n nativeEvent: {\n progress,\n height,\n },\n },\n ],\n { useNativeDriver: true }\n ),\n []\n );\n // handlers\n const updateSharedValues = (event: NativeEvent, platforms: string[]) => {\n 'worklet';\n\n if (platforms.includes(Platform.OS)) {\n progressSV.value = event.progress;\n heightSV.value = -event.height;\n }\n };\n const handler = useAnimatedKeyboardHandler(\n {\n onKeyboardMoveStart: (event: NativeEvent) => {\n 'worklet';\n\n broadcast('onStart', event);\n updateSharedValues(event, ['ios']);\n },\n onKeyboardMove: (event: NativeEvent) => {\n 'worklet';\n\n broadcast('onMove', event);\n updateSharedValues(event, ['android']);\n },\n onKeyboardMoveEnd: (event: NativeEvent) => {\n 'worklet';\n\n broadcast('onEnd', event);\n },\n },\n []\n );\n\n return (\n <KeyboardContext.Provider value={context}>\n <KeyboardControllerViewAnimated\n onKeyboardMoveReanimated={handler}\n onKeyboardMoveStart={Platform.OS === 'ios' ? onKeyboardMove : undefined}\n onKeyboardMove={Platform.OS === 'android' ? onKeyboardMove : undefined}\n statusBarTranslucent={statusBarTranslucent}\n style={styles.container}\n >\n <>\n <Animated.View\n // we are using this small hack, because if the component (where\n // animated value has been used) is unmounted, then animation will\n // stop receiving events (seems like it's react-native optimization).\n // So we need to keep a reference to the animated value, to keep it's\n // always mounted (keep a reference to an animated value).\n //\n // To test why it's needed, try to open screen which consumes Animated.Value\n // then close it and open it again (for example 'Animated transition').\n style={style}\n />\n {children}\n </>\n </KeyboardControllerViewAnimated>\n </KeyboardContext.Provider>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,OAAhB,QAA+B,OAA/B;AACA,SAASC,QAAT,EAAmBC,QAAnB,EAA6BC,UAA7B,QAA0D,cAA1D;AACA,OAAOC,UAAP,IAAqBC,cAArB,QAA2C,yBAA3C;AAEA,SAASC,eAAT,QAAgC,WAAhC;AACA,SACEC,0BADF,EAEEC,iBAFF,EAGEC,gBAHF,QAIO,YAJP;AAKA,SAASC,sBAAT,QAAuC,UAA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AAgB,SAAhB,GAA4BP,cAA5B,GAA6CY,SAH/D;IAIE,oBAAoB,EAAE3B,oBAJxB;IAKE,KAAK,EAAET,MAAM,CAACE;EALhB,gBAOE,uDACE,oBAAC,QAAD,CAAU,IAAV;IACE;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,KAAK,EAAEkB;EATT,EADF,EAYGZ,QAZH,CAPF,CADF,CADF;AA0BD,CApGM"}
@@ -1,4 +1,5 @@
1
1
  import { useCallback, useRef } from 'react';
2
+ import { Animated } from 'react-native';
2
3
  import { useEvent, useHandler, useSharedValue } from 'react-native-reanimated';
3
4
  export function useAnimatedKeyboardHandler(handlers, dependencies) {
4
5
  const {
@@ -77,4 +78,23 @@ export function useSharedHandlers() {
77
78
  broadcast
78
79
  };
79
80
  }
81
+ /**
82
+ * TS variant of `useAnimatedValue` hook which is added in RN 0.71
83
+ * A better alternative of storing animated values in refs, since
84
+ * it doesn't recreate a new `Animated.Value` object on every re-render
85
+ * and therefore consumes less memory. We can not use a variant from
86
+ * RN, since this library supports earlier versions of RN.
87
+ *
88
+ * @see https://github.com/facebook/react-native/commit/e22217fe8b9455e32695f88ca835e11442b0a937
89
+ */
90
+
91
+ export function useAnimatedValue(initialValue, config) {
92
+ const ref = useRef(null);
93
+
94
+ if (ref.current == null) {
95
+ ref.current = new Animated.Value(initialValue, config);
96
+ }
97
+
98
+ return ref.current;
99
+ }
80
100
  //# sourceMappingURL=internal.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["useCallback","useRef","useEvent","useHandler","useSharedValue","useAnimatedKeyboardHandler","handlers","dependencies","context","doDependenciesDiffer","event","onKeyboardMoveStart","onKeyboardMove","onKeyboardMoveEnd","eventName","endsWith","useSharedHandlers","jsHandlers","updateSharedHandlers","value","current","setHandlers","handler","broadcast","type","Object","keys","forEach","key"],"sources":["internal.ts"],"sourcesContent":["import { useCallback, useRef } from 'react';\nimport { useEvent, useHandler, useSharedValue } from 'react-native-reanimated';\n\nimport type { EventWithName, Handlers, NativeEvent } from './types';\n\nexport function useAnimatedKeyboardHandler<\n TContext extends Record<string, unknown>\n>(\n handlers: {\n onKeyboardMoveStart?: (e: NativeEvent, context: TContext) => void;\n onKeyboardMove?: (e: NativeEvent, context: TContext) => void;\n onKeyboardMoveEnd?: (e: NativeEvent, context: TContext) => void;\n },\n dependencies?: ReadonlyArray<unknown>\n) {\n const { context, doDependenciesDiffer } = useHandler(handlers, dependencies);\n\n return useEvent(\n (event: EventWithName<NativeEvent>) => {\n 'worklet';\n const { onKeyboardMoveStart, onKeyboardMove, onKeyboardMoveEnd } =\n handlers;\n\n if (\n onKeyboardMoveStart &&\n event.eventName.endsWith('onKeyboardMoveStart')\n ) {\n onKeyboardMoveStart(event, context);\n }\n\n if (onKeyboardMove && event.eventName.endsWith('onKeyboardMove')) {\n onKeyboardMove(event, context);\n }\n\n if (onKeyboardMoveEnd && event.eventName.endsWith('onKeyboardMoveEnd')) {\n onKeyboardMoveEnd(event, context);\n }\n },\n ['onKeyboardMoveStart', 'onKeyboardMove', 'onKeyboardMoveEnd'],\n doDependenciesDiffer\n );\n}\n\n/**\n * Hook for storing worklet handlers (objects with keys, where values are worklets).\n * Returns methods for setting handlers and broadcasting events in them.\n *\n * T is a generic that looks like:\n * @example\n * {\n * onEvent: () => {},\n * onEvent2: () => {},\n * }\n */\nexport function useSharedHandlers<T extends Record<string, Function>>() {\n const handlers = useSharedValue<Handlers<T>>({});\n const jsHandlers = useRef<Handlers<T>>({});\n\n // since js -> worklet -> js call is asynchronous, we can not write handlers\n // straight into shared variable (using current shared value as a previous result),\n // since there may be a race condition in a call, and closure may have out-of-dated\n // values. As a result, some of handlers may be not written to \"all handlers\" object.\n // Below we are writing all handlers to `ref` and afterwards synchronize them with\n // shared value (since `refs` are not referring to actual value in worklets).\n // This approach allow us to update synchronously handlers in js thread (and it assures,\n // that it will have all of them) and then update them in worklet thread (calls are\n // happening in FIFO order, so we will always have actual value).\n const updateSharedHandlers = () => {\n handlers.value = jsHandlers.current;\n };\n const setHandlers = useCallback((handler: Handlers<T>) => {\n jsHandlers.current = {\n ...jsHandlers.current,\n ...handler,\n };\n updateSharedHandlers();\n }, []);\n const broadcast = (type: keyof T, event: NativeEvent) => {\n 'worklet';\n\n Object.keys(handlers.value).forEach((key) =>\n handlers.value[key]?.[type]?.(event)\n );\n };\n\n return { setHandlers, broadcast };\n}\n"],"mappings":"AAAA,SAASA,WAAT,EAAsBC,MAAtB,QAAoC,OAApC;AACA,SAASC,QAAT,EAAmBC,UAAnB,EAA+BC,cAA/B,QAAqD,yBAArD;AAIA,OAAO,SAASC,0BAAT,CAGLC,QAHK,EAQLC,YARK,EASL;EACA,MAAM;IAAEC,OAAF;IAAWC;EAAX,IAAoCN,UAAU,CAACG,QAAD,EAAWC,YAAX,CAApD;EAEA,OAAOL,QAAQ,CACZQ,KAAD,IAAuC;IACrC;;IACA,MAAM;MAAEC,mBAAF;MAAuBC,cAAvB;MAAuCC;IAAvC,IACJP,QADF;;IAGA,IACEK,mBAAmB,IACnBD,KAAK,CAACI,SAAN,CAAgBC,QAAhB,CAAyB,qBAAzB,CAFF,EAGE;MACAJ,mBAAmB,CAACD,KAAD,EAAQF,OAAR,CAAnB;IACD;;IAED,IAAII,cAAc,IAAIF,KAAK,CAACI,SAAN,CAAgBC,QAAhB,CAAyB,gBAAzB,CAAtB,EAAkE;MAChEH,cAAc,CAACF,KAAD,EAAQF,OAAR,CAAd;IACD;;IAED,IAAIK,iBAAiB,IAAIH,KAAK,CAACI,SAAN,CAAgBC,QAAhB,CAAyB,mBAAzB,CAAzB,EAAwE;MACtEF,iBAAiB,CAACH,KAAD,EAAQF,OAAR,CAAjB;IACD;EACF,CApBY,EAqBb,CAAC,qBAAD,EAAwB,gBAAxB,EAA0C,mBAA1C,CArBa,EAsBbC,oBAtBa,CAAf;AAwBD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASO,iBAAT,GAAiE;EACtE,MAAMV,QAAQ,GAAGF,cAAc,CAAc,EAAd,CAA/B;EACA,MAAMa,UAAU,GAAGhB,MAAM,CAAc,EAAd,CAAzB,CAFsE,CAItE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EACA,MAAMiB,oBAAoB,GAAG,MAAM;IACjCZ,QAAQ,CAACa,KAAT,GAAiBF,UAAU,CAACG,OAA5B;EACD,CAFD;;EAGA,MAAMC,WAAW,GAAGrB,WAAW,CAAEsB,OAAD,IAA0B;IACxDL,UAAU,CAACG,OAAX,GAAqB,EACnB,GAAGH,UAAU,CAACG,OADK;MAEnB,GAAGE;IAFgB,CAArB;IAIAJ,oBAAoB;EACrB,CAN8B,EAM5B,EAN4B,CAA/B;;EAOA,MAAMK,SAAS,GAAG,CAACC,IAAD,EAAgBd,KAAhB,KAAuC;IACvD;;IAEAe,MAAM,CAACC,IAAP,CAAYpB,QAAQ,CAACa,KAArB,EAA4BQ,OAA5B,CAAqCC,GAAD;MAAA;;MAAA,8BAClCtB,QAAQ,CAACa,KAAT,CAAeS,GAAf,CADkC,iFAClC,oBAAsBJ,IAAtB,CADkC,0DAClC,gDAA8Bd,KAA9B,CADkC;IAAA,CAApC;EAGD,CAND;;EAQA,OAAO;IAAEW,WAAF;IAAeE;EAAf,CAAP;AACD"}
1
+ {"version":3,"names":["useCallback","useRef","Animated","useEvent","useHandler","useSharedValue","useAnimatedKeyboardHandler","handlers","dependencies","context","doDependenciesDiffer","event","onKeyboardMoveStart","onKeyboardMove","onKeyboardMoveEnd","eventName","endsWith","useSharedHandlers","jsHandlers","updateSharedHandlers","value","current","setHandlers","handler","broadcast","type","Object","keys","forEach","key","useAnimatedValue","initialValue","config","ref","Value"],"sources":["internal.ts"],"sourcesContent":["import { useCallback, useRef } from 'react';\nimport { Animated } from 'react-native';\nimport { useEvent, useHandler, useSharedValue } from 'react-native-reanimated';\n\nimport type { EventWithName, Handlers, NativeEvent } from './types';\n\nexport function useAnimatedKeyboardHandler<\n TContext extends Record<string, unknown>\n>(\n handlers: {\n onKeyboardMoveStart?: (e: NativeEvent, context: TContext) => void;\n onKeyboardMove?: (e: NativeEvent, context: TContext) => void;\n onKeyboardMoveEnd?: (e: NativeEvent, context: TContext) => void;\n },\n dependencies?: ReadonlyArray<unknown>\n) {\n const { context, doDependenciesDiffer } = useHandler(handlers, dependencies);\n\n return useEvent(\n (event: EventWithName<NativeEvent>) => {\n 'worklet';\n const { onKeyboardMoveStart, onKeyboardMove, onKeyboardMoveEnd } =\n handlers;\n\n if (\n onKeyboardMoveStart &&\n event.eventName.endsWith('onKeyboardMoveStart')\n ) {\n onKeyboardMoveStart(event, context);\n }\n\n if (onKeyboardMove && event.eventName.endsWith('onKeyboardMove')) {\n onKeyboardMove(event, context);\n }\n\n if (onKeyboardMoveEnd && event.eventName.endsWith('onKeyboardMoveEnd')) {\n onKeyboardMoveEnd(event, context);\n }\n },\n ['onKeyboardMoveStart', 'onKeyboardMove', 'onKeyboardMoveEnd'],\n doDependenciesDiffer\n );\n}\n\n/**\n * Hook for storing worklet handlers (objects with keys, where values are worklets).\n * Returns methods for setting handlers and broadcasting events in them.\n *\n * T is a generic that looks like:\n * @example\n * {\n * onEvent: () => {},\n * onEvent2: () => {},\n * }\n */\nexport function useSharedHandlers<T extends Record<string, Function>>() {\n const handlers = useSharedValue<Handlers<T>>({});\n const jsHandlers = useRef<Handlers<T>>({});\n\n // since js -> worklet -> js call is asynchronous, we can not write handlers\n // straight into shared variable (using current shared value as a previous result),\n // since there may be a race condition in a call, and closure may have out-of-dated\n // values. As a result, some of handlers may be not written to \"all handlers\" object.\n // Below we are writing all handlers to `ref` and afterwards synchronize them with\n // shared value (since `refs` are not referring to actual value in worklets).\n // This approach allow us to update synchronously handlers in js thread (and it assures,\n // that it will have all of them) and then update them in worklet thread (calls are\n // happening in FIFO order, so we will always have actual value).\n const updateSharedHandlers = () => {\n handlers.value = jsHandlers.current;\n };\n const setHandlers = useCallback((handler: Handlers<T>) => {\n jsHandlers.current = {\n ...jsHandlers.current,\n ...handler,\n };\n updateSharedHandlers();\n }, []);\n const broadcast = (type: keyof T, event: NativeEvent) => {\n 'worklet';\n\n Object.keys(handlers.value).forEach((key) =>\n handlers.value[key]?.[type]?.(event)\n );\n };\n\n return { setHandlers, broadcast };\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,WAAT,EAAsBC,MAAtB,QAAoC,OAApC;AACA,SAASC,QAAT,QAAyB,cAAzB;AACA,SAASC,QAAT,EAAmBC,UAAnB,EAA+BC,cAA/B,QAAqD,yBAArD;AAIA,OAAO,SAASC,0BAAT,CAGLC,QAHK,EAQLC,YARK,EASL;EACA,MAAM;IAAEC,OAAF;IAAWC;EAAX,IAAoCN,UAAU,CAACG,QAAD,EAAWC,YAAX,CAApD;EAEA,OAAOL,QAAQ,CACZQ,KAAD,IAAuC;IACrC;;IACA,MAAM;MAAEC,mBAAF;MAAuBC,cAAvB;MAAuCC;IAAvC,IACJP,QADF;;IAGA,IACEK,mBAAmB,IACnBD,KAAK,CAACI,SAAN,CAAgBC,QAAhB,CAAyB,qBAAzB,CAFF,EAGE;MACAJ,mBAAmB,CAACD,KAAD,EAAQF,OAAR,CAAnB;IACD;;IAED,IAAII,cAAc,IAAIF,KAAK,CAACI,SAAN,CAAgBC,QAAhB,CAAyB,gBAAzB,CAAtB,EAAkE;MAChEH,cAAc,CAACF,KAAD,EAAQF,OAAR,CAAd;IACD;;IAED,IAAIK,iBAAiB,IAA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hC,MAAM,CAAwB,IAAxB,CAAlB;;EAEA,IAAIgC,GAAG,CAACZ,OAAJ,IAAe,IAAnB,EAAyB;IACvBY,GAAG,CAACZ,OAAJ,GAAc,IAAInB,QAAQ,CAACgC,KAAb,CAAmBH,YAAnB,EAAiCC,MAAjC,CAAd;EACD;;EAED,OAAOC,GAAG,CAACZ,OAAX;AACD"}
@@ -1 +1 @@
1
- {"version":3,"names":["Platform","NativeEventEmitter","LINKING_ERROR","select","ios","default","AndroidSoftInputModes","RCTKeyboardController","require","KeyboardController","Proxy","get","Error","eventEmitter","KeyboardEvents","addListener","name","cb","KeyboardControllerView"],"sources":["native.ts"],"sourcesContent":["import { Platform, NativeEventEmitter } from 'react-native';\n\nimport type {\n KeyboardControllerEvents,\n KeyboardControllerModule,\n KeyboardEventData,\n} from './types';\n\nconst LINKING_ERROR =\n `The package 'react-native-keyboard-controller' doesn't seem to be linked. Make sure: \\n\\n` +\n Platform.select({ ios: \"- You have run 'pod install'\\n\", default: '' }) +\n '- You rebuilt the app after installing the package\\n' +\n '- You are not using Expo Go\\n';\n\n// copied from `android.view.WindowManager.LayoutParams`\nexport enum AndroidSoftInputModes {\n SOFT_INPUT_ADJUST_NOTHING = 48,\n SOFT_INPUT_ADJUST_PAN = 32,\n SOFT_INPUT_ADJUST_RESIZE = 16,\n SOFT_INPUT_ADJUST_UNSPECIFIED = 0,\n SOFT_INPUT_IS_FORWARD_NAVIGATION = 256,\n SOFT_INPUT_MASK_ADJUST = 240,\n SOFT_INPUT_MASK_STATE = 15,\n SOFT_INPUT_MODE_CHANGED = 512,\n SOFT_INPUT_STATE_ALWAYS_HIDDEN = 3,\n SOFT_INPUT_STATE_ALWAYS_VISIBLE = 5,\n SOFT_INPUT_STATE_HIDDEN = 2,\n SOFT_INPUT_STATE_UNCHANGED = 1,\n SOFT_INPUT_STATE_UNSPECIFIED = 0,\n SOFT_INPUT_STATE_VISIBLE = 4,\n}\n\nconst RCTKeyboardController =\n require('./specs/NativeKeyboardController').default;\nexport const KeyboardController = (\n RCTKeyboardController\n ? RCTKeyboardController\n : new Proxy(\n {},\n {\n get() {\n throw new Error(LINKING_ERROR);\n },\n }\n )\n) as KeyboardControllerModule;\n\nconst eventEmitter = new NativeEventEmitter(KeyboardController);\n\nexport const KeyboardEvents = {\n addListener: (\n name: KeyboardControllerEvents,\n cb: (e: KeyboardEventData) => void\n ) => eventEmitter.addListener('KeyboardController::' + name, cb),\n};\nexport const KeyboardControllerView =\n require('./specs/KeyboardControllerViewNativeComponent').default;\n"],"mappings":"AAAA,SAASA,QAAT,EAAmBC,kBAAnB,QAA6C,cAA7C;AAQA,MAAMC,aAAa,GAChB,2FAAD,GACAF,QAAQ,CAACG,MAAT,CAAgB;EAAEC,GAAG,EAAE,gCAAP;EAAyCC,OAAO,EAAE;AAAlD,CAAhB,CADA,GAEA,sDAFA,GAGA,+BAJF,C,CAMA;;AACA,WAAYC,qBAAZ;;WAAYA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;GAAAA,qB,KAAAA,qB;;AAiBZ,MAAMC,qBAAqB,GACzBC,OAAO,CAAC,kCAAD,CAAP,CAA4CH,OAD9C;;AAEA,OAAO,MAAMI,kBAAkB,GAC7BF,qBAAqB,GACjBA,qBADiB,GAEjB,IAAIG,KAAJ,CACE,EADF,EAEE;EACEC,GAAG,GAAG;IACJ,MAAM,IAAIC,KAAJ,CAAUV,aAAV,CAAN;EACD;;AAHH,CAFF,CAHC;AAaP,MAAMW,YAAY,GAAG,IAAIZ,kBAAJ,CAAuBQ,kBAAvB,CAArB;AAEA,OAAO,MAAMK,cAAc,GAAG;EAC5BC,WAAW,EAAE,CACXC,IADW,EAEXC,EAFW,KAGRJ,YAAY,CAACE,WAAb,CAAyB,yBAAyBC,IAAlD,EAAwDC,EAAxD;AAJuB,CAAvB;AAMP,OAAO,MAAMC,sBAAsB,GACjCV,OAAO,CAAC,+CAAD,CAAP,CAAyDH,OADpD"}
1
+ {"version":3,"names":["Platform","NativeEventEmitter","LINKING_ERROR","select","ios","default","AndroidSoftInputModes","RCTKeyboardController","require","KeyboardController","Proxy","get","Error","eventEmitter","KeyboardEvents","addListener","name","cb","KeyboardControllerView"],"sources":["native.ts"],"sourcesContent":["import { Platform, NativeEventEmitter } from 'react-native';\n\nimport type {\n KeyboardControllerEvents,\n KeyboardControllerModule,\n KeyboardControllerProps,\n KeyboardEventData,\n} from './types';\n\nconst LINKING_ERROR =\n `The package 'react-native-keyboard-controller' doesn't seem to be linked. Make sure: \\n\\n` +\n Platform.select({ ios: \"- You have run 'pod install'\\n\", default: '' }) +\n '- You rebuilt the app after installing the package\\n' +\n '- You are not using Expo Go\\n';\n\n// copied from `android.view.WindowManager.LayoutParams`\nexport enum AndroidSoftInputModes {\n SOFT_INPUT_ADJUST_NOTHING = 48,\n SOFT_INPUT_ADJUST_PAN = 32,\n SOFT_INPUT_ADJUST_RESIZE = 16,\n SOFT_INPUT_ADJUST_UNSPECIFIED = 0,\n SOFT_INPUT_IS_FORWARD_NAVIGATION = 256,\n SOFT_INPUT_MASK_ADJUST = 240,\n SOFT_INPUT_MASK_STATE = 15,\n SOFT_INPUT_MODE_CHANGED = 512,\n SOFT_INPUT_STATE_ALWAYS_HIDDEN = 3,\n SOFT_INPUT_STATE_ALWAYS_VISIBLE = 5,\n SOFT_INPUT_STATE_HIDDEN = 2,\n SOFT_INPUT_STATE_UNCHANGED = 1,\n SOFT_INPUT_STATE_UNSPECIFIED = 0,\n SOFT_INPUT_STATE_VISIBLE = 4,\n}\n\nconst RCTKeyboardController =\n require('./specs/NativeKeyboardController').default;\nexport const KeyboardController = (\n RCTKeyboardController\n ? RCTKeyboardController\n : new Proxy(\n {},\n {\n get() {\n throw new Error(LINKING_ERROR);\n },\n }\n )\n) as KeyboardControllerModule;\n\nconst eventEmitter = new NativeEventEmitter(KeyboardController);\n\nexport const KeyboardEvents = {\n addListener: (\n name: KeyboardControllerEvents,\n cb: (e: KeyboardEventData) => void\n ) => eventEmitter.addListener('KeyboardController::' + name, cb),\n};\nexport const KeyboardControllerView: React.FC<KeyboardControllerProps> =\n require('./specs/KeyboardControllerViewNativeComponent').default;\n"],"mappings":"AAAA,SAASA,QAAT,EAAmBC,kBAAnB,QAA6C,cAA7C;AASA,MAAMC,aAAa,GAChB,2FAAD,GACAF,QAAQ,CAACG,MAAT,CAAgB;EAAEC,GAAG,EAAE,gCAAP;EAAyCC,OAAO,EAAE;AAAlD,CAAhB,CADA,GAEA,sDAFA,GAGA,+BAJF,C,CAMA;;AACA,WAAYC,qBAAZ;;WAAYA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;GAAAA,qB,KAAAA,qB;;AAiBZ,MAAMC,qBAAqB,GACzBC,OAAO,CAAC,kCAAD,CAAP,CAA4CH,OAD9C;;AAEA,OAAO,MAAMI,kBAAkB,GAC7BF,qBAAqB,GACjBA,qBADiB,GAEjB,IAAIG,KAAJ,CACE,EADF,EAEE;EACEC,GAAG,GAAG;IACJ,MAAM,IAAIC,KAAJ,CAAUV,aAAV,CAAN;EACD;;AAHH,CAFF,CAHC;AAaP,MAAMW,YAAY,GAAG,IAAIZ,kBAAJ,CAAuBQ,kBAAvB,CAArB;AAEA,OAAO,MAAMK,cAAc,GAAG;EAC5BC,WAAW,EAAE,CACXC,IADW,EAEXC,EAFW,KAGRJ,YAAY,CAACE,WAAb,CAAyB,yBAAyBC,IAAlD,EAAwDC,EAAxD;AAJuB,CAAvB;AAMP,OAAO,MAAMC,sBAAyD,GACpEV,OAAO,CAAC,+CAAD,CAAP,CAAyDH,OADpD"}
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { NativeSyntheticEvent, ViewProps } from 'react-native';\n\n// DirectEventHandler events declaration\n\nexport type NativeEvent = {\n progress: number;\n height: number;\n};\nexport type EventWithName<T> = {\n eventName: string;\n} & T;\n\n// native View/Module declarations\n\nexport type KeyboardControllerProps = {\n onKeyboardMoveStart?: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n onKeyboardMove?: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n onKeyboardMoveEnd?: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n // fake prop used to activate reanimated bindings\n onKeyboardMoveReanimated: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n statusBarTranslucent?: boolean;\n} & ViewProps;\n\nexport type KeyboardControllerModule = {\n // android only\n setDefaultMode: () => void;\n setInputMode: (mode: number) => void;\n // native event module stuff\n addListener: (eventName: string) => void;\n removeListeners: (count: number) => void;\n};\n\n// Event module declarations\n\nexport type KeyboardControllerEvents =\n | 'keyboardWillShow'\n | 'keyboardDidShow'\n | 'keyboardWillHide'\n | 'keyboardDidHide';\nexport type KeyboardEventData = {\n height: number;\n};\n\n// package types\n\nexport type Handlers<T> = Record<string, T | undefined>;\nexport type KeyboardHandler = {\n onStart?: (e: NativeEvent) => void;\n onMove?: (e: NativeEvent) => void;\n onEnd?: (e: NativeEvent) => void;\n};\nexport type KeyboardHandlers = Handlers<KeyboardHandler>;\n"],"mappings":""}
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { NativeSyntheticEvent, ViewProps } from 'react-native';\n\n// DirectEventHandler events declaration\n\nexport type NativeEvent = {\n progress: number;\n height: number;\n};\nexport type EventWithName<T> = {\n eventName: string;\n} & T;\n\n// native View/Module declarations\n\nexport type KeyboardControllerProps = {\n onKeyboardMoveStart?: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n onKeyboardMove?: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n onKeyboardMoveEnd?: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n // fake prop used to activate reanimated bindings\n onKeyboardMoveReanimated?: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n statusBarTranslucent?: boolean;\n} & ViewProps;\n\nexport type KeyboardControllerModule = {\n // android only\n setDefaultMode: () => void;\n setInputMode: (mode: number) => void;\n // native event module stuff\n addListener: (eventName: string) => void;\n removeListeners: (count: number) => void;\n};\n\n// Event module declarations\n\nexport type KeyboardControllerEvents =\n | 'keyboardWillShow'\n | 'keyboardDidShow'\n | 'keyboardWillHide'\n | 'keyboardDidHide';\nexport type KeyboardEventData = {\n height: number;\n};\n\n// package types\n\nexport type Handlers<T> = Record<string, T | undefined>;\nexport type KeyboardHandler = {\n onStart?: (e: NativeEvent) => void;\n onMove?: (e: NativeEvent) => void;\n onEnd?: (e: NativeEvent) => void;\n};\nexport type KeyboardHandlers = Handlers<KeyboardHandler>;\n"],"mappings":""}
@@ -1,10 +1,4 @@
1
1
  import React from 'react';
2
- import { ViewStyle } from 'react-native';
3
- declare type Styles = {
4
- container: ViewStyle;
5
- hidden: ViewStyle;
6
- };
7
- export declare const styles: Styles;
8
2
  declare type KeyboardProviderProps = {
9
3
  children: React.ReactNode;
10
4
  /**
@@ -1,3 +1,4 @@
1
+ import { Animated } from 'react-native';
1
2
  import type { EventWithName, Handlers, NativeEvent } from './types';
2
3
  export declare function useAnimatedKeyboardHandler<TContext extends Record<string, unknown>>(handlers: {
3
4
  onKeyboardMoveStart?: (e: NativeEvent, context: TContext) => void;
@@ -19,3 +20,13 @@ export declare function useSharedHandlers<T extends Record<string, Function>>():
19
20
  setHandlers: (handler: Handlers<T>) => void;
20
21
  broadcast: (type: keyof T, event: NativeEvent) => void;
21
22
  };
23
+ /**
24
+ * TS variant of `useAnimatedValue` hook which is added in RN 0.71
25
+ * A better alternative of storing animated values in refs, since
26
+ * it doesn't recreate a new `Animated.Value` object on every re-render
27
+ * and therefore consumes less memory. We can not use a variant from
28
+ * RN, since this library supports earlier versions of RN.
29
+ *
30
+ * @see https://github.com/facebook/react-native/commit/e22217fe8b9455e32695f88ca835e11442b0a937
31
+ */
32
+ export declare function useAnimatedValue(initialValue: number, config?: Animated.AnimatedConfig): Animated.Value;
@@ -1,4 +1,5 @@
1
- import type { KeyboardControllerEvents, KeyboardControllerModule, KeyboardEventData } from './types';
1
+ /// <reference types="react" />
2
+ import type { KeyboardControllerEvents, KeyboardControllerModule, KeyboardControllerProps, KeyboardEventData } from './types';
2
3
  export declare enum AndroidSoftInputModes {
3
4
  SOFT_INPUT_ADJUST_NOTHING = 48,
4
5
  SOFT_INPUT_ADJUST_PAN = 32,
@@ -19,4 +20,4 @@ export declare const KeyboardController: KeyboardControllerModule;
19
20
  export declare const KeyboardEvents: {
20
21
  addListener: (name: KeyboardControllerEvents, cb: (e: KeyboardEventData) => void) => import("react-native").EmitterSubscription;
21
22
  };
22
- export declare const KeyboardControllerView: any;
23
+ export declare const KeyboardControllerView: React.FC<KeyboardControllerProps>;
@@ -10,7 +10,7 @@ export declare type KeyboardControllerProps = {
10
10
  onKeyboardMoveStart?: (e: NativeSyntheticEvent<EventWithName<NativeEvent>>) => void;
11
11
  onKeyboardMove?: (e: NativeSyntheticEvent<EventWithName<NativeEvent>>) => void;
12
12
  onKeyboardMoveEnd?: (e: NativeSyntheticEvent<EventWithName<NativeEvent>>) => void;
13
- onKeyboardMoveReanimated: (e: NativeSyntheticEvent<EventWithName<NativeEvent>>) => void;
13
+ onKeyboardMoveReanimated?: (e: NativeSyntheticEvent<EventWithName<NativeEvent>>) => void;
14
14
  statusBarTranslucent?: boolean;
15
15
  } & ViewProps;
16
16
  export declare type KeyboardControllerModule = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-keyboard-controller",
3
- "version": "1.4.1",
3
+ "version": "1.4.3",
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",
@@ -14,6 +14,7 @@
14
14
  "ios",
15
15
  "cpp",
16
16
  "react-native-keyboard-controller.podspec",
17
+ "jest",
17
18
  "!lib/typescript/example",
18
19
  "!android/build",
19
20
  "!android/.gradle",
@@ -59,7 +60,7 @@
59
60
  "@release-it/conventional-changelog": "^2.0.0",
60
61
  "@types/jest": "^27.4.1",
61
62
  "@types/react": "^18.0.21",
62
- "@types/react-native": "0.70.4",
63
+ "@types/react-native": "0.70.6",
63
64
  "commitlint": "^11.0.0",
64
65
  "clang-format": "^1.8.0",
65
66
  "eslint": "^7.2.0",
@@ -128,6 +129,9 @@
128
129
  }
129
130
  ],
130
131
  "react-hooks/exhaustive-deps": "warn"
132
+ },
133
+ "globals": {
134
+ "jest": "readonly"
131
135
  }
132
136
  },
133
137
  "eslintIgnore": [
package/src/animated.tsx CHANGED
@@ -1,9 +1,13 @@
1
- import React, { useMemo, useRef } from 'react';
1
+ import React, { useMemo } from 'react';
2
2
  import { Animated, Platform, StyleSheet, ViewStyle } from 'react-native';
3
3
  import Reanimated, { useSharedValue } from 'react-native-reanimated';
4
4
 
5
5
  import { KeyboardContext } from './context';
6
- import { useAnimatedKeyboardHandler, useSharedHandlers } from './internal';
6
+ import {
7
+ useAnimatedKeyboardHandler,
8
+ useSharedHandlers,
9
+ useAnimatedValue,
10
+ } from './internal';
7
11
  import { KeyboardControllerView } from './native';
8
12
 
9
13
  import type {
@@ -23,7 +27,7 @@ type Styles = {
23
27
  hidden: ViewStyle;
24
28
  };
25
29
 
26
- export const styles = StyleSheet.create<Styles>({
30
+ const styles = StyleSheet.create<Styles>({
27
31
  container: {
28
32
  flex: 1,
29
33
  },
@@ -52,8 +56,8 @@ export const KeyboardProvider = ({
52
56
  statusBarTranslucent,
53
57
  }: KeyboardProviderProps) => {
54
58
  // animated values
55
- const progress = useRef(new Animated.Value(0)).current;
56
- const height = useRef(new Animated.Value(0)).current;
59
+ const progress = useAnimatedValue(0);
60
+ const height = useAnimatedValue(0);
57
61
  // shared values
58
62
  const progressSV = useSharedValue(0);
59
63
  const heightSV = useSharedValue(0);
package/src/internal.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { useCallback, useRef } from 'react';
2
+ import { Animated } from 'react-native';
2
3
  import { useEvent, useHandler, useSharedValue } from 'react-native-reanimated';
3
4
 
4
5
  import type { EventWithName, Handlers, NativeEvent } from './types';
@@ -85,3 +86,25 @@ export function useSharedHandlers<T extends Record<string, Function>>() {
85
86
 
86
87
  return { setHandlers, broadcast };
87
88
  }
89
+
90
+ /**
91
+ * TS variant of `useAnimatedValue` hook which is added in RN 0.71
92
+ * A better alternative of storing animated values in refs, since
93
+ * it doesn't recreate a new `Animated.Value` object on every re-render
94
+ * and therefore consumes less memory. We can not use a variant from
95
+ * RN, since this library supports earlier versions of RN.
96
+ *
97
+ * @see https://github.com/facebook/react-native/commit/e22217fe8b9455e32695f88ca835e11442b0a937
98
+ */
99
+ export function useAnimatedValue(
100
+ initialValue: number,
101
+ config?: Animated.AnimatedConfig
102
+ ): Animated.Value {
103
+ const ref = useRef<Animated.Value | null>(null);
104
+
105
+ if (ref.current == null) {
106
+ ref.current = new Animated.Value(initialValue, config);
107
+ }
108
+
109
+ return ref.current;
110
+ }
package/src/native.ts CHANGED
@@ -3,6 +3,7 @@ import { Platform, NativeEventEmitter } from 'react-native';
3
3
  import type {
4
4
  KeyboardControllerEvents,
5
5
  KeyboardControllerModule,
6
+ KeyboardControllerProps,
6
7
  KeyboardEventData,
7
8
  } from './types';
8
9
 
@@ -53,5 +54,5 @@ export const KeyboardEvents = {
53
54
  cb: (e: KeyboardEventData) => void
54
55
  ) => eventEmitter.addListener('KeyboardController::' + name, cb),
55
56
  };
56
- export const KeyboardControllerView =
57
+ export const KeyboardControllerView: React.FC<KeyboardControllerProps> =
57
58
  require('./specs/KeyboardControllerViewNativeComponent').default;
package/src/types.ts CHANGED
@@ -23,7 +23,7 @@ export type KeyboardControllerProps = {
23
23
  e: NativeSyntheticEvent<EventWithName<NativeEvent>>
24
24
  ) => void;
25
25
  // fake prop used to activate reanimated bindings
26
- onKeyboardMoveReanimated: (
26
+ onKeyboardMoveReanimated?: (
27
27
  e: NativeSyntheticEvent<EventWithName<NativeEvent>>
28
28
  ) => void;
29
29
  statusBarTranslucent?: boolean;