forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convert ViewUtil to Kotlin (facebook#43799)
Summary: Pull Request resolved: facebook#43799 convert Java to Kotlin: `/react/uimanager/common/ViewUtil.java` Changelog: [Internal] internal Differential Revision: D55651762
- Loading branch information
1 parent
4fd95b6
commit 5b4ff49
Showing
3 changed files
with
69 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 0 additions & 67 deletions
67
...react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/common/ViewUtil.java
This file was deleted.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
...s/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/common/ViewUtil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
@file:JvmName("ViewUtil") | ||
|
||
package com.facebook.react.uimanager.common | ||
|
||
import com.facebook.react.uimanager.common.UIManagerType.DEFAULT | ||
import com.facebook.react.uimanager.common.UIManagerType.FABRIC | ||
|
||
public const val NO_SURFACE_ID: Int = -1 | ||
|
||
/** | ||
* Counter for uniquely identifying views. - % 2 === 0 means it is a Fabric tag. See | ||
* https://github.com/facebook/react/pull/12587 | ||
* | ||
* @param viewTag [int] tag of the view this is event is dispatched to | ||
*/ | ||
@UIManagerType | ||
public fun getUIManagerType(viewTag: Int): Int { | ||
return if (viewTag % 2 == 0) { | ||
FABRIC | ||
} else { | ||
DEFAULT | ||
} | ||
} | ||
|
||
/** | ||
* Version of getUIManagerType that uses both surfaceId and viewTag heuristics | ||
* | ||
* @param viewTag {@link int} tag of the view this is event is dispatched to | ||
* @param surfaceId {@link int} ID of the corresponding surface | ||
*/ | ||
@UIManagerType | ||
public fun getUIManagerType(viewTag: Int, surfaceId: Int): Int { | ||
// We have a contract that Fabric events *always* have a SurfaceId passed in, and non-Fabric | ||
// events NEVER have a SurfaceId passed in (the default/placeholder of -1 is passed in instead). | ||
// | ||
// Why does this matter? | ||
// Events can be sent to Views that are part of the View hierarchy *but not directly managed | ||
// by React Native*. For example, embedded custom hierarchies, Litho hierarchies, etc. | ||
// In those cases it's important to know that the Event should be sent to the Fabric or | ||
// non-Fabric UIManager, and we cannot use the ViewTag for inference since it's not controlled | ||
// by RN and is essentially a random number. | ||
// At some point it would be great to pass the SurfaceContext here instead. | ||
@UIManagerType val uiManagerType: Int = if (surfaceId == -1) DEFAULT else FABRIC | ||
if (uiManagerType == DEFAULT && !isRootTag(viewTag)) { | ||
// TODO (T123064648): Some events for Fabric still didn't have the surfaceId set, so if it's | ||
// not a React RootView, double check if the tag belongs to Fabric. | ||
if (viewTag % 2 == 0) { | ||
return FABRIC | ||
} | ||
} | ||
return uiManagerType | ||
} | ||
|
||
/** | ||
* @param viewTag [int] react tag | ||
* @return if the react tag received by parameter is a RootTag or not. | ||
*/ | ||
public fun isRootTag(viewTag: Int): Boolean = viewTag % 10 == 1 |