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 (5/n) (#52337)
Summary: Static code analysis reports several weak warnings, many of which seem to be leftovers after Kotlin migration. This PR addresses quite a few: - [Unnecessary type argument](https://www.jetbrains.com/help/inspectopedia/RemoveExplicitTypeArguments.html) - [Variable declaration could be moved inside 'when'](https://www.jetbrains.com/help/inspectopedia/MoveVariableDeclarationIntoWhen.html) - [Assignment can be replaced with operator assignment](https://www.jetbrains.com/help/inspectopedia/AssignmentReplaceableWithOperatorAssignment.html) - [Negated call can be simplified](https://www.jetbrains.com/help/inspectopedia/SimplifyNegatedBinaryExpression.html) ## Changelog: [INTERNAL] - Kotlin: fix static code analysis weak warnings (5/n) Pull Request resolved: https://github.com/facebook/react-native/pull/52337 Test Plan: ```sh yarn android yarn test-android ``` Reviewed By: cortinico Differential Revision: D77525702 Pulled By: rshest fbshipit-source-id: b0bd2e7616340c22b22e7f58387c53c51cbf073e
This commit is contained in:
committed by
Facebook GitHub Bot
parent
9a2c422b80
commit
73e513280d
+2
-4
@@ -105,9 +105,8 @@ public class NativeAnimatedNodesManager(
|
||||
throw JSApplicationIllegalArgumentException(
|
||||
"createAnimatedNode: Animated node [$tag] already exists")
|
||||
}
|
||||
val type = config.getString("type")
|
||||
val node =
|
||||
when (type) {
|
||||
when (val type = config.getString("type")) {
|
||||
"style" -> StyleAnimatedNode(config, this)
|
||||
"value" -> ValueAnimatedNode(config)
|
||||
"color" -> ColorAnimatedNode(config, this, checkNotNull(reactApplicationContext))
|
||||
@@ -239,9 +238,8 @@ public class NativeAnimatedNodesManager(
|
||||
return
|
||||
}
|
||||
|
||||
val type = animationConfig.getString("type")
|
||||
val animation =
|
||||
when (type) {
|
||||
when (val type = animationConfig.getString("type")) {
|
||||
"frames" -> FrameBasedAnimationDriver(animationConfig)
|
||||
"spring" -> SpringAnimation(animationConfig)
|
||||
"decay" -> DecayAnimation(animationConfig)
|
||||
|
||||
+2
-6
@@ -36,9 +36,7 @@ public object JSONArguments {
|
||||
val result = buildReadableMap {
|
||||
while (keys.hasNext()) {
|
||||
val key = keys.next()
|
||||
val value = obj.get(key)
|
||||
|
||||
when (value) {
|
||||
when (val value = obj.get(key)) {
|
||||
is JSONObject -> put(key, fromJSONObject(value))
|
||||
is JSONArray -> put(key, fromJSONArray(value))
|
||||
is String -> put(key, value)
|
||||
@@ -82,9 +80,7 @@ public object JSONArguments {
|
||||
public fun fromJSONArray(arr: JSONArray): ReadableArray {
|
||||
val result = buildReadableArray {
|
||||
repeat(arr.length()) {
|
||||
val value = arr.get(it)
|
||||
|
||||
when (value) {
|
||||
when (val value = arr.get(it)) {
|
||||
is JSONObject -> add(fromJSONObject(value))
|
||||
is JSONArray -> add(fromJSONArray(value))
|
||||
is String -> add(value)
|
||||
|
||||
+1
-1
@@ -62,7 +62,7 @@ internal object ReactSoftExceptionLogger {
|
||||
|
||||
@JvmStatic
|
||||
fun logSoftException(@CategoryMode category: String, cause: Throwable): Unit {
|
||||
if (!listeners.isEmpty()) {
|
||||
if (listeners.isNotEmpty()) {
|
||||
for (listener in listeners) {
|
||||
listener.logSoftException(category, cause)
|
||||
}
|
||||
|
||||
+2
-2
@@ -140,9 +140,9 @@ private constructor(
|
||||
var curLen = 0
|
||||
while (curLen < sizeMapBufferList) {
|
||||
val sizeMapBuffer = buffer.getInt(offset + curLen)
|
||||
curLen = curLen + Int.SIZE_BYTES
|
||||
curLen += Int.SIZE_BYTES
|
||||
readMapBufferList.add(cloneWithOffset(offset + curLen))
|
||||
curLen = curLen + sizeMapBuffer
|
||||
curLen += sizeMapBuffer
|
||||
}
|
||||
return readMapBufferList
|
||||
}
|
||||
|
||||
+1
-1
@@ -260,7 +260,7 @@ public class Task<TResult> : TaskInterface<TResult> {
|
||||
|
||||
@JvmStatic
|
||||
internal fun <TResult> create(): TaskCompletionSource<TResult> {
|
||||
return TaskCompletionSource<TResult>()
|
||||
return TaskCompletionSource()
|
||||
}
|
||||
|
||||
/** Creates a completed task with the given value. */
|
||||
|
||||
+4
-4
@@ -261,7 +261,7 @@ public object ReactScrollViewHelper {
|
||||
// Register the listeners for the fling animator if there isn't any
|
||||
val flingAnimator = scrollView.getFlingAnimator()
|
||||
if (flingAnimator.listeners == null || flingAnimator.listeners.size == 0) {
|
||||
registerFlingAnimator<T>(scrollView)
|
||||
registerFlingAnimator(scrollView)
|
||||
}
|
||||
val scrollState = scrollView.reactScrollViewScrollState
|
||||
scrollState.setFinalAnimatedPositionScroll(x, y)
|
||||
@@ -400,7 +400,7 @@ public object ReactScrollViewHelper {
|
||||
|
||||
override fun onAnimationEnd(animator: Animator) {
|
||||
scrollView.reactScrollViewScrollState.isFinished = true
|
||||
updateFabricScrollState<T>(scrollView)
|
||||
updateFabricScrollState(scrollView)
|
||||
}
|
||||
|
||||
override fun onAnimationCancel(animator: Animator) {
|
||||
@@ -456,9 +456,9 @@ public object ReactScrollViewHelper {
|
||||
val height = scrollView.height - scrollView.paddingBottom - scrollView.paddingTop
|
||||
val finalAnimatedPositionScroll = scrollState.finalAnimatedPositionScroll
|
||||
scroller.fling(
|
||||
getNextFlingStartValue<T>(
|
||||
getNextFlingStartValue(
|
||||
scrollView, scrollView.scrollX, finalAnimatedPositionScroll.x, velocityX), // startX
|
||||
getNextFlingStartValue<T>(
|
||||
getNextFlingStartValue(
|
||||
scrollView, scrollView.scrollY, finalAnimatedPositionScroll.y, velocityY), // startY
|
||||
velocityX, // velocityX
|
||||
velocityY, // velocityY
|
||||
|
||||
Reference in New Issue
Block a user