Skip to content

Commit bf1a5d4

Browse files
alanleedevfacebook-github-bot
authored andcommitted
convert ViewUtil to Kotlin (facebook#43799)
Summary: Pull Request resolved: facebook#43799 convert Java to Kotlin: `/react/uimanager/common/ViewUtil.java` Changelog: [Internal] internal Reviewed By: cortinico Differential Revision: D55651762 fbshipit-source-id: 26896a41df8efec9fa032f0e16e3e50342dd54f8
1 parent fd3ef7b commit bf1a5d4

File tree

2 files changed

+30
-32
lines changed

2 files changed

+30
-32
lines changed

packages/react-native/ReactAndroid/api/ReactAndroid.api

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5393,12 +5393,12 @@ public abstract interface annotation class com/facebook/react/uimanager/common/U
53935393
public static final field FABRIC I
53945394
}
53955395

5396-
public class com/facebook/react/uimanager/common/ViewUtil {
5396+
public final class com/facebook/react/uimanager/common/ViewUtil {
5397+
public static final field INSTANCE Lcom/facebook/react/uimanager/common/ViewUtil;
53975398
public static final field NO_SURFACE_ID I
5398-
public fun <init> ()V
5399-
public static fun getUIManagerType (I)I
5400-
public static fun getUIManagerType (II)I
5401-
public static fun isRootTag (I)Z
5399+
public static final fun getUIManagerType (I)I
5400+
public static final fun getUIManagerType (II)I
5401+
public static final fun isRootTag (I)Z
54025402
}
54035403

54045404
public abstract interface class com/facebook/react/uimanager/debug/NotThreadSafeViewHierarchyUpdateDebugListener {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/common/ViewUtil.java renamed to packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/common/ViewUtil.kt

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,38 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
package com.facebook.react.uimanager.common;
8+
package com.facebook.react.uimanager.common
99

10-
import static com.facebook.react.uimanager.common.UIManagerType.DEFAULT;
11-
import static com.facebook.react.uimanager.common.UIManagerType.FABRIC;
10+
import com.facebook.react.uimanager.common.UIManagerType.DEFAULT
11+
import com.facebook.react.uimanager.common.UIManagerType.FABRIC
1212

13-
import com.facebook.infer.annotation.Nullsafe;
14-
15-
@Nullsafe(Nullsafe.Mode.LOCAL)
16-
public class ViewUtil {
17-
18-
public static final int NO_SURFACE_ID = -1;
13+
public object ViewUtil {
1914

15+
public const val NO_SURFACE_ID: Int = -1
2016
/**
2117
* Counter for uniquely identifying views. - % 2 === 0 means it is a Fabric tag. See
2218
* https://github.com/facebook/react/pull/12587
2319
*
24-
* @param viewTag {@link int} tag of the view this is event is dispatched to
20+
* @param viewTag [int] tag of the view this is event is dispatched to
2521
*/
22+
@JvmStatic
2623
@UIManagerType
27-
public static int getUIManagerType(int viewTag) {
28-
if (viewTag % 2 == 0) return FABRIC;
29-
return DEFAULT;
30-
}
24+
public fun getUIManagerType(viewTag: Int): Int =
25+
if (viewTag % 2 == 0) {
26+
FABRIC
27+
} else {
28+
DEFAULT
29+
}
3130

3231
/**
3332
* Version of getUIManagerType that uses both surfaceId and viewTag heuristics
3433
*
35-
* @param viewTag {@link int} tag of the view this is event is dispatched to
36-
* @param surfaceId {@link int} ID of the corresponding surface
34+
* @param viewTag [int] tag of the view this is event is dispatched to
35+
* @param surfaceId [int] ID of the corresponding surface
3736
*/
37+
@JvmStatic
3838
@UIManagerType
39-
public static int getUIManagerType(int viewTag, int surfaceId) {
39+
public fun getUIManagerType(viewTag: Int, surfaceId: Int): Int {
4040
// We have a contract that Fabric events *always* have a SurfaceId passed in, and non-Fabric
4141
// events NEVER have a SurfaceId passed in (the default/placeholder of -1 is passed in instead).
4242
//
@@ -47,21 +47,19 @@ public static int getUIManagerType(int viewTag, int surfaceId) {
4747
// non-Fabric UIManager, and we cannot use the ViewTag for inference since it's not controlled
4848
// by RN and is essentially a random number.
4949
// At some point it would be great to pass the SurfaceContext here instead.
50-
@UIManagerType int uiManagerType = (surfaceId == -1 ? DEFAULT : FABRIC);
51-
if (uiManagerType == DEFAULT && !ViewUtil.isRootTag(viewTag)) {
50+
@UIManagerType val uiManagerType = if (surfaceId == -1) DEFAULT else FABRIC
51+
if (uiManagerType == DEFAULT && !isRootTag(viewTag)) {
5252
// TODO (T123064648): Some events for Fabric still didn't have the surfaceId set, so if it's
5353
// not a React RootView, double check if the tag belongs to Fabric.
54-
if (viewTag % 2 == 0) return FABRIC;
54+
if (viewTag % 2 == 0) {
55+
return FABRIC
56+
}
5557
}
56-
return uiManagerType;
58+
return uiManagerType
5759
}
58-
5960
/**
60-
* @param viewTag {@link int} react tag
61+
* @param viewTag [int] react tag
6162
* @return if the react tag received by parameter is a RootTag or not.
6263
*/
63-
@Deprecated
64-
public static boolean isRootTag(int viewTag) {
65-
return viewTag % 10 == 1;
66-
}
64+
@JvmStatic public fun isRootTag(viewTag: Int): Boolean = viewTag % 10 == 1
6765
}

0 commit comments

Comments
 (0)