Skip to content

Commit dada809

Browse files
authored
refactor: migrate from deprecated RCTEventEmitter (#215)
## 📜 Description Re-worked deprecated API for `RCTEventEmitter ` on Android. Minimal supported RN version is 0.65. Updated compatibility page in docs. ## 💡 Motivation and Context Deprecated API sooner or earlier will be removed, so there is no sense to keep the usage of deprecated API. In this PR I've decided to drop a support of really old RN versions and remove usage of deprecated APIs. For that I reworked event dispatching API 🙂 ## 📢 Changelog ### Docs - added info about minimal supported version of RN for paper architecture; ### Android - added `surfaceId` to the event; - removed `dispatch` method; - override `getEventData` method. ## 🤔 How Has This Been Tested? Tested on Pixel 7 Pro (both fabric & paper). Works as before. ## 📝 Checklist - [x] CI successfully passed
1 parent 01dbb7f commit dada809

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

Diff for: android/src/main/java/com/reactnativekeyboardcontroller/KeyboardAnimationCallback.kt

+9-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class KeyboardAnimationCallback(
3232
dispatchMode: Int = DISPATCH_MODE_STOP,
3333
val context: ThemedReactContext?,
3434
) : WindowInsetsAnimationCompat.Callback(dispatchMode), OnApplyWindowInsetsListener {
35+
private val surfaceId = UIManagerHelper.getSurfaceId(view)
3536
private var persistentKeyboardHeight = 0.0
3637
private var isKeyboardVisible = false
3738
private var isTransitioning = false
@@ -57,6 +58,7 @@ class KeyboardAnimationCallback(
5758
// can bring breaking changes
5859
this.sendEventToJS(
5960
KeyboardTransitionEvent(
61+
surfaceId,
6062
view.id,
6163
"topKeyboardMoveStart",
6264
this.persistentKeyboardHeight,
@@ -67,6 +69,7 @@ class KeyboardAnimationCallback(
6769
)
6870
this.sendEventToJS(
6971
KeyboardTransitionEvent(
72+
surfaceId,
7073
view.id,
7174
"topKeyboardMoveEnd",
7275
this.persistentKeyboardHeight,
@@ -115,6 +118,7 @@ class KeyboardAnimationCallback(
115118
this.emitEvent("KeyboardController::keyboardWillShow", getEventParams(keyboardHeight))
116119
this.sendEventToJS(
117120
KeyboardTransitionEvent(
121+
surfaceId,
118122
view.id,
119123
"topKeyboardMoveStart",
120124
keyboardHeight,
@@ -129,6 +133,7 @@ class KeyboardAnimationCallback(
129133
val toValue = animator.animatedValue as Float
130134
this.sendEventToJS(
131135
KeyboardTransitionEvent(
136+
surfaceId,
132137
view.id,
133138
"topKeyboardMove",
134139
toValue.toDouble(),
@@ -142,6 +147,7 @@ class KeyboardAnimationCallback(
142147
this.emitEvent("KeyboardController::keyboardDidShow", getEventParams(keyboardHeight))
143148
this.sendEventToJS(
144149
KeyboardTransitionEvent(
150+
surfaceId,
145151
view.id,
146152
"topKeyboardMoveEnd",
147153
keyboardHeight,
@@ -182,6 +188,7 @@ class KeyboardAnimationCallback(
182188
Log.i(TAG, "HEIGHT:: $keyboardHeight TAG:: $viewTagFocused")
183189
this.sendEventToJS(
184190
KeyboardTransitionEvent(
191+
surfaceId,
185192
view.id,
186193
"topKeyboardMoveStart",
187194
keyboardHeight,
@@ -223,7 +230,7 @@ class KeyboardAnimationCallback(
223230
Log.i(TAG, "DiffY: $diffY $height $progress ${InteractiveKeyboardProvider.isInteractive} $viewTagFocused")
224231

225232
val event = if (InteractiveKeyboardProvider.isInteractive) "topKeyboardMoveInteractive" else "topKeyboardMove"
226-
this.sendEventToJS(KeyboardTransitionEvent(view.id, event, height, progress, duration, viewTagFocused))
233+
this.sendEventToJS(KeyboardTransitionEvent(surfaceId, view.id, event, height, progress, duration, viewTagFocused))
227234

228235
return insets
229236
}
@@ -254,6 +261,7 @@ class KeyboardAnimationCallback(
254261
)
255262
this.sendEventToJS(
256263
KeyboardTransitionEvent(
264+
surfaceId,
257265
view.id,
258266
"topKeyboardMoveEnd",
259267
keyboardHeight,
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
package com.reactnativekeyboardcontroller.events
22

33
import com.facebook.react.bridge.Arguments
4+
import com.facebook.react.bridge.WritableMap
45
import com.facebook.react.uimanager.events.Event
5-
import com.facebook.react.uimanager.events.RCTEventEmitter
66

7+
@Suppress("detekt:LongParameterList")
78
class KeyboardTransitionEvent(
9+
surfaceId: Int,
810
viewId: Int,
911
private val event: String,
1012
private val height: Double,
1113
private val progress: Double,
1214
private val duration: Int,
1315
private val target: Int,
14-
) : Event<KeyboardTransitionEvent>(viewId) {
16+
) : Event<KeyboardTransitionEvent>(surfaceId, viewId) {
1517
override fun getEventName() = event
1618

1719
// All events for a given view can be coalesced?
1820
override fun getCoalescingKey(): Short = 0
1921

20-
override fun dispatch(rctEventEmitter: RCTEventEmitter) {
21-
val map = Arguments.createMap()
22-
map.putDouble("progress", progress)
23-
map.putDouble("height", height)
24-
map.putInt("duration", duration)
25-
map.putInt("target", target)
26-
rctEventEmitter.receiveEvent(viewTag, eventName, map)
22+
override fun getEventData(): WritableMap? = Arguments.createMap().apply {
23+
putDouble("progress", progress)
24+
putDouble("height", height)
25+
putInt("duration", duration)
26+
putInt("target", target)
2727
}
2828
}

Diff for: docs/docs/guides/compatibility.md

+16-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,18 @@ keywords: [react-native-keyboard-controller, compatibility, react-native version
66

77
# Compatibility
88

9+
:::info
10+
11+
If you found an incompatibility or conflict with other open source libraries - don't hesitate to open an [issue](https://github.com/kirillzyusko/react-native-keyboard-controller/issues/new?assignees=kirillzyusko&labels=bug&template=bug_report.md&title=). It will help the project 🙏
12+
13+
:::
14+
915
## React Native
1016

17+
Below you can find an information about compatibility with `react-native` package per different architectures.
18+
19+
### Fabric (new) architecture
20+
1121
Starting from `1.2.0` this library adds support for a new architecture called `Fabric`. Since a new architecture is still in adoption stage and it changes some APIs over time - it's highly recommended to use versions which are compatible and were intensively tested against specific `react-native` versions.
1222

1323
Below you can find a table with supported versions:
@@ -17,11 +27,14 @@ Below you can find a table with supported versions:
1727
|1.3.0+ | 0.70.0+ |
1828
|1.2.0+ | 0.69.0+ |
1929

20-
:::info
30+
### Paper (old) architecture
2131

22-
For `Paper` (old) architecture there is no any restrictions. If you found an incompatibility - don't hesitate to open an [issue](https://github.com/kirillzyusko/react-native-keyboard-controller/issues/new?assignees=kirillzyusko&labels=bug&template=bug_report.md&title=). It will help the project 🙏
32+
This library supports as minimal `react-native` version as possible. However it was decided to drop a support for some really old versions for better development workflow and future support.
2333

24-
:::
34+
|library version|react-native version|
35+
|-------|--------------------|
36+
|1.7.0+ | 0.65.0+ |
37+
|1.0.0+ | 0.62.0+ |
2538

2639
## Third-party libraries compatibility
2740

0 commit comments

Comments
 (0)