diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java index 9291b5e335a..eac64d218a8 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java @@ -540,8 +540,9 @@ public class FabricUIManager implements UIManager, LifecycleEventListener { private long measureMapBuffer( int surfaceId, String componentName, - ReadableMapBuffer attributedString, - ReadableMapBuffer paragraphAttributes, + ReadableMapBuffer localData, + ReadableMapBuffer props, + @Nullable ReadableMapBuffer state, float minWidth, float maxWidth, float minHeight, @@ -561,11 +562,12 @@ public class FabricUIManager implements UIManager, LifecycleEventListener { } // TODO: replace ReadableNativeMap -> ReadableMapBuffer - return mMountingManager.measureTextMapBuffer( + return mMountingManager.measureMapBuffer( context, componentName, - attributedString, - paragraphAttributes, + localData, + props, + state, getYogaSize(minWidth, maxWidth), getYogaMeasureMode(minWidth, maxWidth), getYogaSize(minHeight, maxHeight), diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java index 43ff442ef6d..74305bfacbb 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java @@ -10,7 +10,6 @@ package com.facebook.react.fabric.mounting; import static com.facebook.infer.annotation.ThreadConfined.ANY; import static com.facebook.infer.annotation.ThreadConfined.UI; -import android.text.Spannable; import android.view.View; import androidx.annotation.AnyThread; import androidx.annotation.NonNull; @@ -32,8 +31,6 @@ import com.facebook.react.touch.JSResponderHandler; import com.facebook.react.uimanager.RootViewManager; import com.facebook.react.uimanager.ThemedReactContext; import com.facebook.react.uimanager.ViewManagerRegistry; -import com.facebook.react.views.text.ReactTextViewManagerCallback; -import com.facebook.react.views.text.TextLayoutManagerMapBuffer; import com.facebook.yoga.YogaMeasureMode; import java.util.Map; import java.util.Queue; @@ -386,8 +383,8 @@ public class MountingManager { * * @param context * @param componentName - * @param attributedString - * @param paragraphAttributes + * @param localData + * @param props * @param width * @param widthMode * @param height @@ -396,30 +393,30 @@ public class MountingManager { * @return */ @AnyThread - public long measureTextMapBuffer( + public long measureMapBuffer( @NonNull ReactContext context, @NonNull String componentName, - @NonNull ReadableMapBuffer attributedString, - @NonNull ReadableMapBuffer paragraphAttributes, + @NonNull ReadableMapBuffer localData, + @NonNull ReadableMapBuffer props, + @Nullable ReadableMapBuffer state, float width, @NonNull YogaMeasureMode widthMode, float height, @NonNull YogaMeasureMode heightMode, @Nullable float[] attachmentsPositions) { - return TextLayoutManagerMapBuffer.measureText( - context, - attributedString, - paragraphAttributes, - width, - widthMode, - height, - heightMode, - new ReactTextViewManagerCallback() { - @Override - public void onPostProcessSpannable(Spannable text) {} - }, - attachmentsPositions); + return mViewManagerRegistry + .get(componentName) + .measure( + context, + localData, + props, + state, + width, + widthMode, + height, + heightMode, + attachmentsPositions); } public void initializeViewManager(String componentName) { 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 f27c5eddec7..3a0879c98a5 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManager.java @@ -15,6 +15,7 @@ import com.facebook.react.bridge.BaseJavaModule; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableMap; +import com.facebook.react.common.mapbuffer.ReadableMapBuffer; import com.facebook.react.touch.JSResponderHandler; import com.facebook.react.touch.ReactInterceptingViewGroup; import com.facebook.react.uimanager.annotations.ReactProp; @@ -323,6 +324,47 @@ public abstract class ViewManager return 0; } + /** + * THIS MEASURE METHOD IS EXPERIMENTAL, MOST LIKELY YOU ARE LOOKING TO USE THE OTHER OVERLOAD + * INSTEAD: {@link #measure(Context, ReadableMap, ReadableMap, ReadableMap, float, + * YogaMeasureMode, float, YogaMeasureMode, float[])} + * + *

Subclasses can override this method to implement custom measure functions for the + * ViewManager + * + * @param context {@link com.facebook.react.bridge.ReactContext} used for the view. + * @param localData {@link ReadableMapBuffer} containing "local data" defined in C++ + * @param props {@link ReadableMapBuffer} containing JS props + * @param state {@link ReadableMapBuffer} containing state defined in C++ + * @param width width of the view (usually zero) + * @param widthMode widthMode used during calculation of layout + * @param height height of the view (usually zero) + * @param heightMode widthMode used during calculation of layout + * @param attachmentsPositions {@link int[]} array containing 2x times the amount of attachments + * of the view. An attachment represents the position of an inline view that needs to be + * rendered inside a component and it requires the content of the parent view in order to be + * positioned. This array is meant to be used by the platform to RETURN the position of each + * attachment, as a result of the calculation of layout. (e.g. this array is used to measure + * inlineViews that are rendered inside Text components). On most of the components this array + * will be contain a null value. + *

Even values will represent the TOP of each attachment, Odd values represent the LEFT of + * each attachment. + * @return result of calculation of layout for the arguments received as a parameter. + */ + public long measure( + Context context, + ReadableMapBuffer localData, + ReadableMapBuffer props, + // TODO(T114731225): review whether state parameter is needed + @Nullable ReadableMapBuffer state, + float width, + YogaMeasureMode widthMode, + float height, + YogaMeasureMode heightMode, + @Nullable float[] attachmentsPositions) { + return 0; + } + /** * Subclasses can override this method to set padding for the given View in Fabric. Since not all * components support setting padding, the default implementation of this method does nothing. 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 a9623479824..f5033368acf 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 @@ -175,7 +175,6 @@ public class ReactTextViewManager float height, YogaMeasureMode heightMode, @Nullable float[] attachmentsPositions) { - return TextLayoutManager.measureText( context, localData, @@ -188,6 +187,29 @@ public class ReactTextViewManager attachmentsPositions); } + @Override + public long measure( + Context context, + ReadableMapBuffer localData, + ReadableMapBuffer props, + @Nullable ReadableMapBuffer state, + float width, + YogaMeasureMode widthMode, + float height, + YogaMeasureMode heightMode, + @Nullable float[] attachmentsPositions) { + return TextLayoutManagerMapBuffer.measureText( + context, + localData, + props, + width, + widthMode, + height, + heightMode, + mReactTextViewManagerCallback, + attachmentsPositions); + } + @Override public void setPadding(ReactTextView view, int left, int top, int right, int bottom) { view.setPadding(left, top, right, bottom); diff --git a/ReactCommon/react/renderer/textlayoutmanager/platform/android/react/renderer/textlayoutmanager/TextLayoutManager.cpp b/ReactCommon/react/renderer/textlayoutmanager/platform/android/react/renderer/textlayoutmanager/TextLayoutManager.cpp index 0701852e01d..925ab9bc6f7 100644 --- a/ReactCommon/react/renderer/textlayoutmanager/platform/android/react/renderer/textlayoutmanager/TextLayoutManager.cpp +++ b/ReactCommon/react/renderer/textlayoutmanager/platform/android/react/renderer/textlayoutmanager/TextLayoutManager.cpp @@ -113,6 +113,7 @@ Size measureAndroidComponentMapBuffer( jstring, ReadableMapBuffer::javaobject, ReadableMapBuffer::javaobject, + ReadableMapBuffer::javaobject, jfloat, jfloat, jfloat, @@ -129,6 +130,7 @@ Size measureAndroidComponentMapBuffer( componentNameRef.get(), localDataMap.get(), propsMap.get(), + nullptr, minWidth, maxWidth, minHeight,