react-native-keyboard-controller 1.5.0 → 1.5.2

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.
@@ -32,16 +32,13 @@ class KeyboardGestureAreaViewManager(mReactContext: ReactApplicationContext) :
32
32
  manager.setInterpolator(view as KeyboardGestureAreaReactViewGroup, value ?: "linear")
33
33
  }
34
34
 
35
- @ReactProp(name = "allowToShowKeyboardFromHiddenStateBySwipeUp")
36
- override fun setAllowToShowKeyboardFromHiddenStateBySwipeUp(
37
- view: ReactViewGroup,
38
- value: Boolean,
39
- ) {
35
+ @ReactProp(name = "showOnSwipeUp")
36
+ override fun setShowOnSwipeUp(view: ReactViewGroup, value: Boolean) {
40
37
  manager.setScrollKeyboardOnScreenWhenNotVisible(view as KeyboardGestureAreaReactViewGroup, value)
41
38
  }
42
39
 
43
- @ReactProp(name = "allowToDragKeyboardFromShownStateBySwipes")
44
- override fun setAllowToDragKeyboardFromShownStateBySwipes(view: ReactViewGroup?, value: Boolean) {
40
+ @ReactProp(name = "enableSwipeToDismiss")
41
+ override fun setEnableSwipeToDismiss(view: ReactViewGroup?, value: Boolean) {
45
42
  manager.setScrollKeyboardOffScreenWhenVisible(view as KeyboardGestureAreaReactViewGroup, value)
46
43
  }
47
44
  }
@@ -156,7 +156,7 @@ class KeyboardAnimationCallback(
156
156
  // then we need to reset the state
157
157
  InteractiveKeyboardProvider.shown = false
158
158
  }
159
- val isKeyboardVisible = isKeyboardVisible || isKeyboardShown
159
+ isKeyboardVisible = isKeyboardVisible || isKeyboardShown
160
160
 
161
161
  this.emitEvent("KeyboardController::" + if (!isKeyboardVisible) "keyboardDidHide" else "keyboardDidShow", getEventParams(this.persistentKeyboardHeight))
162
162
  this.sendEventToJS(KeyboardTransitionEvent(view.id, "topKeyboardMoveEnd", this.persistentKeyboardHeight, if (!isKeyboardVisible) 0.0 else 1.0))
@@ -21,12 +21,12 @@ class KeyboardGestureAreaViewManager(mReactContext: ReactApplicationContext) : R
21
21
  manager.setInterpolator(view, interpolator)
22
22
  }
23
23
 
24
- @ReactProp(name = "allowToShowKeyboardFromHiddenStateBySwipeUp")
24
+ @ReactProp(name = "showOnSwipeUp")
25
25
  fun setScrollKeyboardOnScreenWhenNotVisible(view: KeyboardGestureAreaReactViewGroup, value: Boolean) {
26
26
  manager.setScrollKeyboardOnScreenWhenNotVisible(view, value)
27
27
  }
28
28
 
29
- @ReactProp(name = "allowToDragKeyboardFromShownStateBySwipes")
29
+ @ReactProp(name = "enableSwipeToDismiss")
30
30
  fun setScrollKeyboardOffScreenWhenVisible(view: KeyboardGestureAreaReactViewGroup, value: Boolean) {
31
31
  manager.setScrollKeyboardOffScreenWhenVisible(view, value)
32
32
  }
