Skip to content

Commit 926d5b1

Browse files
rshestfacebook-github-bot
authored andcommitted
DeviceEventManagerModule.java->.kt (#45813)
Summary: Pull Request resolved: #45813 # Changelog: [Internal] - As in the title. Differential Revision: D60446332
1 parent cb105c5 commit 926d5b1

File tree

3 files changed

+72
-79
lines changed

3 files changed

+72
-79
lines changed

packages/react-native/ReactAndroid/api/ReactAndroid.api

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3140,13 +3140,18 @@ public abstract interface class com/facebook/react/modules/core/DefaultHardwareB
31403140
public abstract fun invokeDefaultOnBackPressed ()V
31413141
}
31423142

3143-
public class com/facebook/react/modules/core/DeviceEventManagerModule : com/facebook/fbreact/specs/NativeDeviceEventManagerSpec {
3143+
public final class com/facebook/react/modules/core/DeviceEventManagerModule : com/facebook/fbreact/specs/NativeDeviceEventManagerSpec {
3144+
public static final field Companion Lcom/facebook/react/modules/core/DeviceEventManagerModule$Companion;
3145+
public static final field NAME Ljava/lang/String;
31443146
public fun <init> (Lcom/facebook/react/bridge/ReactApplicationContext;Lcom/facebook/react/modules/core/DefaultHardwareBackBtnHandler;)V
3145-
public fun emitHardwareBackPressed ()V
3146-
public fun emitNewIntentReceived (Landroid/net/Uri;)V
3147+
public final fun emitHardwareBackPressed ()V
3148+
public final fun emitNewIntentReceived (Landroid/net/Uri;)V
31473149
public fun invokeDefaultBackPressHandler ()V
31483150
}
31493151

3152+
public final class com/facebook/react/modules/core/DeviceEventManagerModule$Companion {
3153+
}
3154+
31503155
public abstract interface class com/facebook/react/modules/core/DeviceEventManagerModule$RCTDeviceEventEmitter : com/facebook/react/bridge/JavaScriptModule {
31513156
public abstract fun emit (Ljava/lang/String;Ljava/lang/Object;)V
31523157
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/core/DeviceEventManagerModule.java

Lines changed: 0 additions & 76 deletions
This file was deleted.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
package com.facebook.react.modules.core
9+
10+
import android.net.Uri
11+
import com.facebook.proguard.annotations.DoNotStrip
12+
import com.facebook.react.bridge.Arguments
13+
import com.facebook.react.bridge.JavaScriptModule
14+
import com.facebook.react.bridge.ReactApplicationContext
15+
import com.facebook.react.bridge.UiThreadUtil
16+
import com.facebook.react.module.annotations.ReactModule
17+
18+
/** Native module that handles device hardware events like hardware back presses. */
19+
@ReactModule(name = com.facebook.fbreact.specs.NativeDeviceEventManagerSpec.NAME)
20+
public class DeviceEventManagerModule(
21+
reactContext: ReactApplicationContext?,
22+
backBtnHandler: DefaultHardwareBackBtnHandler
23+
) : com.facebook.fbreact.specs.NativeDeviceEventManagerSpec(reactContext) {
24+
@DoNotStrip
25+
public fun interface RCTDeviceEventEmitter : JavaScriptModule {
26+
public fun emit(eventName: String, data: Any?)
27+
}
28+
29+
private val invokeDefaultBackPressRunnable: Runnable = Runnable {
30+
UiThreadUtil.assertOnUiThread()
31+
backBtnHandler.invokeDefaultOnBackPressed()
32+
}
33+
34+
/** Sends an event to the JS instance that the hardware back has been pressed. */
35+
public fun emitHardwareBackPressed() {
36+
val reactApplicationContext: ReactApplicationContext? =
37+
getReactApplicationContextIfActiveOrWarn()
38+
reactApplicationContext?.emitDeviceEvent("hardwareBackPress", null)
39+
}
40+
41+
/** Sends an event to the JS instance that a new intent was received. */
42+
public fun emitNewIntentReceived(uri: Uri) {
43+
val reactApplicationContext: ReactApplicationContext? =
44+
getReactApplicationContextIfActiveOrWarn()
45+
val map = Arguments.createMap()
46+
map.putString("url", uri.toString())
47+
reactApplicationContext?.emitDeviceEvent("url", map)
48+
}
49+
50+
/**
51+
* Invokes the default back handler for the host of this catalyst instance. This should be invoked
52+
* if JS does not want to handle the back press itself.
53+
*/
54+
override fun invokeDefaultBackPressHandler() {
55+
// There should be no need to check if the catalyst instance is alive. After initialization
56+
// the thread instances cannot be null, and scheduling on a thread after ReactApplicationContext
57+
// teardown is a noop.
58+
getReactApplicationContext().runOnUiQueueThread(invokeDefaultBackPressRunnable)
59+
}
60+
61+
public companion object {
62+
public const val NAME: String = com.facebook.fbreact.specs.NativeDeviceEventManagerSpec.NAME
63+
}
64+
}

0 commit comments

Comments
 (0)