Skip to content

Commit 305a85d

Browse files
Migrate ViewGroupManager.java to kotlin
1 parent 4e679a2 commit 305a85d

File tree

2 files changed

+72
-116
lines changed

2 files changed

+72
-116
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewGroupManager.java

Lines changed: 0 additions & 116 deletions
This file was deleted.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
package com.facebook.react.uimanager
9+
10+
import android.view.View
11+
import android.view.ViewGroup
12+
import com.facebook.react.bridge.ReactApplicationContext
13+
import com.facebook.react.bridge.UiThreadUtil
14+
import java.util.*
15+
16+
public abstract class ViewGroupManager<T : ViewGroup>
17+
@JvmOverloads
18+
constructor(reactContext: ReactApplicationContext? = null) :
19+
BaseViewManager<T, LayoutShadowNode>(reactContext), IViewGroupManager<T> {
20+
21+
public companion object {
22+
private val zIndexHash: WeakHashMap<View, Int> = WeakHashMap()
23+
24+
@JvmStatic
25+
public fun setViewZIndex(view: View, zIndex: Int): Unit = zIndexHash.set(view, zIndex)
26+
27+
@JvmStatic public fun getViewZIndex(view: View?): Int? = zIndexHash[view]
28+
}
29+
30+
public override fun createShadowNodeInstance(): LayoutShadowNode = LayoutShadowNode()
31+
32+
public override fun getShadowNodeClass(): Class<out LayoutShadowNode> =
33+
LayoutShadowNode::class.java
34+
35+
public override fun updateExtraData(root: T, extraData: Any) {}
36+
37+
public override fun addView(parent: T, child: View, index: Int): Unit =
38+
parent.addView(child, index)
39+
40+
/**
41+
* Convenience method for batching a set of addView calls Note that this adds the views to the
42+
* beginning of the ViewGroup
43+
*
44+
* @param parent the parent ViewGroup
45+
* @param views the set of views to add
46+
*/
47+
public fun addViews(parent: T, views: List<View>) {
48+
UiThreadUtil.assertOnUiThread()
49+
views.forEachIndexed { i, view -> addView(parent, view, i) }
50+
}
51+
52+
public override fun getChildCount(parent: T): Int = parent.childCount
53+
54+
public override fun getChildAt(parent: T, index: Int): View? = parent.getChildAt(index)
55+
56+
public override fun removeViewAt(parent: T, index: Int) {
57+
UiThreadUtil.assertOnUiThread()
58+
parent.removeViewAt(index)
59+
}
60+
61+
public fun removeView(parent: T, view: View) {
62+
UiThreadUtil.assertOnUiThread()
63+
for (i in 0 until getChildCount(parent)) {
64+
if (getChildAt(parent, i) === view) {
65+
removeViewAt(parent, i)
66+
break
67+
}
68+
}
69+
}
70+
71+
public override fun needsCustomLayoutForChildren(): Boolean = false
72+
}

0 commit comments

Comments
 (0)