diff --git a/android/src/main/java/com/reactnativekeyboardcontroller/extensions/ThemedReactContext.kt b/android/src/main/java/com/reactnativekeyboardcontroller/extensions/ThemedReactContext.kt index 8c0b188827..3f4eb4bc80 100644 --- a/android/src/main/java/com/reactnativekeyboardcontroller/extensions/ThemedReactContext.kt +++ b/android/src/main/java/com/reactnativekeyboardcontroller/extensions/ThemedReactContext.kt @@ -1,6 +1,10 @@ package com.reactnativekeyboardcontroller.extensions +import android.util.Log import android.view.View + +import com.facebook.react.bridge.WritableMap +import com.facebook.react.modules.core.DeviceEventManagerModule import com.facebook.react.uimanager.ThemedReactContext import com.facebook.react.uimanager.UIManagerHelper import com.facebook.react.uimanager.events.Event @@ -14,3 +18,9 @@ fun ThemedReactContext?.dispatchEvent(viewId: Int, event: Event<*>) { UIManagerHelper.getEventDispatcherForReactTag(this, viewId) eventDispatcher?.dispatchEvent(event) } + +fun ThemedReactContext?.emitEvent(event: String, params: WritableMap) { + this?.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)?.emit(event, params) + + Log.i("ThemedReactContext", event) +} diff --git a/android/src/main/java/com/reactnativekeyboardcontroller/listeners/KeyboardAnimationCallback.kt b/android/src/main/java/com/reactnativekeyboardcontroller/listeners/KeyboardAnimationCallback.kt index a6aaa67313..ee592291a3 100644 --- a/android/src/main/java/com/reactnativekeyboardcontroller/listeners/KeyboardAnimationCallback.kt +++ b/android/src/main/java/com/reactnativekeyboardcontroller/listeners/KeyboardAnimationCallback.kt @@ -23,6 +23,7 @@ import com.reactnativekeyboardcontroller.events.KeyboardTransitionEvent import com.reactnativekeyboardcontroller.events.KeyboardTransitionEventData import com.reactnativekeyboardcontroller.extensions.dispatchEvent import com.reactnativekeyboardcontroller.extensions.dp +import com.reactnativekeyboardcontroller.extensions.emitEvent import kotlin.math.abs private val TAG = KeyboardAnimationCallback::class.qualifiedName @@ -75,8 +76,8 @@ class KeyboardAnimationCallback( viewTagFocused, ), ) - this.emitEvent("KeyboardController::keyboardWillShow", getEventParams(this.persistentKeyboardHeight)) - this.emitEvent("KeyboardController::keyboardDidShow", getEventParams(this.persistentKeyboardHeight)) + context.emitEvent("KeyboardController::keyboardWillShow", getEventParams(this.persistentKeyboardHeight)) + context.emitEvent("KeyboardController::keyboardDidShow", getEventParams(this.persistentKeyboardHeight)) } } } @@ -149,7 +150,7 @@ class KeyboardAnimationCallback( } layoutObserver?.syncUpLayout() - this.emitEvent( + context.emitEvent( "KeyboardController::" + if (!isKeyboardVisible) "keyboardWillHide" else "keyboardWillShow", getEventParams(keyboardHeight), ) @@ -233,7 +234,7 @@ class KeyboardAnimationCallback( } isKeyboardVisible = isKeyboardVisible || isKeyboardShown - this.emitEvent( + context.emitEvent( "KeyboardController::" + if (!isKeyboardVisible) "keyboardDidHide" else "keyboardDidShow", getEventParams(keyboardHeight), ) @@ -274,7 +275,7 @@ class KeyboardAnimationCallback( this.animation?.cancel() } - this.emitEvent("KeyboardController::keyboardWillShow", getEventParams(keyboardHeight)) + context.emitEvent("KeyboardController::keyboardWillShow", getEventParams(keyboardHeight)) this.dispatchEventToJS( KeyboardTransitionEventData( "topKeyboardMoveStart", @@ -300,7 +301,7 @@ class KeyboardAnimationCallback( ) } animation.doOnEnd { - this.emitEvent("KeyboardController::keyboardDidShow", getEventParams(keyboardHeight)) + context.emitEvent("KeyboardController::keyboardDidShow", getEventParams(keyboardHeight)) this.dispatchEventToJS( KeyboardTransitionEventData( "topKeyboardMoveEnd", @@ -334,12 +335,6 @@ class KeyboardAnimationCallback( return (keyboardHeight - navigationBar).toFloat().dp.coerceAtLeast(0.0) } - private fun emitEvent(event: String, params: WritableMap) { - context?.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)?.emit(event, params) - - Log.i(TAG, event) - } - private fun getEventParams(height: Double): WritableMap { val params: WritableMap = Arguments.createMap() params.putDouble("height", height)