Skip to content

Commit aaad7e0

Browse files
mateoguzmanafacebook-github-bot
authored andcommitted
Kotlin: fix static code analysis weak warnings (1/n) (#52153)
Summary: Static code analysis reports several weak warnings, many of which seem to be leftovers after Kotlin migration. This PR addresses quite a few: - [Convert to primary constructor](https://www.jetbrains.com/help/inspectopedia/ConvertSecondaryConstructorToPrimary.html) - [If-Then foldable to '?.'](https://www.jetbrains.com/help/inspectopedia/IfThenToSafeAccess.html) - [Non-canonical modifier order](https://www.jetbrains.com/help/inspectopedia/SortModifiers.html) ## Changelog: [INTERNAL] - Kotlin: fix static code analysis weak warnings (1/n) Pull Request resolved: #52153 Test Plan: ```sh yarn android yarn test-android ``` Reviewed By: christophpurrer Differential Revision: D77042260 Pulled By: arushikesarwani94 fbshipit-source-id: ea210976ccbcecbe4843ff5205238a83fc75d43b
1 parent 999f437 commit aaad7e0

7 files changed

Lines changed: 29 additions & 43 deletions

File tree

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/MemoryPressureRouter.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ public class MemoryPressureRouter(context: Context) : ComponentCallbacks2 {
3737
listeners.remove(listener)
3838
}
3939

40-
override public fun onTrimMemory(level: Int) {
40+
public override fun onTrimMemory(level: Int) {
4141
dispatchMemoryPressure(level)
4242
}
4343

44-
override public fun onConfigurationChanged(newConfig: Configuration): Unit = Unit
44+
public override fun onConfigurationChanged(newConfig: Configuration): Unit = Unit
4545

4646
@Deprecated(
4747
"onLowMemory is deprecated, use onTrimMemory instead.", ReplaceWith("onTrimMemory(level)"))
48-
override public fun onLowMemory(): Unit = Unit
48+
public override fun onLowMemory(): Unit = Unit
4949

5050
private fun dispatchMemoryPressure(level: Int) {
5151
for (listener in listeners) {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/BaseActivityEventListener.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ public open class BaseActivityEventListener : ActivityEventListener {
1818
ReplaceWith("onActivityResult(activity, requestCode, resultCode, data)"))
1919
public open fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent): Unit = Unit
2020

21-
override public fun onActivityResult(
21+
public override fun onActivityResult(
2222
activity: Activity,
2323
requestCode: Int,
2424
resultCode: Int,
2525
data: Intent?
2626
): Unit = Unit
2727

28-
override public fun onNewIntent(intent: Intent): Unit = Unit
28+
public override fun onNewIntent(intent: Intent): Unit = Unit
2929
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/GuardedAsyncTask.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ protected constructor(private val exceptionHandler: JSExceptionHandler) :
2525
protected constructor(reactContext: ReactContext) : this(reactContext.exceptionHandler)
2626

2727
@Deprecated("AsyncTask is deprecated.")
28-
override protected final fun doInBackground(vararg params: Params): Void? {
28+
protected final override fun doInBackground(vararg params: Params): Void? {
2929
try {
3030
doInBackgroundGuarded(*params)
3131
} catch (e: RuntimeException) {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,9 +465,7 @@ public abstract class DevSupportManagerBase(
465465
devOptionsDialog?.show()
466466

467467
val reactContext = currentReactContext
468-
if (reactContext != null) {
469-
reactContext.getJSModule(RCTNativeAppEventEmitter::class.java).emit("RCTDevMenuShown", null)
470-
}
468+
reactContext?.getJSModule(RCTNativeAppEventEmitter::class.java)?.emit("RCTDevMenuShown", null)
471469
}
472470

473471
override fun onNewReactContextCreated(reactContext: ReactContext) {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/accessibilityinfo/AccessibilityInfoModule.kt

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -181,35 +181,29 @@ internal class AccessibilityInfoModule(context: ReactApplicationContext) :
181181
val isReduceMotionEnabled = isReduceMotionEnabledValue
182182
if (reduceMotionEnabled != isReduceMotionEnabled) {
183183
reduceMotionEnabled = isReduceMotionEnabled
184-
val reactApplicationContext = getReactApplicationContextIfActiveOrWarn()
185-
if (reactApplicationContext != null) {
186-
reactApplicationContext.emitDeviceEvent(REDUCE_MOTION_EVENT_NAME, reduceMotionEnabled)
187-
}
184+
getReactApplicationContextIfActiveOrWarn()
185+
?.emitDeviceEvent(REDUCE_MOTION_EVENT_NAME, reduceMotionEnabled)
188186
}
189187
}
190188

191189
private fun updateAndSendInvertColorsChangeEvent() {
192190
val isInvertColorsEnabled = isInvertColorsEnabledValue
193191
if (invertColorsEnabled != isInvertColorsEnabled) {
194192
invertColorsEnabled = isInvertColorsEnabled
195-
val reactApplicationContext = getReactApplicationContextIfActiveOrWarn()
196-
if (reactApplicationContext != null) {
197-
reactApplicationContext.emitDeviceEvent(INVERT_COLOR_EVENT_NAME, invertColorsEnabled)
198-
}
193+
getReactApplicationContextIfActiveOrWarn()
194+
?.emitDeviceEvent(INVERT_COLOR_EVENT_NAME, invertColorsEnabled)
199195
}
200196
}
201197

202198
private fun updateAndSendHighTextContrastChangeEvent() {
203199
val isHighTextContrastEnabled = isHighTextContrastEnabledValue
204200
if (highTextContrastEnabled != isHighTextContrastEnabled) {
205201
highTextContrastEnabled = isHighTextContrastEnabled
206-
val reactApplicationContext = getReactApplicationContextIfActiveOrWarn()
207-
if (reactApplicationContext != null) {
208-
reactApplicationContext.emitDeviceEvent(
209-
HIGH_TEXT_CONTRAST_EVENT_NAME,
210-
highTextContrastEnabled,
211-
)
212-
}
202+
getReactApplicationContextIfActiveOrWarn()
203+
?.emitDeviceEvent(
204+
HIGH_TEXT_CONTRAST_EVENT_NAME,
205+
highTextContrastEnabled,
206+
)
213207
}
214208
}
215209

@@ -239,10 +233,8 @@ internal class AccessibilityInfoModule(context: ReactApplicationContext) :
239233
val isGrayscaleModeEnabled = isGrayscaleEnabledValue
240234
if (grayscaleModeEnabled != isGrayscaleModeEnabled) {
241235
grayscaleModeEnabled = isGrayscaleModeEnabled
242-
val reactApplicationContext = getReactApplicationContextIfActiveOrWarn()
243-
if (reactApplicationContext != null) {
244-
reactApplicationContext.emitDeviceEvent(GRAYSCALE_MODE_EVENT_NAME, grayscaleModeEnabled)
245-
}
236+
getReactApplicationContextIfActiveOrWarn()
237+
?.emitDeviceEvent(GRAYSCALE_MODE_EVENT_NAME, grayscaleModeEnabled)
246238
}
247239
}
248240

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/layoutanimation/SimpleSpringInterpolator.kt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,9 @@ import com.facebook.react.common.annotations.internal.LegacyArchitectureLogger
1717
/** Simple spring interpolator */
1818
// TODO(7613736): Improve spring interpolator with friction and damping variable support
1919
@LegacyArchitecture(logLevel = LegacyArchitectureLogLevel.ERROR)
20-
internal class SimpleSpringInterpolator : Interpolator {
21-
private val _springDamping: Float
22-
23-
@JvmOverloads
24-
constructor(springDamping: Float = FACTOR) {
25-
_springDamping = springDamping
26-
}
20+
internal class SimpleSpringInterpolator @JvmOverloads constructor(springDamping: Float = FACTOR) :
21+
Interpolator {
22+
private val _springDamping: Float = springDamping
2723

2824
override fun getInterpolation(input: Float): Float =
2925
// Using mSpringDamping in this equation is not really the exact mathematical springDamping,

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextViewAccessibilityDelegate.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ import com.facebook.react.R
2121
import com.facebook.react.uimanager.ReactAccessibilityDelegate
2222
import com.facebook.react.views.text.internal.span.ReactClickableSpan
2323

24-
internal class ReactTextViewAccessibilityDelegate : ReactAccessibilityDelegate {
25-
constructor(
26-
view: View,
27-
originalFocus: Boolean,
28-
originalImportantForAccessibility: Int
29-
) : super(view, originalFocus, originalImportantForAccessibility) {
24+
internal class ReactTextViewAccessibilityDelegate(
25+
view: View,
26+
originalFocus: Boolean,
27+
originalImportantForAccessibility: Int
28+
) : ReactAccessibilityDelegate(view, originalFocus, originalImportantForAccessibility) {
29+
private var accessibilityLinks: AccessibilityLinks? = null
30+
31+
init {
3032
accessibilityLinks = hostView.getTag(R.id.accessibility_links) as AccessibilityLinks?
3133
}
3234

33-
private var accessibilityLinks: AccessibilityLinks? = null
34-
3535
companion object {
3636
fun setDelegate(view: View, originalFocus: Boolean, originalImportantForAccessibility: Int) {
3737
// if a view already has an accessibility delegate, replacing it could cause

0 commit comments

Comments
 (0)