Skip to content

Commit 11108f3

Browse files
rshestfacebook-github-bot
authored andcommitted
Migrate ProgressBarShadowNode.java to Kotlin (facebook#43770)
Summary: Pull Request resolved: facebook#43770 # Changelog: [Internal] - As in the title. Reviewed By: cortinico Differential Revision: D55636867 fbshipit-source-id: 2c88d8e2c39baead0094865af9dd7de5d6bc111a
1 parent c01edf4 commit 11108f3

File tree

3 files changed

+62
-84
lines changed

3 files changed

+62
-84
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6222,11 +6222,11 @@ public abstract interface class com/facebook/react/views/modal/ReactModalHostVie
62226222
public abstract fun onRequestClose (Landroid/content/DialogInterface;)V
62236223
}
62246224

6225-
public class com/facebook/react/views/progressbar/ProgressBarShadowNode : com/facebook/react/uimanager/LayoutShadowNode, com/facebook/yoga/YogaMeasureFunction {
6225+
public final class com/facebook/react/views/progressbar/ProgressBarShadowNode : com/facebook/react/uimanager/LayoutShadowNode, com/facebook/yoga/YogaMeasureFunction {
62266226
public fun <init> ()V
6227-
public fun getStyle ()Ljava/lang/String;
6227+
public final fun getStyle ()Ljava/lang/String;
62286228
public fun measure (Lcom/facebook/yoga/YogaNode;FLcom/facebook/yoga/YogaMeasureMode;FLcom/facebook/yoga/YogaMeasureMode;)J
6229-
public fun setStyle (Ljava/lang/String;)V
6229+
public final fun setStyle (Ljava/lang/String;)V
62306230
}
62316231

62326232
public class com/facebook/react/views/progressbar/ProgressBarShadowNode$$PropsSetter : com/facebook/react/uimanager/ViewManagerPropertyUpdater$ShadowNodeSetter {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ProgressBarShadowNode.java

Lines changed: 0 additions & 81 deletions
This file was deleted.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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.views.progressbar
9+
10+
import android.util.SparseIntArray
11+
import android.view.View
12+
import android.view.ViewGroup
13+
import com.facebook.react.uimanager.LayoutShadowNode
14+
import com.facebook.react.uimanager.annotations.ReactProp
15+
import com.facebook.yoga.YogaMeasureFunction
16+
import com.facebook.yoga.YogaMeasureMode
17+
import com.facebook.yoga.YogaMeasureOutput
18+
import com.facebook.yoga.YogaNode
19+
20+
/**
21+
* Node responsible for holding the style of the ProgressBar, see under [ ] for possible styles.
22+
* ReactProgressBarViewManager manages how this style is applied to the ProgressBar.
23+
*/
24+
public class ProgressBarShadowNode : LayoutShadowNode(), YogaMeasureFunction {
25+
private val height: SparseIntArray = SparseIntArray()
26+
private val width: SparseIntArray = SparseIntArray()
27+
private val measured: MutableSet<Int> = HashSet()
28+
29+
init {
30+
setMeasureFunction(this)
31+
}
32+
33+
@set:ReactProp(name = ReactProgressBarViewManager.PROP_STYLE)
34+
public var style: String? = ReactProgressBarViewManager.DEFAULT_STYLE
35+
set(value) {
36+
field = value ?: ReactProgressBarViewManager.DEFAULT_STYLE
37+
}
38+
39+
override fun measure(
40+
node: YogaNode,
41+
width: Float,
42+
widthMode: YogaMeasureMode,
43+
height: Float,
44+
heightMode: YogaMeasureMode
45+
): Long {
46+
val style = ReactProgressBarViewManager.getStyleFromString(style)
47+
if (!measured.contains(style)) {
48+
val progressBar = ReactProgressBarViewManager.createProgressBar(themedContext, style)
49+
val spec =
50+
View.MeasureSpec.makeMeasureSpec(
51+
ViewGroup.LayoutParams.WRAP_CONTENT, View.MeasureSpec.UNSPECIFIED)
52+
progressBar.measure(spec, spec)
53+
this.height.put(style, progressBar.measuredHeight)
54+
this.width.put(style, progressBar.measuredWidth)
55+
measured.add(style)
56+
}
57+
return YogaMeasureOutput.make(this.width[style], this.height[style])
58+
}
59+
}

0 commit comments

Comments
 (0)