mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Fix multiple warnings post Kotlin migration (#38156)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/38156 As we migrated several files from Java to Kotlin, our build log got really noisy with several compilation warnings. That's happing as the Kotlin compiler is stricter than the Java one. Here I've fixed most of them. Changelog: [Internal] [Changed] - Fix multiple warnings post Kotlin migration Reviewed By: rshest Differential Revision: D47185820 fbshipit-source-id: f49c90b4a6db9892979ea95b404cf427805c6503
This commit is contained in:
1 parent
f90829fb01
commit
bf7b81f3a2
12 files changed
+36
-22
No files matched your search
+1
-2
@@ -15,7 +15,6 @@ import android.content.res.Configuration;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.KeyEvent;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.react.bridge.Callback;
|
||||
@@ -58,7 +57,7 @@ public class ReactActivityDelegate {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected @NonNull Bundle composeLaunchOptions() {
|
||||
protected @Nullable Bundle composeLaunchOptions() {
|
||||
Bundle composedLaunchOptions = getLaunchOptions();
|
||||
if (isFabricEnabled()) {
|
||||
if (composedLaunchOptions == null) {
|
||||
|
||||
+4
-5
@@ -7,7 +7,6 @@
|
||||
|
||||
package com.facebook.react
|
||||
|
||||
import android.app.Activity
|
||||
import android.os.Bundle
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
@@ -17,7 +16,7 @@ import org.robolectric.RobolectricTestRunner
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class ReactActivityDelegateTest {
|
||||
|
||||
val nullDelegate: Activity? = null
|
||||
val nullDelegate: ReactActivity? = null
|
||||
|
||||
@Test
|
||||
fun delegateWithFabricEnabled_populatesInitialPropsCorrectly() {
|
||||
@@ -25,7 +24,7 @@ class ReactActivityDelegateTest {
|
||||
object : ReactActivityDelegate(nullDelegate, "test-delegate") {
|
||||
override fun isFabricEnabled() = true
|
||||
|
||||
public val inspectLaunchOptions: Bundle?
|
||||
val inspectLaunchOptions: Bundle?
|
||||
get() = composeLaunchOptions()
|
||||
}
|
||||
|
||||
@@ -40,7 +39,7 @@ class ReactActivityDelegateTest {
|
||||
object : ReactActivityDelegate(nullDelegate, "test-delegate") {
|
||||
override fun isFabricEnabled() = false
|
||||
|
||||
public val inspectLaunchOptions: Bundle?
|
||||
val inspectLaunchOptions: Bundle?
|
||||
get() = composeLaunchOptions()
|
||||
}
|
||||
|
||||
@@ -56,7 +55,7 @@ class ReactActivityDelegateTest {
|
||||
override fun getLaunchOptions(): Bundle =
|
||||
Bundle().apply { putString("test-property", "test-value") }
|
||||
|
||||
public val inspectLaunchOptions: Bundle?
|
||||
val inspectLaunchOptions: Bundle?
|
||||
get() = composeLaunchOptions()
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
@file:Suppress("DEPRECATION") // Suppressing as we want to test RCTEventEmitter here
|
||||
package com.facebook.react
|
||||
|
||||
import android.app.Activity
|
||||
|
||||
+4
-2
@@ -5,6 +5,7 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
@file:Suppress("DEPRECATION") // Suppressing as we want to test RCTEventEmitter here
|
||||
package com.facebook.react.animated
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
@@ -872,6 +873,7 @@ class NativeAnimatedNodeTraversalTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated("Deprecated in Java")
|
||||
override fun dispatch(rctEventEmitter: RCTEventEmitter) {
|
||||
rctEventEmitter.receiveEvent(
|
||||
tag, "topScroll", JavaOnlyMap.of("contentOffset", JavaOnlyMap.of("y", value)))
|
||||
@@ -881,7 +883,7 @@ class NativeAnimatedNodeTraversalTest {
|
||||
|
||||
@Test
|
||||
fun testNativeAnimatedEventDoUpdate() {
|
||||
val viewTag: Int = 1000
|
||||
val viewTag = 1000
|
||||
|
||||
createSimpleAnimatedViewWithOpacity(viewTag)
|
||||
|
||||
@@ -903,7 +905,7 @@ class NativeAnimatedNodeTraversalTest {
|
||||
|
||||
@Test
|
||||
fun testNativeAnimatedEventDoNotUpdate() {
|
||||
val viewTag: Int = 1000
|
||||
val viewTag = 1000
|
||||
|
||||
createSimpleAnimatedViewWithOpacity()
|
||||
|
||||
|
||||
+1
@@ -77,6 +77,7 @@ class BaseJavaModuleTest {
|
||||
generatedModuleWrapper.invoke(methodId, arguments)
|
||||
}
|
||||
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
private class MethodsModule : BaseJavaModule() {
|
||||
override fun getName(): String = "Methods"
|
||||
|
||||
|
||||
+2
@@ -134,6 +134,7 @@ class FallbackJSBundleLoaderTest {
|
||||
|
||||
private fun recoverableMsg(errMsg: String): String = FallbackJSBundleLoader.RECOVERABLE + errMsg
|
||||
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
private fun recoverableLoader(url: String, errMsg: String): JSBundleLoader {
|
||||
val loader = mock(JSBundleLoader::class.java)
|
||||
whenever(loader.loadScript(null))
|
||||
@@ -144,6 +145,7 @@ class FallbackJSBundleLoaderTest {
|
||||
|
||||
private fun fatalMsg(errMsg: String): String = UNRECOVERABLE + errMsg
|
||||
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
private fun fatalLoader(url: String, errMsg: String): JSBundleLoader {
|
||||
val loader = mock(JSBundleLoader::class.java)
|
||||
whenever(loader.loadScript(null)).thenThrow(RuntimeException(UNRECOVERABLE + errMsg))
|
||||
|
||||
+1
@@ -5,6 +5,7 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
@file:Suppress("DEPRECATION") // Suppressing as we want to fake a RCTEventEmitter here
|
||||
package com.facebook.react.bridge.interop
|
||||
|
||||
import com.facebook.react.bridge.WritableArray
|
||||
|
||||
+2
@@ -5,6 +5,8 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
@file:Suppress(
|
||||
"DEPRECATION") // Suppressing as we want to test specifically with RCTEventEmitter here
|
||||
package com.facebook.react.bridge.interop
|
||||
|
||||
import com.facebook.react.config.ReactFeatureFlags
|
||||
|
||||
+14
-9
@@ -9,6 +9,8 @@ package com.facebook.react.fabric.events
|
||||
|
||||
import android.util.DisplayMetrics
|
||||
import android.view.MotionEvent
|
||||
import android.view.MotionEvent.PointerCoords
|
||||
import android.view.MotionEvent.PointerProperties
|
||||
import com.facebook.react.bridge.*
|
||||
import com.facebook.react.fabric.FabricUIManager
|
||||
import com.facebook.react.uimanager.DisplayMetricsHolder
|
||||
@@ -511,22 +513,23 @@ class TouchEventDispatchTest {
|
||||
action: Int,
|
||||
pointerId: Int,
|
||||
pointerIds: IntArray,
|
||||
pointerCoords: Array<MotionEvent.PointerCoords>
|
||||
pointerCoords: Array<PointerCoords>
|
||||
): TouchEvent {
|
||||
touchEventCoalescingKeyHelper.addCoalescingKey(gestureTime.toLong())
|
||||
val action = action or (pointerId shl MotionEvent.ACTION_POINTER_INDEX_SHIFT)
|
||||
val shiftedAction = action or (pointerId shl MotionEvent.ACTION_POINTER_INDEX_SHIFT)
|
||||
return TouchEvent.obtain(
|
||||
SURFACE_ID,
|
||||
TARGET_VIEW_ID,
|
||||
getType(action),
|
||||
getType(shiftedAction),
|
||||
MotionEvent.obtain(
|
||||
gestureTime.toLong(),
|
||||
gestureTime.toLong(),
|
||||
action,
|
||||
shiftedAction,
|
||||
pointerIds.size,
|
||||
pointerIds,
|
||||
pointerIds.toPointerProperties(),
|
||||
pointerCoords,
|
||||
0,
|
||||
0,
|
||||
0f,
|
||||
0f,
|
||||
0,
|
||||
@@ -545,8 +548,7 @@ class TouchEventDispatchTest {
|
||||
private const val GESTURE_START_TIME = 1
|
||||
|
||||
private fun getType(action: Int): TouchEventType {
|
||||
val action = action and MotionEvent.ACTION_POINTER_INDEX_MASK.inv()
|
||||
when (action) {
|
||||
when (action and MotionEvent.ACTION_POINTER_INDEX_MASK.inv()) {
|
||||
MotionEvent.ACTION_DOWN,
|
||||
MotionEvent.ACTION_POINTER_DOWN -> return TouchEventType.START
|
||||
MotionEvent.ACTION_UP,
|
||||
@@ -591,10 +593,13 @@ class TouchEventDispatchTest {
|
||||
putDouble("timestamp", time.toDouble())
|
||||
}
|
||||
|
||||
private fun pointerCoords(x: Float, y: Float): MotionEvent.PointerCoords =
|
||||
MotionEvent.PointerCoords().apply {
|
||||
private fun pointerCoords(x: Float, y: Float): PointerCoords =
|
||||
PointerCoords().apply {
|
||||
this.x = x
|
||||
this.y = y
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun IntArray.toPointerProperties(): Array<PointerProperties> =
|
||||
this.map { PointerProperties().apply { id = it } }.toTypedArray()
|
||||
+1
@@ -5,6 +5,7 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
@file:Suppress("DEPRECATION") // Suppressing as RCTEventEmitter is part of the API
|
||||
package com.facebook.react.fabric.interop
|
||||
|
||||
import com.facebook.react.uimanager.events.BatchEventDispatchedListener
|
||||
|
||||
+4
-4
@@ -58,13 +58,13 @@ class ShareModuleTest {
|
||||
val chooserIntent = shadowOf(RuntimeEnvironment.application).nextStartedActivity
|
||||
assertNotNull("Dialog was not displayed", chooserIntent)
|
||||
assertEquals(Intent.ACTION_CHOOSER, chooserIntent.action)
|
||||
assertEquals(dialogTitle, chooserIntent.extras?.get(Intent.EXTRA_TITLE))
|
||||
assertEquals(dialogTitle, chooserIntent.extras?.getString(Intent.EXTRA_TITLE))
|
||||
|
||||
val contentIntent = chooserIntent.extras?.get(Intent.EXTRA_INTENT) as Intent?
|
||||
val contentIntent = chooserIntent.extras?.getParcelable(Intent.EXTRA_INTENT, Intent::class.java)
|
||||
assertNotNull("Intent was not built correctly", contentIntent)
|
||||
assertEquals(Intent.ACTION_SEND, contentIntent?.action)
|
||||
assertEquals(title, contentIntent?.extras?.get(Intent.EXTRA_SUBJECT))
|
||||
assertEquals(message, contentIntent?.extras?.get(Intent.EXTRA_TEXT))
|
||||
assertEquals(title, contentIntent?.extras?.getString(Intent.EXTRA_SUBJECT))
|
||||
assertEquals(message, contentIntent?.extras?.getString(Intent.EXTRA_TEXT))
|
||||
|
||||
assertEquals(1, promise.resolved)
|
||||
}
|
||||
|
||||
+1
@@ -13,6 +13,7 @@ import kotlin.jvm.JvmStatic
|
||||
import org.robolectric.annotation.Implementation
|
||||
import org.robolectric.annotation.Implements
|
||||
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
@Implements(SoLoader::class)
|
||||
class ShadowSoLoader {
|
||||
companion object {
|
||||
|
||||
Reference in new issue
Block a user