react-native-keyboard-controller 1.0.0-alpha.0 → 1.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,24 +7,25 @@ Keyboard manager which works in identical way on both iOS and Android.
7
7
  ## Demonstration
8
8
 
9
9
  <div>
10
- <img align="right" width="30%" style="margin-left: 20px" src="./gifs/ios.gif?raw=true">
11
- <img align="right" width="30%" style="margin-left: 20px" src="./gifs/android.gif?raw=true">
10
+ <img align="right" width="28.65%" style="margin-left: 20px" src="./gifs/ios.gif?raw=true">
11
+ <img align="right" width="30%" style="margin-left: 20px" src="./gifs/android.gif?raw=true">
12
12
  </div>
13
13
 
14
14
  - mapping keyboard appearance to animated values 😎
15
- - missing `keyboardWillShow`/`keyboardWillHide` events are available on Android 😍
15
+ - missing `keyboardWillShow` / `keyboardWillHide` events are available on Android 😍
16
16
  - module for changing soft input mode on Android 🤔
17
17
  - reanimated support 🚀
18
18
  - interactive keyboard dismissing (planned) 👆📱
19
19
  - and more is coming... Stay tuned! 😊
20
20
 
21
+ <br clear="right" />
22
+
21
23
  ## Installation
22
24
 
23
25
  Install `react-native-keyboard-controller` package from npm:
24
26
 
25
27
  ```sh
26
28
  yarn add react-native-keyboard-controller
27
-
28
29
  # or
29
30
  # npm install react-native-keyboard-controller --save
30
31
  ```
@@ -17,6 +17,7 @@
17
17
  package com.reactnativekeyboardcontroller
18
18
 
19
19
  import android.content.Context
20
+ import android.util.Log
20
21
  import androidx.core.graphics.Insets
21
22
  import androidx.core.view.ViewCompat
22
23
  import androidx.core.view.WindowInsetsAnimationCompat
@@ -56,6 +57,7 @@ class TranslateDeferringInsetsAnimationCallback(
56
57
  dispatchMode: Int = DISPATCH_MODE_STOP,
57
58
  val context: ReactApplicationContext?
58
59
  ) : WindowInsetsAnimationCompat.Callback(dispatchMode) {
60
+ private val TAG = TranslateDeferringInsetsAnimationCallback::class.qualifiedName
59
61
  private var persistentKeyboardHeight = 0
60
62
 
61
63
  init {
@@ -81,8 +83,8 @@ class TranslateDeferringInsetsAnimationCallback(
81
83
  params.putInt("height", keyboardHeight)
82
84
  context?.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)?.emit("KeyboardController::" + if(!isKeyboardVisible) "keyboardWillHide" else "keyboardWillShow", params)
83
85
 
84
- println("KeyboardController::" + if(!isKeyboardVisible) "keyboardWillHide" else "keyboardWillShow")
85
- println("HEIGHT:: " + keyboardHeight)
86
+ Log.i(TAG, "KeyboardController::" + if(!isKeyboardVisible) "keyboardWillHide" else "keyboardWillShow")
87
+ Log.i(TAG, "HEIGHT:: $keyboardHeight")
86
88
 
87
89
  return super.onStart(animation, bounds)
88
90
  }
@@ -95,7 +97,7 @@ class TranslateDeferringInsetsAnimationCallback(
95
97
  val params: WritableMap = Arguments.createMap()
96
98
  context?.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)?.emit("KeyboardController::" + if(!isKeyboardVisible) "keyboardDidHide" else "keyboardDidShow", params)
97
99
 
98
- println("KeyboardController::" + if(!isKeyboardVisible) "keyboardDidHide" else "keyboardDidShow")
100
+ Log.i(TAG, "KeyboardController::" + if(!isKeyboardVisible) "keyboardDidHide" else "keyboardDidShow")
99
101
  }
100
102
 
101
103
  private fun isKeyboardVisible(): Boolean {
@@ -138,7 +140,7 @@ class TranslateDeferringInsetsAnimationCallback(
138
140
  } catch (e: ArithmeticException) {
139
141
  // do nothing, send progress as 0
140
142
  }
141
- println("DiffY: " + diffY + " " + height)
143
+ Log.i(TAG, "DiffY: $diffY $height")
142
144
 
143
145
  context
144
146
  .getNativeModule(UIManagerModule::class.java)
@@ -13,6 +13,7 @@ import AVFoundation
13
13
  @objc(KeyboardController)
14
14
  class KeyboardController: RCTEventEmitter {
15
15
  public static var shared: KeyboardController?
16
+ private var hasListeners = false
16
17
 
17
18
  override class func requiresMainQueueSetup() -> Bool {
18
19
  return false
@@ -35,4 +36,18 @@ class KeyboardController: RCTEventEmitter {
35
36
  "KeyboardController::keyboardDidHide"
36
37
  ]
37
38
  }
39
+
40
+ @objc open override func startObserving() {
41
+ hasListeners = true
42
+ }
43
+
44
+ @objc open override func stopObserving() {
45
+ hasListeners = false
46
+ }
47
+
48
+ @objc open override func sendEvent(withName name: String!, body: Any!) {
49
+ if (hasListeners) {
50
+ super.sendEvent(withName: name, body: body)
51
+ }
52
+ }
38
53
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-keyboard-controller",
3
- "version": "1.0.0-alpha.0",
3
+ "version": "1.0.0-alpha.1",
4
4
  "description": "Platform agnostic keyboard manager",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",