From f02607badb5641ab235f41be8005ce62d2bd63d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateo=20Guzm=C3=A1n?= Date: Thu, 3 Apr 2025 04:56:05 -0700 Subject: [PATCH] Make `DeviceInfoModule` internal (#50458) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: This class can be internalized as part of the initiative to reduce the public API surface. I've checked there are [no relevant OSS usages](https://github.com/search?type=code&q=NOT+is%3Afork+NOT+org%3Afacebook+NOT+repo%3Areact-native-tvos%2Freact-native-tvos+NOT+repo%3Anuagoz%2Freact-native+NOT+repo%3A2lambda123%2Freact-native+NOT+repo%3Abeanchips%2Ffacebookreactnative+NOT+repo%3AfabOnReact%2Freact-native-notes+NOT+user%3Ahuntie+NOT+user%3Acortinico+NOT+repo%3AMaxdev18%2Fpowersync_app+NOT+repo%3Acarter-0%2Finstagram-decompiled+NOT+repo%3Am0mosenpai%2Finstadamn+NOT+repo%3AA-Star100%2FA-Star100-AUG2-2024+NOT+repo%3Alclnrd%2Fdetox-scrollview-reproductible+NOT+repo%3ADionisisChytiris%2FWorldWiseTrivia_Main+NOT+repo%3Apast3l%2Fhi2+NOT+repo%3AoneDotpy%2FCaribouQuest+NOT+repo%3Abejayoharen%2Fdailytodo+NOT+repo%3Amolangning%2Freversing-discord+NOT+repo%3AScottPrzy%2Freact-native+NOT+repo%3Agabrieldonadel%2Freact-native-visionos+NOT+repo%3AGabriel2308%2FTestes-Soft+NOT+repo%3Adawnzs03%2FflakyBuild+NOT+repo%3Acga2351%2Fcode+NOT+repo%3Astreeg%2Ftcc+NOT+repo%3Asoftware-mansion-labs%2Freact-native-swiftui+NOT+repo%3Apkcsecurity%2Fdecompiled-lightbulb+com.facebook.react.modules.deviceinfo.DeviceInfoModule). All GH search results are forks – there is only one relevant case for the repository [renavigation2/renavigation2](https://github.com/renavigation2/renavigation2/blob/82582c11a9eb2e4e7c56d84d53fbc4e575cb0174/packages/navigation/android/src/main/java/com/navigation/reactnative/SceneView.java#L17), but the repo has no been updated for 4 years, marked as work in progress and its packages have 0 downloads, so this won't break OSS but I'm marking it as breaking just in case (let me know if you think we should open an issue on their side). ## Changelog: [ANDROID][BREAKING] - Make com.facebook.react.modules.deviceinfo.DeviceInfoModule internal Pull Request resolved: https://github.com/facebook/react-native/pull/50458 Test Plan: ```bash yarn test-android yarn android ``` Reviewed By: cortinico Differential Revision: D72377448 Pulled By: javache fbshipit-source-id: 974146474f649ce2bc80d74c3eb8d6d8f987c372 --- .../ReactAndroid/api/ReactAndroid.api | 11 ----------- .../modules/deviceinfo/DeviceInfoModule.kt | 19 +++++-------------- 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index bf994ef3eee..b3945ca0e88 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -2963,17 +2963,6 @@ public abstract interface class com/facebook/react/modules/debug/interfaces/Deve public abstract fun setStartSamplingProfilerOnInit (Z)V } -public final class com/facebook/react/modules/deviceinfo/DeviceInfoModule : com/facebook/fbreact/specs/NativeDeviceInfoSpec, com/facebook/react/bridge/LifecycleEventListener { - public fun (Landroid/content/Context;)V - public fun (Lcom/facebook/react/bridge/ReactApplicationContext;)V - public final fun emitUpdateDimensionsEvent ()V - public fun getTypedExportedConstants ()Ljava/util/Map; - public fun invalidate ()V - public fun onHostDestroy ()V - public fun onHostPause ()V - public fun onHostResume ()V -} - public class com/facebook/react/modules/dialog/AlertFragment : androidx/fragment/app/DialogFragment, android/content/DialogInterface$OnClickListener { public fun ()V public fun (Lcom/facebook/react/modules/dialog/DialogModule$AlertFragmentListener;Landroid/os/Bundle;)V diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/deviceinfo/DeviceInfoModule.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/deviceinfo/DeviceInfoModule.kt index c8906be5248..bc262392623 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/deviceinfo/DeviceInfoModule.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/deviceinfo/DeviceInfoModule.kt @@ -7,7 +7,6 @@ package com.facebook.react.modules.deviceinfo -import android.content.Context import com.facebook.fbreact.specs.NativeDeviceInfoSpec import com.facebook.react.bridge.LifecycleEventListener import com.facebook.react.bridge.ReactApplicationContext @@ -20,22 +19,14 @@ import com.facebook.react.uimanager.DisplayMetricsHolder.initDisplayMetricsIfNot /** Module that exposes Android Constants to JS. */ @ReactModule(name = NativeDeviceInfoSpec.NAME) -public class DeviceInfoModule : NativeDeviceInfoSpec, LifecycleEventListener { - private var reactApplicationContext: ReactApplicationContext? = null - private var fontScale: Float +internal class DeviceInfoModule(reactContext: ReactApplicationContext) : + NativeDeviceInfoSpec(reactContext), LifecycleEventListener { + private var fontScale: Float = reactContext.resources.configuration.fontScale private var previousDisplayMetrics: ReadableMap? = null - public constructor(reactContext: ReactApplicationContext) : super(reactContext) { + init { initDisplayMetricsIfNotInitialized(reactContext) - fontScale = reactContext.resources.configuration.fontScale reactContext.addLifecycleEventListener(this) - reactApplicationContext = reactContext - } - - public constructor(context: Context) : super(null) { - reactApplicationContext = null - initDisplayMetricsIfNotInitialized(context) - fontScale = context.resources.configuration.fontScale } public override fun getTypedExportedConstants(): Map { @@ -58,7 +49,7 @@ public class DeviceInfoModule : NativeDeviceInfoSpec, LifecycleEventListener { override fun onHostDestroy(): Unit = Unit - public fun emitUpdateDimensionsEvent() { + fun emitUpdateDimensionsEvent() { reactApplicationContext?.let { context -> if (context.hasActiveReactInstance()) { // Don't emit an event to JS if the dimensions haven't changed