mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
convert LayoutMetricsConversions to Kotlin (#43863)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43863 convert Java to Kotlin: `react/fabric/mounding/LayoutMetricsConversions.java` Changelog: [Internal] internal Reviewed By: cortinico Differential Revision: D55714004 fbshipit-source-id: fbf167cb6030916789f6676c1bd0690f144cf330
This commit is contained in:
committed by
Facebook GitHub Bot
parent
c84faadd50
commit
445c9ce806
@@ -2702,12 +2702,20 @@ public class com/facebook/react/fabric/events/FabricEventEmitter : com/facebook/
|
||||
}
|
||||
|
||||
public abstract interface class com/facebook/react/fabric/mounting/LayoutMetricsConversions {
|
||||
public static final field Companion Lcom/facebook/react/fabric/mounting/LayoutMetricsConversions$Companion;
|
||||
public static fun getMaxSize (I)F
|
||||
public static fun getMinSize (I)F
|
||||
public static fun getYogaMeasureMode (FF)Lcom/facebook/yoga/YogaMeasureMode;
|
||||
public static fun getYogaSize (FF)F
|
||||
}
|
||||
|
||||
public final class com/facebook/react/fabric/mounting/LayoutMetricsConversions$Companion {
|
||||
public final fun getMaxSize (I)F
|
||||
public final fun getMinSize (I)F
|
||||
public final fun getYogaMeasureMode (FF)Lcom/facebook/yoga/YogaMeasureMode;
|
||||
public final fun getYogaSize (FF)F
|
||||
}
|
||||
|
||||
public class com/facebook/react/fabric/mounting/MountItemDispatcher {
|
||||
public fun <init> (Lcom/facebook/react/fabric/mounting/MountingManager;Lcom/facebook/react/fabric/mounting/MountItemDispatcher$ItemDispatchListener;)V
|
||||
public fun addMountItem (Lcom/facebook/react/fabric/mounting/mountitems/MountItem;)V
|
||||
|
||||
-54
@@ -1,54 +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.fabric.mounting;
|
||||
|
||||
import static android.view.View.MeasureSpec.EXACTLY;
|
||||
|
||||
import android.view.View;
|
||||
import com.facebook.infer.annotation.Nullsafe;
|
||||
import com.facebook.react.uimanager.PixelUtil;
|
||||
import com.facebook.yoga.YogaMeasureMode;
|
||||
|
||||
@Nullsafe(Nullsafe.Mode.LOCAL)
|
||||
public interface LayoutMetricsConversions {
|
||||
|
||||
static float getMinSize(int viewMeasureSpec) {
|
||||
int mode = View.MeasureSpec.getMode(viewMeasureSpec);
|
||||
int size = View.MeasureSpec.getSize(viewMeasureSpec);
|
||||
|
||||
return mode == EXACTLY ? size : 0f;
|
||||
}
|
||||
|
||||
static float getMaxSize(int viewMeasureSpec) {
|
||||
int mode = View.MeasureSpec.getMode(viewMeasureSpec);
|
||||
int size = View.MeasureSpec.getSize(viewMeasureSpec);
|
||||
|
||||
// Infinity represents an "unconstrained" size
|
||||
return mode == View.MeasureSpec.UNSPECIFIED ? Float.POSITIVE_INFINITY : size;
|
||||
}
|
||||
|
||||
static float getYogaSize(float minSize, float maxSize) {
|
||||
if (minSize == maxSize) {
|
||||
return PixelUtil.toPixelFromDIP(maxSize);
|
||||
} else if (Float.isInfinite(maxSize)) {
|
||||
return Float.POSITIVE_INFINITY;
|
||||
} else {
|
||||
return PixelUtil.toPixelFromDIP(maxSize);
|
||||
}
|
||||
}
|
||||
|
||||
static YogaMeasureMode getYogaMeasureMode(float minSize, float maxSize) {
|
||||
if (minSize == maxSize) {
|
||||
return YogaMeasureMode.EXACTLY;
|
||||
} else if (Float.isInfinite(maxSize)) {
|
||||
return YogaMeasureMode.UNDEFINED;
|
||||
} else {
|
||||
return YogaMeasureMode.AT_MOST;
|
||||
}
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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.fabric.mounting
|
||||
|
||||
import android.view.View.MeasureSpec
|
||||
import com.facebook.react.uimanager.PixelUtil
|
||||
import com.facebook.yoga.YogaMeasureMode
|
||||
|
||||
public interface LayoutMetricsConversions {
|
||||
|
||||
public companion object {
|
||||
@JvmStatic
|
||||
public fun getMinSize(viewMeasureSpec: Int): Float {
|
||||
val mode = MeasureSpec.getMode(viewMeasureSpec)
|
||||
val size = MeasureSpec.getSize(viewMeasureSpec)
|
||||
return if (mode == MeasureSpec.EXACTLY) size.toFloat() else 0f
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
public fun getMaxSize(viewMeasureSpec: Int): Float {
|
||||
val mode = MeasureSpec.getMode(viewMeasureSpec)
|
||||
val size = MeasureSpec.getSize(viewMeasureSpec)
|
||||
|
||||
// Infinity represents an "unconstrained" size
|
||||
return if (mode == MeasureSpec.UNSPECIFIED) Float.POSITIVE_INFINITY else size.toFloat()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
public fun getYogaSize(minSize: Float, maxSize: Float): Float =
|
||||
if (minSize == maxSize) {
|
||||
PixelUtil.toPixelFromDIP(maxSize)
|
||||
} else if (maxSize.isInfinite()) {
|
||||
Float.POSITIVE_INFINITY
|
||||
} else {
|
||||
PixelUtil.toPixelFromDIP(maxSize)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
public fun getYogaMeasureMode(minSize: Float, maxSize: Float): YogaMeasureMode =
|
||||
if (minSize == maxSize) {
|
||||
YogaMeasureMode.EXACTLY
|
||||
} else if (maxSize.isInfinite()) {
|
||||
YogaMeasureMode.UNDEFINED
|
||||
} else {
|
||||
YogaMeasureMode.AT_MOST
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user