From 8367fa9644b0f58ce192a1bb56648a1e9da34044 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Sat, 17 Nov 2018 01:52:50 -0800 Subject: [PATCH] Implement layout constraint when measuring text Summary: This diff adds support for layout constraint when measuring text Reviewed By: shergin Differential Revision: D13111434 fbshipit-source-id: 0c8689e9ac8ce2281b03386f275d2a8e034f88d8 --- .../facebook/react/uimanager/ViewManager.java | 5 +++-- .../react/views/text/ReactTextViewManager.java | 13 ++++++------- .../platform/android/TextLayoutManager.cpp | 16 ++++++++++++---- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManager.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManager.java index 4abd015eb..f73493257 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManager.java @@ -18,6 +18,7 @@ import com.facebook.react.touch.ReactInterceptingViewGroup; import com.facebook.react.uimanager.annotations.ReactProp; import com.facebook.react.uimanager.annotations.ReactPropGroup; import com.facebook.react.uimanager.annotations.ReactPropertyHolder; +import com.facebook.yoga.YogaMeasureMode; import java.util.Map; import javax.annotation.Nullable; @@ -218,9 +219,9 @@ public abstract class ViewManager ReadableNativeMap localData, ReadableNativeMap props, float width, - int widthMode, + YogaMeasureMode widthMode, float height, - int heightMode) { + YogaMeasureMode heightMode) { return null; } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextViewManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextViewManager.java index c2f4ed22b..39cedcf70 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextViewManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextViewManager.java @@ -9,18 +9,18 @@ package com.facebook.react.views.text; import android.text.Layout; import android.text.Spannable; -import com.facebook.react.common.MapBuilder; import com.facebook.react.bridge.ReactContext; import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.ReadableNativeMap; +import com.facebook.react.common.MapBuilder; import com.facebook.react.common.annotations.VisibleForTesting; import com.facebook.react.module.annotations.ReactModule; import com.facebook.react.uimanager.ReactStylesDiffMap; import com.facebook.react.uimanager.ThemedReactContext; +import com.facebook.yoga.YogaMeasureMode; import java.util.Map; import javax.annotation.Nullable; -import com.facebook.yoga.YogaMeasureMode; /** * Concrete class for {@link ReactTextAnchorViewManager} which represents view managers of anchor @@ -109,18 +109,17 @@ public class ReactTextViewManager ReadableNativeMap localData, ReadableNativeMap props, float width, - int widthMode, + YogaMeasureMode widthMode, float height, - int heightMode) { + YogaMeasureMode heightMode) { - // TODO: should widthMode and heightMode be a YogaMeasureMode? return TextLayoutManager.measureText(context, view, localData, props, width, - YogaMeasureMode.fromInt(widthMode), + widthMode, height, - YogaMeasureMode.fromInt(heightMode)); + heightMode); } } diff --git a/ReactCommon/fabric/textlayoutmanager/platform/android/TextLayoutManager.cpp b/ReactCommon/fabric/textlayoutmanager/platform/android/TextLayoutManager.cpp index f58ad5330..251b81314 100644 --- a/ReactCommon/fabric/textlayoutmanager/platform/android/TextLayoutManager.cpp +++ b/ReactCommon/fabric/textlayoutmanager/platform/android/TextLayoutManager.cpp @@ -38,10 +38,16 @@ Size TextLayoutManager::measure( ReadableNativeMap::javaobject, ReadableNativeMap::javaobject, jint, + jint, + jint, jint)>("measure"); - int width = (int)layoutConstraints.maximumSize.width; - int height = (int)layoutConstraints.maximumSize.height; + auto minimumSize = layoutConstraints.minimumSize; + auto maximumSize = layoutConstraints.maximumSize; + int minWidth = (int)minimumSize.width; + int minHeight = (int)minimumSize.height; + int maxWidth = (int)maximumSize.width; + int maxHeight = (int)maximumSize.height; local_ref componentName = make_jstring("RCTText"); auto values = measure( fabricUIManager, @@ -49,8 +55,10 @@ Size TextLayoutManager::measure( componentName.get(), ReadableNativeMap::newObjectCxxArgs(toDynamic(attributedString)).get(), ReadableNativeMap::newObjectCxxArgs(toDynamic(paragraphAttributes)).get(), - width, - height); + minWidth, + maxWidth, + minHeight, + maxHeight); std::vector indices; indices.resize(values->size());