From c942469700d979ee75770393135ea4947c3b46bc Mon Sep 17 00:00:00 2001 From: Thomas Nardone Date: Wed, 11 Sep 2024 19:06:25 -0700 Subject: [PATCH] Re-enable ktfmt on RN (#46441) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/46441 Changelog: [Internal] Reviewed By: zertosh Differential Revision: D62518893 fbshipit-source-id: ca2ff83018716a4dc1e2dcfb8596138d088ce9f4 --- .../com/facebook/react/ReactExtensionTest.kt | 6 ++--- .../popupmenu/ReactPopupMenuContainer.kt | 1 - .../android/build.gradle.kts | 4 +-- .../ReactAndroid/build.gradle.kts | 16 +++++------ .../facebook/react/devsupport/LogBoxDialog.kt | 3 ++- .../modules/appearance/AppearanceModule.kt | 1 - .../react/modules/core/ReactChoreographer.kt | 15 +++++------ .../modules/i18nmanager/I18nManagerModule.kt | 3 +-- .../react/views/common/ContextUtils.kt | 3 ++- .../react/views/modal/ModalHostShadowNode.kt | 2 +- .../react/views/modal/ReactModalHostView.kt | 27 ++++++++++--------- .../facebook/react/uiapp/RNTesterActivity.kt | 5 ++-- 12 files changed, 42 insertions(+), 44 deletions(-) diff --git a/packages/gradle-plugin/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/ReactExtensionTest.kt b/packages/gradle-plugin/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/ReactExtensionTest.kt index 6340f7fd81a73b..c2db6e1bf8725f 100644 --- a/packages/gradle-plugin/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/ReactExtensionTest.kt +++ b/packages/gradle-plugin/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/ReactExtensionTest.kt @@ -192,8 +192,8 @@ class ReactExtensionTest { @Test fun getGradleDependenciesToApply_withIsPureCxxDeps_filtersCorrectly() { val validJsonFile = - createJsonFile( - """ + createJsonFile( + """ { "reactNativeVersion": "1000.0.0", "dependencies": { @@ -221,7 +221,7 @@ class ReactExtensionTest { } } """ - .trimIndent()) + .trimIndent()) val deps = getGradleDependenciesToApply(validJsonFile) assertThat(deps).containsExactly("implementation" to ":react-native_android-example") diff --git a/packages/react-native-popup-menu-android/android/src/main/java/com/facebook/react/popupmenu/ReactPopupMenuContainer.kt b/packages/react-native-popup-menu-android/android/src/main/java/com/facebook/react/popupmenu/ReactPopupMenuContainer.kt index 5a85e6f2d6e9a0..c0963d057a9472 100644 --- a/packages/react-native-popup-menu-android/android/src/main/java/com/facebook/react/popupmenu/ReactPopupMenuContainer.kt +++ b/packages/react-native-popup-menu-android/android/src/main/java/com/facebook/react/popupmenu/ReactPopupMenuContainer.kt @@ -8,7 +8,6 @@ package com.facebook.react.popupmenu import android.content.Context -import android.os.Build import android.view.Menu import android.widget.FrameLayout import android.widget.PopupMenu diff --git a/packages/react-native-test-library/android/build.gradle.kts b/packages/react-native-test-library/android/build.gradle.kts index ac68aea30d0407..903c15d07affbe 100644 --- a/packages/react-native-test-library/android/build.gradle.kts +++ b/packages/react-native-test-library/android/build.gradle.kts @@ -16,9 +16,7 @@ android { buildToolsVersion = libs.versions.buildTools.get() namespace = "com.facebook.react.osslibraryexample" - defaultConfig { - minSdk = libs.versions.minSdk.get().toInt() - } + defaultConfig { minSdk = libs.versions.minSdk.get().toInt() } compileOptions { sourceCompatibility = JavaVersion.VERSION_17 diff --git a/packages/react-native/ReactAndroid/build.gradle.kts b/packages/react-native/ReactAndroid/build.gradle.kts index e4dfb42a571ab8..52ae6d3a9f7955 100644 --- a/packages/react-native/ReactAndroid/build.gradle.kts +++ b/packages/react-native/ReactAndroid/build.gradle.kts @@ -226,14 +226,14 @@ val preparePrefab by Pair("../ReactCommon/yoga/", ""), Pair("src/main/jni/first-party/yogajni/jni", ""), )), - PrefabPreprocessingEntry("hermestooling", - // hermes_executor - Pair("../ReactCommon/hermes/inspector-modern/", "hermes/inspector-modern/") - ), - PrefabPreprocessingEntry("jsctooling", - // jsc - Pair("../ReactCommon/jsc/", "jsc/") - ), + PrefabPreprocessingEntry( + "hermestooling", + // hermes_executor + Pair("../ReactCommon/hermes/inspector-modern/", "hermes/inspector-modern/")), + PrefabPreprocessingEntry( + "jsctooling", + // jsc + Pair("../ReactCommon/jsc/", "jsc/")), )) outputDir.set(prefabHeadersDir) } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/LogBoxDialog.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/LogBoxDialog.kt index a0b5b086be3cb5..9e268d2fc8c0fd 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/LogBoxDialog.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/LogBoxDialog.kt @@ -33,7 +33,8 @@ internal class LogBoxDialog(context: Activity, private val reactRootView: View?) super.onCreate(savedInstanceState) // set background color so it will show below transparent system bars on forced edge-to-edge this.window?.setBackgroundDrawable(ColorDrawable(Color.BLACK)) - // register insets listener to update margins on the ReactRootView to avoid overlap w/ system bars + // register insets listener to update margins on the ReactRootView to avoid overlap w/ system + // bars reactRootView?.let { rootView -> val insetsType: Int = WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout() diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/appearance/AppearanceModule.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/appearance/AppearanceModule.kt index e58f108f1eb1c0..558d3f2b77bccb 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/appearance/AppearanceModule.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/appearance/AppearanceModule.kt @@ -63,7 +63,6 @@ constructor( "light" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) "unspecified" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) - } } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/core/ReactChoreographer.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/core/ReactChoreographer.kt index 4d28e67465f7ea..7e1922e7d59592 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/core/ReactChoreographer.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/core/ReactChoreographer.kt @@ -7,8 +7,8 @@ package com.facebook.react.modules.core -import androidx.annotation.GuardedBy import android.view.Choreographer +import androidx.annotation.GuardedBy import com.facebook.common.logging.FLog import com.facebook.infer.annotation.Assertions import com.facebook.react.bridge.UiThreadUtil @@ -42,8 +42,7 @@ public class ReactChoreographer private constructor(choreographerProvider: Chore private val callbackQueues: Array> = Array(CallbackType.entries.size) { ArrayDeque() } private var totalCallbacks = 0 - @GuardedBy("callbackQueues") - private var hasPostedCallback = false + @GuardedBy("callbackQueues") private var hasPostedCallback = false private val frameCallback = Choreographer.FrameCallback { frameTimeNanos -> @@ -93,17 +92,17 @@ public class ReactChoreographer private constructor(choreographerProvider: Chore } /** - * This method writes [hasPostedCallback] and it should be called from another method that has - * the lock on [callbackQueues]. + * This method writes [hasPostedCallback] and it should be called from another method that has the + * lock on [callbackQueues]. */ private fun postFrameCallbackOnChoreographer() { if (!hasPostedCallback) { val choreographer = choreographer if (choreographer == null) { // Schedule on the main thread, at which point the constructor's async work will have - UiThreadUtil.runOnUiThread { - synchronized(callbackQueues) { postFrameCallbackOnChoreographer() } - } + UiThreadUtil.runOnUiThread { + synchronized(callbackQueues) { postFrameCallbackOnChoreographer() } + } } else { choreographer.postFrameCallback(frameCallback) hasPostedCallback = true diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nManagerModule.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nManagerModule.kt index 4f41466e407c1f..6b3b22565b5e6d 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nManagerModule.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nManagerModule.kt @@ -7,7 +7,6 @@ package com.facebook.react.modules.i18nmanager -import android.os.Build import com.facebook.fbreact.specs.NativeI18nManagerSpec import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.module.annotations.ReactModule @@ -18,7 +17,7 @@ public class I18nManagerModule(context: ReactApplicationContext?) : NativeI18nMa override public fun getTypedExportedConstants(): Map { val context = getReactApplicationContext() val locale = context.resources.configuration.locales[0] - + return mapOf( "isRTL" to I18nUtil.instance.isRTL(context), "doLeftAndRightSwapInRTL" to I18nUtil.instance.doLeftAndRightSwapInRTL(context), diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/common/ContextUtils.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/common/ContextUtils.kt index 9ca1d9fcc72e6a..64ca9577f8f5a9 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/common/ContextUtils.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/common/ContextUtils.kt @@ -38,6 +38,7 @@ public object ContextUtils { return null } } - @Suppress("UNCHECKED_CAST") return currentContext as T? + @Suppress("UNCHECKED_CAST") + return currentContext as T? } } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/modal/ModalHostShadowNode.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/modal/ModalHostShadowNode.kt index 2466caa3b9bfdd..adc9c52320b9a1 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/modal/ModalHostShadowNode.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/modal/ModalHostShadowNode.kt @@ -18,7 +18,7 @@ import com.facebook.react.uimanager.ReactShadowNodeImpl * to be the window size. This will then cause the children of the Modal to layout as if they can * fill the window. */ -@Deprecated("This class is no longer used and will be removed soon.") +@Deprecated("This class is no longer used and will be removed soon.") internal class ModalHostShadowNode : LayoutShadowNode() { /** * We need to set the styleWidth and styleHeight of the one child (represented by the diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.kt index 586d934c781e3b..0384a28d4cafa7 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.kt @@ -44,8 +44,8 @@ import com.facebook.react.uimanager.ThemedReactContext import com.facebook.react.uimanager.UIManagerModule import com.facebook.react.uimanager.events.EventDispatcher import com.facebook.react.views.common.ContextUtils -import com.facebook.react.views.view.setStatusBarTranslucency import com.facebook.react.views.view.ReactViewGroup +import com.facebook.react.views.view.setStatusBarTranslucency import java.util.Objects /** @@ -413,18 +413,19 @@ public class ReactModalHostView(context: ThemedReactContext) : newStateData.putDouble("screenWidth", realWidth.toDouble()) newStateData.putDouble("screenHeight", realHeight.toDouble()) sw.updateState(newStateData) - } ?: run { - // old architecture - // TODO: T44725185 remove after full migration to Fabric - reactContext.runOnNativeModulesQueueThread( - object : GuardedRunnable(reactContext) { - override fun runGuarded() { - reactContext.reactApplicationContext - .getNativeModule(UIManagerModule::class.java) - ?.updateNodeSize(id, viewWidth, viewHeight) - } - }) - } + } + ?: run { + // old architecture + // TODO: T44725185 remove after full migration to Fabric + reactContext.runOnNativeModulesQueueThread( + object : GuardedRunnable(reactContext) { + override fun runGuarded() { + reactContext.reactApplicationContext + .getNativeModule(UIManagerModule::class.java) + ?.updateNodeSize(id, viewWidth, viewHeight) + } + }) + } } override fun handleException(t: Throwable) { diff --git a/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterActivity.kt b/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterActivity.kt index 741d3fee461410..ceb499fd44e94d 100644 --- a/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterActivity.kt +++ b/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterActivity.kt @@ -7,9 +7,9 @@ package com.facebook.react.uiapp -import android.os.Bundle import android.graphics.Color import android.graphics.drawable.ColorDrawable +import android.os.Bundle import android.view.View import android.widget.FrameLayout import androidx.core.view.ViewCompat @@ -47,7 +47,8 @@ class RNTesterActivity : ReactActivity() { super.onCreate(savedInstanceState) // set background color so it will show below transparent system bars on forced edge-to-edge this.window?.setBackgroundDrawable(ColorDrawable(Color.BLACK)) - // register insets listener to update margins on the ReactRootView to avoid overlap w/ system bars + // register insets listener to update margins on the ReactRootView to avoid overlap w/ system + // bars getReactDelegate()?.getReactRootView()?.let { rootView -> val insetsType: Int = WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout()