mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Kotlin: fix static code analysis weak warnings (6/n) (#52338)
Summary: Static code analysis reports several weak warnings, many of which seem to be leftovers after Kotlin migration. This PR addresses quite a few: - [Accessor call that can be replaced with property access syntax](https://www.jetbrains.com/help/inspectopedia/UsePropertyAccessSyntax.html) ## Changelog: [INTERNAL] - Kotlin: fix static code analysis weak warnings (6/n) Pull Request resolved: https://github.com/facebook/react-native/pull/52338 Test Plan: ```sh yarn android yarn test-android ``` Reviewed By: NickGerleman Differential Revision: D77504913 Pulled By: cortinico fbshipit-source-id: 62661ba6adafb7893ce27811357020966d5ea4c1
This commit is contained in:
committed by
Facebook GitHub Bot
parent
69e4252ccb
commit
7d01060a8b
+3
-3
@@ -54,7 +54,7 @@ internal class AccessibilityInfoModule(context: ReactApplicationContext) :
|
||||
}
|
||||
|
||||
override fun onChange(selfChange: Boolean, uri: Uri?) {
|
||||
if (getReactApplicationContext().hasActiveReactInstance()) {
|
||||
if (reactApplicationContext.hasActiveReactInstance()) {
|
||||
updateAndSendReduceMotionChangeEvent()
|
||||
}
|
||||
}
|
||||
@@ -67,7 +67,7 @@ internal class AccessibilityInfoModule(context: ReactApplicationContext) :
|
||||
}
|
||||
|
||||
override fun onChange(selfChange: Boolean, uri: Uri?) {
|
||||
if (getReactApplicationContext().hasActiveReactInstance()) {
|
||||
if (reactApplicationContext.hasActiveReactInstance()) {
|
||||
updateAndSendHighTextContrastChangeEvent()
|
||||
}
|
||||
}
|
||||
@@ -90,7 +90,7 @@ internal class AccessibilityInfoModule(context: ReactApplicationContext) :
|
||||
val appContext = context.applicationContext
|
||||
accessibilityManager =
|
||||
appContext.getSystemService(Context.ACCESSIBILITY_SERVICE) as AccessibilityManager
|
||||
contentResolver = getReactApplicationContext().getContentResolver()
|
||||
contentResolver = reactApplicationContext.contentResolver
|
||||
touchExplorationEnabled = accessibilityManager.isTouchExplorationEnabled
|
||||
accessibilityServiceEnabled = accessibilityManager.isEnabled
|
||||
reduceMotionEnabled = isReduceMotionEnabledValue
|
||||
|
||||
+2
-2
@@ -61,7 +61,7 @@ internal class AppStateModule(reactContext: ReactApplicationContext) :
|
||||
Arguments.createMap().apply { putString("app_state", appState) }
|
||||
|
||||
private fun sendEvent(eventName: String, data: Any?) {
|
||||
val reactApplicationContext = getReactApplicationContext() ?: return
|
||||
val reactApplicationContext = reactApplicationContext ?: return
|
||||
// We don't gain anything interesting from logging here, and it's an extremely common
|
||||
// race condition for an AppState event to be triggered as the Catalyst instance is being
|
||||
// set up or torn down. So, just fail silently here.
|
||||
@@ -85,7 +85,7 @@ internal class AppStateModule(reactContext: ReactApplicationContext) :
|
||||
|
||||
override fun invalidate() {
|
||||
super.invalidate()
|
||||
getReactApplicationContext().removeLifecycleEventListener(this)
|
||||
reactApplicationContext.removeLifecycleEventListener(this)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ internal class ImageStoreManager(reactContext: ReactApplicationContext) :
|
||||
val executor = Executors.newSingleThreadExecutor()
|
||||
executor.execute {
|
||||
try {
|
||||
val contentResolver = getReactApplicationContext().getContentResolver()
|
||||
val contentResolver = reactApplicationContext.contentResolver
|
||||
val parsedUri = Uri.parse(uri)
|
||||
val inputStream = contentResolver.openInputStream(parsedUri) as InputStream
|
||||
try {
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ public open class DeviceEventManagerModule(
|
||||
// There should be no need to check if the catalyst instance is alive. After initialization
|
||||
// the thread instances cannot be null, and scheduling on a thread after ReactApplicationContext
|
||||
// teardown is a noop.
|
||||
getReactApplicationContext().runOnUiQueueThread(invokeDefaultBackPressRunnable)
|
||||
reactApplicationContext.runOnUiQueueThread(invokeDefaultBackPressRunnable)
|
||||
}
|
||||
|
||||
public companion object {
|
||||
|
||||
+2
-2
@@ -23,7 +23,7 @@ internal open class HeadlessJsTaskSupportModule(reactContext: ReactApplicationCo
|
||||
NativeHeadlessJsTaskSupportSpec(reactContext) {
|
||||
override fun notifyTaskRetry(taskIdDouble: Double, promise: Promise) {
|
||||
val taskId = taskIdDouble.toInt()
|
||||
val headlessJsTaskContext = HeadlessJsTaskContext.getInstance(getReactApplicationContext())
|
||||
val headlessJsTaskContext = HeadlessJsTaskContext.getInstance(reactApplicationContext)
|
||||
if (headlessJsTaskContext.isTaskRunning(taskId)) {
|
||||
val retryPosted = headlessJsTaskContext.retryTask(taskId)
|
||||
promise.resolve(retryPosted)
|
||||
@@ -38,7 +38,7 @@ internal open class HeadlessJsTaskSupportModule(reactContext: ReactApplicationCo
|
||||
|
||||
override fun notifyTaskFinished(taskIdDouble: Double) {
|
||||
val taskId = taskIdDouble.toInt()
|
||||
val headlessJsTaskContext = HeadlessJsTaskContext.getInstance(getReactApplicationContext())
|
||||
val headlessJsTaskContext = HeadlessJsTaskContext.getInstance(reactApplicationContext)
|
||||
if (headlessJsTaskContext.isTaskRunning(taskId)) {
|
||||
headlessJsTaskContext.finishTask(taskId)
|
||||
} else {
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ public class SourceCodeModule(reactContext: ReactApplicationContext) :
|
||||
mapOf(
|
||||
"scriptURL" to
|
||||
Assertions.assertNotNull<String>(
|
||||
getReactApplicationContext().getSourceURL(),
|
||||
reactApplicationContext.getSourceURL(),
|
||||
"No source URL loaded, have you initialised the instance?"))
|
||||
|
||||
public companion object {
|
||||
|
||||
+4
-4
@@ -16,7 +16,7 @@ import com.facebook.react.module.annotations.ReactModule
|
||||
internal class I18nManagerModule(context: ReactApplicationContext?) :
|
||||
NativeI18nManagerSpec(context) {
|
||||
override fun getTypedExportedConstants(): Map<String, Any> {
|
||||
val context = getReactApplicationContext()
|
||||
val context = reactApplicationContext
|
||||
val locale = context.resources.configuration.locales[0]
|
||||
|
||||
return mapOf(
|
||||
@@ -26,15 +26,15 @@ internal class I18nManagerModule(context: ReactApplicationContext?) :
|
||||
}
|
||||
|
||||
override fun allowRTL(value: Boolean) {
|
||||
I18nUtil.instance.allowRTL(getReactApplicationContext(), value)
|
||||
I18nUtil.instance.allowRTL(reactApplicationContext, value)
|
||||
}
|
||||
|
||||
override fun forceRTL(value: Boolean) {
|
||||
I18nUtil.instance.forceRTL(getReactApplicationContext(), value)
|
||||
I18nUtil.instance.forceRTL(reactApplicationContext, value)
|
||||
}
|
||||
|
||||
override fun swapLeftAndRightInRTL(value: Boolean) {
|
||||
I18nUtil.instance.swapLeftAndRightInRTL(getReactApplicationContext(), value)
|
||||
I18nUtil.instance.swapLeftAndRightInRTL(reactApplicationContext, value)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
+2
-2
@@ -81,7 +81,7 @@ internal class ImageLoaderModule : NativeImageLoaderAndroidSpec, LifecycleEventL
|
||||
promise.reject(ERROR_INVALID_URI, "Cannot get the size of an image for an empty URI")
|
||||
return
|
||||
}
|
||||
val source = ImageSource(getReactApplicationContext(), uriString)
|
||||
val source = ImageSource(reactApplicationContext, uriString)
|
||||
val request: ImageRequest = ImageRequestBuilder.newBuilderWithSource(source.uri).build()
|
||||
val dataSource: DataSource<CloseableReference<CloseableImage>> =
|
||||
this.imagePipeline.fetchDecodedImage(request, this.callerContext)
|
||||
@@ -226,7 +226,7 @@ internal class ImageLoaderModule : NativeImageLoaderAndroidSpec, LifecycleEventL
|
||||
override fun queryCache(uris: ReadableArray, promise: Promise) {
|
||||
// perform cache interrogation in async task as disk cache checks are expensive
|
||||
@Suppress("DEPRECATION", "StaticFieldLeak")
|
||||
object : GuardedAsyncTask<Void, Void>(getReactApplicationContext()) {
|
||||
object : GuardedAsyncTask<Void, Void>(reactApplicationContext) {
|
||||
override fun doInBackgroundGuarded(vararg params: Void) {
|
||||
val result = buildReadableMap {
|
||||
val imagePipeline: ImagePipeline = this@ImageLoaderModule.imagePipeline
|
||||
|
||||
+4
-4
@@ -34,7 +34,7 @@ public open class IntentModule(reactContext: ReactApplicationContext) :
|
||||
synchronized(this) {
|
||||
pendingOpenURLPromises.clear()
|
||||
initialURLListener
|
||||
?.let { listener -> getReactApplicationContext().removeLifecycleEventListener(listener) }
|
||||
?.let { listener -> reactApplicationContext.removeLifecycleEventListener(listener) }
|
||||
.also { initialURLListener = null }
|
||||
}
|
||||
super.invalidate()
|
||||
@@ -47,7 +47,7 @@ public open class IntentModule(reactContext: ReactApplicationContext) :
|
||||
*/
|
||||
override fun getInitialURL(promise: Promise) {
|
||||
try {
|
||||
val currentActivity = getReactApplicationContext().getCurrentActivity()
|
||||
val currentActivity = reactApplicationContext.getCurrentActivity()
|
||||
if (currentActivity == null) {
|
||||
waitForActivityAndGetInitialURL(promise)
|
||||
return
|
||||
@@ -82,7 +82,7 @@ public open class IntentModule(reactContext: ReactApplicationContext) :
|
||||
initialURLListener =
|
||||
object : LifecycleEventListener {
|
||||
override fun onHostResume() {
|
||||
getReactApplicationContext().removeLifecycleEventListener(this)
|
||||
reactApplicationContext.removeLifecycleEventListener(this)
|
||||
synchronized(this@IntentModule) {
|
||||
for (pendingPromise in pendingOpenURLPromises) {
|
||||
getInitialURL(pendingPromise)
|
||||
@@ -96,7 +96,7 @@ public open class IntentModule(reactContext: ReactApplicationContext) :
|
||||
|
||||
override fun onHostDestroy() = Unit
|
||||
}
|
||||
getReactApplicationContext().addLifecycleEventListener(initialURLListener)
|
||||
reactApplicationContext.addLifecycleEventListener(initialURLListener)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ public class PermissionsModule(reactContext: ReactApplicationContext?) :
|
||||
* permission had been granted, false otherwise. See [Activity.checkSelfPermission].
|
||||
*/
|
||||
public override fun checkPermission(permission: String, promise: Promise): Unit {
|
||||
val context = getReactApplicationContext().getBaseContext()
|
||||
val context = reactApplicationContext.baseContext
|
||||
promise.resolve(context.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED)
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ internal class SoundManagerModule(reactContext: ReactApplicationContext?) :
|
||||
NativeSoundManagerSpec(reactContext) {
|
||||
override fun playTouchSound() {
|
||||
val audioManager =
|
||||
getReactApplicationContext().getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||
reactApplicationContext.getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||
audioManager.playSoundEffect(AudioManager.FX_KEY_CLICK)
|
||||
}
|
||||
|
||||
|
||||
+3
-5
@@ -31,16 +31,14 @@ internal class ToastModule(reactContext: ReactApplicationContext) :
|
||||
|
||||
override fun show(message: String?, durationDouble: Double) {
|
||||
val duration = durationDouble.toInt()
|
||||
UiThreadUtil.runOnUiThread {
|
||||
Toast.makeText(getReactApplicationContext(), message, duration).show()
|
||||
}
|
||||
UiThreadUtil.runOnUiThread { Toast.makeText(reactApplicationContext, message, duration).show() }
|
||||
}
|
||||
|
||||
override fun showWithGravity(message: String?, durationDouble: Double, gravityDouble: Double) {
|
||||
val duration = durationDouble.toInt()
|
||||
val gravity = gravityDouble.toInt()
|
||||
UiThreadUtil.runOnUiThread {
|
||||
val toast = Toast.makeText(getReactApplicationContext(), message, duration)
|
||||
val toast = Toast.makeText(reactApplicationContext, message, duration)
|
||||
toast.setGravity(gravity, 0, 0)
|
||||
toast.show()
|
||||
}
|
||||
@@ -58,7 +56,7 @@ internal class ToastModule(reactContext: ReactApplicationContext) :
|
||||
val xOffset = xOffsetDouble.toInt()
|
||||
val yOffset = yOffsetDouble.toInt()
|
||||
UiThreadUtil.runOnUiThread {
|
||||
val toast = Toast.makeText(getReactApplicationContext(), message, duration)
|
||||
val toast = Toast.makeText(reactApplicationContext, message, duration)
|
||||
toast.setGravity(gravity, xOffset, yOffset)
|
||||
toast.show()
|
||||
}
|
||||
|
||||
+2
-2
@@ -54,12 +54,12 @@ internal class VibrationModule(reactContext: ReactApplicationContext) :
|
||||
private fun getVibrator(): Vibrator? =
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
val vibratorManager =
|
||||
getReactApplicationContext().getSystemService(Context.VIBRATOR_MANAGER_SERVICE)
|
||||
reactApplicationContext.getSystemService(Context.VIBRATOR_MANAGER_SERVICE)
|
||||
as VibratorManager?
|
||||
vibratorManager?.defaultVibrator
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
getReactApplicationContext().getSystemService(Context.VIBRATOR_SERVICE) as Vibrator?
|
||||
reactApplicationContext.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator?
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
Reference in New Issue
Block a user