@@ -42,6 +42,7 @@ public class KeyboardMovementObserver: NSObject {
42
42
  private var prevKeyboardPosition = 0.0
43
43
  private var displayLink: CADisplayLink?
44
44
  private var keyboardHeight: CGFloat = 0.0
45
+ private var hasKVObserver = false
45
46
 
46
47
  @objc public init(
47
48
  handler: @escaping (NSString, NSNumber, NSNumber) -> Void,
@@ -82,18 +83,40 @@ public class KeyboardMovementObserver: NSObject {
82
83
  name: UIWindow.didBecomeVisibleNotification,
83
84
  object: nil
84
85
  )
86
+ NotificationCenter.default.addObserver(
87
+ self,
88
+ selector: #selector(windowDidBecomeHidden),
89
+ name: UIWindow.didBecomeHiddenNotification,
90
+ object: nil
91
+ )
92
+ }
93
+
94
+ @objc func windowDidBecomeHidden(_: Notification) {
95
+ removeKVObserver()
85
96
  }
86
97
 
87
98
  @objc func windowDidBecomeVisible(_: Notification) {
88
- let keyboardView = findKeyboardView()
99
+ setupKVObserver()
100
+ }
89
101
 
90
- if keyboardView == _keyboardView {
102
+ private func setupKVObserver() {
103
+ if hasKVObserver {
91
104
  return
92
105
  }
93
106
 
94
- _keyboardView = keyboardView
107
+ if keyboardView != nil {
108
+ hasKVObserver = true
109
+ keyboardView?.addObserver(self, forKeyPath: "center", options: .new, context: nil)
110
+ }
111
+ }
112
+
113
+ private func removeKVObserver() {
114
+ if !hasKVObserver {
115
+ return
116
+ }
95
117
 
96
- keyboardView?.addObserver(self, forKeyPath: "center", options: .new, context: nil)
118
+ hasKVObserver = false
119
+ keyboardView?.removeObserver(self, forKeyPath: "center", context: nil)
97
120
  }
98
121
 
99
122
  // swiftlint:disable:next block_based_kvo
@@ -1 +1 @@
1
- {"version":3,"names":["codegenNativeComponent","excludedPlatforms"],"sources":["KeyboardGestureAreaNativeComponent.ts"],"sourcesContent":["import type { HostComponent } from 'react-native';\nimport type { ViewProps } from 'react-native/Libraries/Components/View/ViewPropTypes';\nimport type { WithDefault } from 'react-native/Libraries/Types/CodegenTypes';\nimport codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';\n\nexport interface NativeProps extends ViewProps {\n interpolator?: WithDefault<'linear' | 'ios', 'linear'>;\n allowToShowKeyboardFromHiddenStateBySwipeUp?: boolean;\n allowToDragKeyboardFromShownStateBySwipes?: boolean;\n}\n\nexport default codegenNativeComponent<NativeProps>('KeyboardGestureArea', {\n excludedPlatforms: ['iOS'],\n}) as HostComponent<NativeProps>;\n"],"mappings":";;;;;;AAGA;AAA6F;AAAA,eAQ9E,IAAAA,+BAAsB,EAAc,qBAAqB,EAAE;EACxEC,iBAAiB,EAAE,CAAC,KAAK;AAC3B,CAAC,CAAC;AAAA"}
1
+ {"version":3,"names":["codegenNativeComponent","excludedPlatforms"],"sources":["KeyboardGestureAreaNativeComponent.ts"],"sourcesContent":["import type { HostComponent } from 'react-native';\nimport type { ViewProps } from 'react-native/Libraries/Components/View/ViewPropTypes';\nimport type { WithDefault } from 'react-native/Libraries/Types/CodegenTypes';\nimport codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';\n\nexport interface NativeProps extends ViewProps {\n interpolator?: WithDefault<'linear' | 'ios', 'linear'>;\n showOnSwipeUp?: boolean;\n enableSwipeToDismiss?: boolean;\n}\n\nexport default codegenNativeComponent<NativeProps>('KeyboardGestureArea', {\n excludedPlatforms: ['iOS'],\n}) as HostComponent<NativeProps>;\n"],"mappings":";;;;;;AAGA;AAA6F;AAAA,eAQ9E,IAAAA,+BAAsB,EAAc,qBAAqB,EAAE;EACxEC,iBAAiB,EAAE,CAAC,KAAK;AAC3B,CAAC,CAAC;AAAA"}
@@ -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 onKeyboardMoveInteractive?: (\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 navigationBarTranslucent?: boolean;\n} & ViewProps;\n\nexport type KeyboardGestureAreaProps = {\n interpolator: 'ios' | 'linear';\n /**\n * Whether to allow to show a keyboard from dismissed state by swipe up.\n * Default to `false`.\n */\n allowToShowKeyboardFromHiddenStateBySwipeUp?: boolean;\n /**\n * Whether to allow to control a keyboard by gestures. The strategy how\n * it should be controlled is determined by `interpolator` property.\n * Defaults to `true`.\n */\n allowToDragKeyboardFromShownStateBySwipes?: 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 = Partial<{\n onStart: (e: NativeEvent) => void;\n onMove: (e: NativeEvent) => void;\n onEnd: (e: NativeEvent) => void;\n onInteractive: (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 onKeyboardMoveInteractive?: (\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 navigationBarTranslucent?: boolean;\n} & ViewProps;\n\nexport type KeyboardGestureAreaProps = {\n interpolator: 'ios' | 'linear';\n /**\n * Whether to allow to show a keyboard from dismissed state by swipe up.\n * Default to `false`.\n */\n showOnSwipeUp?: boolean;\n /**\n * Whether to allow to control a keyboard by gestures. The strategy how\n * it should be controlled is determined by `interpolator` property.\n * Defaults to `true`.\n */\n enableSwipeToDismiss?: 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 = Partial<{\n onStart: (e: NativeEvent) => void;\n onMove: (e: NativeEvent) => void;\n onEnd: (e: NativeEvent) => void;\n onInteractive: (e: NativeEvent) => void;\n}>;\nexport type KeyboardHandlers = Handlers<KeyboardHandler>;\n"],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"names":["codegenNativeComponent","excludedPlatforms"],"sources":["KeyboardGestureAreaNativeComponent.ts"],"sourcesContent":["import type { HostComponent } from 'react-native';\nimport type { ViewProps } from 'react-native/Libraries/Components/View/ViewPropTypes';\nimport type { WithDefault } from 'react-native/Libraries/Types/CodegenTypes';\nimport codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';\n\nexport interface NativeProps extends ViewProps {\n interpolator?: WithDefault<'linear' | 'ios', 'linear'>;\n allowToShowKeyboardFromHiddenStateBySwipeUp?: boolean;\n allowToDragKeyboardFromShownStateBySwipes?: boolean;\n}\n\nexport default codegenNativeComponent<NativeProps>('KeyboardGestureArea', {\n excludedPlatforms: ['iOS'],\n}) as HostComponent<NativeProps>;\n"],"mappings":"AAGA,OAAOA,sBAAsB,MAAM,yDAAyD;AAQ5F,eAAeA,sBAAsB,CAAc,qBAAqB,EAAE;EACxEC,iBAAiB,EAAE,CAAC,KAAK;AAC3B,CAAC,CAAC"}
1
+ {"version":3,"names":["codegenNativeComponent","excludedPlatforms"],"sources":["KeyboardGestureAreaNativeComponent.ts"],"sourcesContent":["import type { HostComponent } from 'react-native';\nimport type { ViewProps } from 'react-native/Libraries/Components/View/ViewPropTypes';\nimport type { WithDefault } from 'react-native/Libraries/Types/CodegenTypes';\nimport codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';\n\nexport interface NativeProps extends ViewProps {\n interpolator?: WithDefault<'linear' | 'ios', 'linear'>;\n showOnSwipeUp?: boolean;\n enableSwipeToDismiss?: boolean;\n}\n\nexport default codegenNativeComponent<NativeProps>('KeyboardGestureArea', {\n excludedPlatforms: ['iOS'],\n}) as HostComponent<NativeProps>;\n"],"mappings":"AAGA,OAAOA,sBAAsB,MAAM,yDAAyD;AAQ5F,eAAeA,sBAAsB,CAAc,qBAAqB,EAAE;EACxEC,iBAAiB,EAAE,CAAC,KAAK;AAC3B,CAAC,CAAC"}
@@ -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 onKeyboardMoveInteractive?: (\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 navigationBarTranslucent?: boolean;\n} & ViewProps;\n\nexport type KeyboardGestureAreaProps = {\n interpolator: 'ios' | 'linear';\n /**\n * Whether to allow to show a keyboard from dismissed state by swipe up.\n * Default to `false`.\n */\n allowToShowKeyboardFromHiddenStateBySwipeUp?: boolean;\n /**\n * Whether to allow to control a keyboard by gestures. The strategy how\n * it should be controlled is determined by `interpolator` property.\n * Defaults to `true`.\n */\n allowToDragKeyboardFromShownStateBySwipes?: 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 = Partial<{\n onStart: (e: NativeEvent) => void;\n onMove: (e: NativeEvent) => void;\n onEnd: (e: NativeEvent) => void;\n onInteractive: (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 onKeyboardMoveInteractive?: (\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 navigationBarTranslucent?: boolean;\n} & ViewProps;\n\nexport type KeyboardGestureAreaProps = {\n interpolator: 'ios' | 'linear';\n /**\n * Whether to allow to show a keyboard from dismissed state by swipe up.\n * Default to `false`.\n */\n showOnSwipeUp?: boolean;\n /**\n * Whether to allow to control a keyboard by gestures. The strategy how\n * it should be controlled is determined by `interpolator` property.\n * Defaults to `true`.\n */\n enableSwipeToDismiss?: 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 = Partial<{\n onStart: (e: NativeEvent) => void;\n onMove: (e: NativeEvent) => void;\n onEnd: (e: NativeEvent) => void;\n onInteractive: (e: NativeEvent) => void;\n}>;\nexport type KeyboardHandlers = Handlers<KeyboardHandler>;\n"],"mappings":""}
@@ -3,8 +3,8 @@ import type { ViewProps } from 'react-native/Libraries/Components/View/ViewPropT
3
3
  import type { WithDefault } from 'react-native/Libraries/Types/CodegenTypes';
4
4
  export interface NativeProps extends ViewProps {
5
5
  interpolator?: WithDefault<'linear' | 'ios', 'linear'>;
6
- allowToShowKeyboardFromHiddenStateBySwipeUp?: boolean;
7
- allowToDragKeyboardFromShownStateBySwipes?: boolean;
6
+ showOnSwipeUp?: boolean;
7
+ enableSwipeToDismiss?: boolean;
8
8
  }
9
9
  declare const _default: HostComponent<NativeProps>;
10
10
  export default _default;
@@ -21,13 +21,13 @@ export type KeyboardGestureAreaProps = {
21
21
  * Whether to allow to show a keyboard from dismissed state by swipe up.
22
22
  * Default to `false`.
23
23
  */
24
- allowToShowKeyboardFromHiddenStateBySwipeUp?: boolean;
24
+ showOnSwipeUp?: boolean;
25
25
  /**
26
26
  * Whether to allow to control a keyboard by gestures. The strategy how
27
27
  * it should be controlled is determined by `interpolator` property.
28
28
  * Defaults to `true`.
29
29
  */
30
- allowToDragKeyboardFromShownStateBySwipes?: boolean;
30
+ enableSwipeToDismiss?: boolean;
31
31
  } & ViewProps;
32
32
  export type KeyboardControllerModule = {
33
33
  setDefaultMode: () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-keyboard-controller",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
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",
@@ -5,8 +5,8 @@ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNati
5
5
 
6
6
  export interface NativeProps extends ViewProps {
7
7
  interpolator?: WithDefault<'linear' | 'ios', 'linear'>;
8
- allowToShowKeyboardFromHiddenStateBySwipeUp?: boolean;
9
- allowToDragKeyboardFromShownStateBySwipes?: boolean;
8
+ showOnSwipeUp?: boolean;
9
+ enableSwipeToDismiss?: boolean;
10
10
  }
11
11
 
12
12
  export default codegenNativeComponent<NativeProps>('KeyboardGestureArea', {
package/src/types.ts CHANGED
@@ -39,13 +39,13 @@ export type KeyboardGestureAreaProps = {
39
39
  * Whether to allow to show a keyboard from dismissed state by swipe up.
40
40
  * Default to `false`.
41
41
  */
42
- allowToShowKeyboardFromHiddenStateBySwipeUp?: boolean;
42
+ showOnSwipeUp?: boolean;
43
43
  /**
44
44
  * Whether to allow to control a keyboard by gestures. The strategy how
45
45
  * it should be controlled is determined by `interpolator` property.
46
46
  * Defaults to `true`.
47
47
  */
48
- allowToDragKeyboardFromShownStateBySwipes?: boolean;
48
+ enableSwipeToDismiss?: boolean;
49
49
  } & ViewProps;
50
50
 
51
51
  export type KeyboardControllerModule = {