mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Migrate ProgressBarShadowNode.java to Kotlin (#43770)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43770 # Changelog: [Internal] - As in the title. Reviewed By: cortinico Differential Revision: D55636867 fbshipit-source-id: 2c88d8e2c39baead0094865af9dd7de5d6bc111a
This commit is contained in:
committed by
Facebook GitHub Bot
parent
c01edf4115
commit
11108f3763
@@ -6222,11 +6222,11 @@ public abstract interface class com/facebook/react/views/modal/ReactModalHostVie
|
||||
public abstract fun onRequestClose (Landroid/content/DialogInterface;)V
|
||||
}
|
||||
|
||||
public class com/facebook/react/views/progressbar/ProgressBarShadowNode : com/facebook/react/uimanager/LayoutShadowNode, com/facebook/yoga/YogaMeasureFunction {
|
||||
public final class com/facebook/react/views/progressbar/ProgressBarShadowNode : com/facebook/react/uimanager/LayoutShadowNode, com/facebook/yoga/YogaMeasureFunction {
|
||||
public fun <init> ()V
|
||||
public fun getStyle ()Ljava/lang/String;
|
||||
public final fun getStyle ()Ljava/lang/String;
|
||||
public fun measure (Lcom/facebook/yoga/YogaNode;FLcom/facebook/yoga/YogaMeasureMode;FLcom/facebook/yoga/YogaMeasureMode;)J
|
||||
public fun setStyle (Ljava/lang/String;)V
|
||||
public final fun setStyle (Ljava/lang/String;)V
|
||||
}
|
||||
|
||||
public class com/facebook/react/views/progressbar/ProgressBarShadowNode$$PropsSetter : com/facebook/react/uimanager/ViewManagerPropertyUpdater$ShadowNodeSetter {
|
||||
|
||||
-81
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.facebook.react.views.progressbar;
|
||||
|
||||
import android.util.SparseIntArray;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ProgressBar;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.facebook.infer.annotation.Nullsafe;
|
||||
import com.facebook.react.uimanager.LayoutShadowNode;
|
||||
import com.facebook.react.uimanager.annotations.ReactProp;
|
||||
import com.facebook.yoga.YogaMeasureFunction;
|
||||
import com.facebook.yoga.YogaMeasureMode;
|
||||
import com.facebook.yoga.YogaMeasureOutput;
|
||||
import com.facebook.yoga.YogaNode;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Node responsible for holding the style of the ProgressBar, see under {@link
|
||||
* android.R.attr.progressBarStyle} for possible styles. ReactProgressBarViewManager manages how
|
||||
* this style is applied to the ProgressBar.
|
||||
*/
|
||||
@Nullsafe(Nullsafe.Mode.LOCAL)
|
||||
public class ProgressBarShadowNode extends LayoutShadowNode implements YogaMeasureFunction {
|
||||
|
||||
private String mStyle = ReactProgressBarViewManager.DEFAULT_STYLE;
|
||||
|
||||
private final SparseIntArray mHeight;
|
||||
private final SparseIntArray mWidth;
|
||||
private final Set<Integer> mMeasured;
|
||||
|
||||
public ProgressBarShadowNode() {
|
||||
mHeight = new SparseIntArray();
|
||||
mWidth = new SparseIntArray();
|
||||
mMeasured = new HashSet<>();
|
||||
initMeasureFunction();
|
||||
}
|
||||
|
||||
private void initMeasureFunction() {
|
||||
setMeasureFunction(this);
|
||||
}
|
||||
|
||||
public @Nullable String getStyle() {
|
||||
return mStyle;
|
||||
}
|
||||
|
||||
@ReactProp(name = ReactProgressBarViewManager.PROP_STYLE)
|
||||
public void setStyle(@Nullable String style) {
|
||||
mStyle = style == null ? ReactProgressBarViewManager.DEFAULT_STYLE : style;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long measure(
|
||||
YogaNode node,
|
||||
float width,
|
||||
YogaMeasureMode widthMode,
|
||||
float height,
|
||||
YogaMeasureMode heightMode) {
|
||||
final int style = ReactProgressBarViewManager.getStyleFromString(getStyle());
|
||||
if (!mMeasured.contains(style)) {
|
||||
ProgressBar progressBar =
|
||||
ReactProgressBarViewManager.createProgressBar(getThemedContext(), style);
|
||||
final int spec =
|
||||
View.MeasureSpec.makeMeasureSpec(
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT, View.MeasureSpec.UNSPECIFIED);
|
||||
progressBar.measure(spec, spec);
|
||||
mHeight.put(style, progressBar.getMeasuredHeight());
|
||||
mWidth.put(style, progressBar.getMeasuredWidth());
|
||||
mMeasured.add(style);
|
||||
}
|
||||
|
||||
return YogaMeasureOutput.make(mWidth.get(style), mHeight.get(style));
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.facebook.react.views.progressbar
|
||||
|
||||
import android.util.SparseIntArray
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.facebook.react.uimanager.LayoutShadowNode
|
||||
import com.facebook.react.uimanager.annotations.ReactProp
|
||||
import com.facebook.yoga.YogaMeasureFunction
|
||||
import com.facebook.yoga.YogaMeasureMode
|
||||
import com.facebook.yoga.YogaMeasureOutput
|
||||
import com.facebook.yoga.YogaNode
|
||||
|
||||
/**
|
||||
* Node responsible for holding the style of the ProgressBar, see under [ ] for possible styles.
|
||||
* ReactProgressBarViewManager manages how this style is applied to the ProgressBar.
|
||||
*/
|
||||
public class ProgressBarShadowNode : LayoutShadowNode(), YogaMeasureFunction {
|
||||
private val height: SparseIntArray = SparseIntArray()
|
||||
private val width: SparseIntArray = SparseIntArray()
|
||||
private val measured: MutableSet<Int> = HashSet()
|
||||
|
||||
init {
|
||||
setMeasureFunction(this)
|
||||
}
|
||||
|
||||
@set:ReactProp(name = ReactProgressBarViewManager.PROP_STYLE)
|
||||
public var style: String? = ReactProgressBarViewManager.DEFAULT_STYLE
|
||||
set(value) {
|
||||
field = value ?: ReactProgressBarViewManager.DEFAULT_STYLE
|
||||
}
|
||||
|
||||
override fun measure(
|
||||
node: YogaNode,
|
||||
width: Float,
|
||||
widthMode: YogaMeasureMode,
|
||||
height: Float,
|
||||
heightMode: YogaMeasureMode
|
||||
): Long {
|
||||
val style = ReactProgressBarViewManager.getStyleFromString(style)
|
||||
if (!measured.contains(style)) {
|
||||
val progressBar = ReactProgressBarViewManager.createProgressBar(themedContext, style)
|
||||
val spec =
|
||||
View.MeasureSpec.makeMeasureSpec(
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT, View.MeasureSpec.UNSPECIFIED)
|
||||
progressBar.measure(spec, spec)
|
||||
this.height.put(style, progressBar.measuredHeight)
|
||||
this.width.put(style, progressBar.measuredWidth)
|
||||
measured.add(style)
|
||||
}
|
||||
return YogaMeasureOutput.make(this.width[style], this.height[style])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user