Refactor types used during yoga meassure calls

Summary: This diff refactors the types used when Yoga requires to measure the size of a View in C++

Reviewed By: shergin

Differential Revision: D13124086

fbshipit-source-id: 89dfe80bb41b4fb2eaba84af630d52ef2509b1e1
This commit is contained in:
David Vacca 2018-11-25 17:18:10 -08:00 коммит произвёл Facebook Github Bot
Родитель 0357d0de64
Коммит 10ce6c3e11
5 изменённых файлов: 24 добавлений и 14 удалений

Просмотреть файл

@ -213,7 +213,7 @@ public abstract class ViewManager<T extends View, C extends ReactShadowNode>
return null; return null;
} }
public float[] measure( public long measure(
ReactContext context, ReactContext context,
T view, T view,
ReadableNativeMap localData, ReadableNativeMap localData,
@ -222,6 +222,6 @@ public abstract class ViewManager<T extends View, C extends ReactShadowNode>
YogaMeasureMode widthMode, YogaMeasureMode widthMode,
float height, float height,
YogaMeasureMode heightMode) { YogaMeasureMode heightMode) {
return null; return 0;
} }
} }

Просмотреть файл

@ -103,7 +103,7 @@ public class ReactTextViewManager
return MapBuilder.of("topTextLayout", MapBuilder.of("registrationName", "onTextLayout")); return MapBuilder.of("topTextLayout", MapBuilder.of("registrationName", "onTextLayout"));
} }
public float[] measure( public long measure(
ReactContext context, ReactContext context,
ReactTextView view, ReactTextView view,
ReadableNativeMap localData, ReadableNativeMap localData,

Просмотреть файл

@ -32,6 +32,7 @@ import com.facebook.react.uimanager.ReactStylesDiffMap;
import com.facebook.react.uimanager.ViewDefaults; import com.facebook.react.uimanager.ViewDefaults;
import com.facebook.yoga.YogaConstants; import com.facebook.yoga.YogaConstants;
import com.facebook.yoga.YogaMeasureMode; import com.facebook.yoga.YogaMeasureMode;
import com.facebook.yoga.YogaMeasureOutput;
import java.awt.font.TextAttribute; import java.awt.font.TextAttribute;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -189,7 +190,7 @@ public class TextLayoutManager {
return sb; return sb;
} }
public static float[] measureText( public static long measureText(
ReactContext context, ReactContext context,
ReactTextView view, ReactTextView view,
ReadableNativeMap attributedString, ReadableNativeMap attributedString,
@ -296,7 +297,7 @@ public class TextLayoutManager {
height = layout.getHeight(); height = layout.getHeight();
} }
return new float[] { PixelUtil.toSPFromPixel(width), PixelUtil.toSPFromPixel(height) }; return YogaMeasureOutput.make(PixelUtil.toSPFromPixel(width), PixelUtil.toSPFromPixel(height));
} }
private static class SetSpanOperation { private static class SetSpanOperation {

Просмотреть файл

@ -34,5 +34,19 @@ inline std::string toString(const DisplayType &displayType) {
} }
} }
inline Size yogaMeassureToSize(int64_t value) {
static_assert(
sizeof(value) == 8,
"Expected measureResult to be 8 bytes, or two 32 bit ints");
int32_t wBits = 0xFFFFFFFF & (value >> 32);
int32_t hBits = 0xFFFFFFFF & value;
float *measuredWidth = reinterpret_cast<float *>(&wBits);
float *measuredHeight = reinterpret_cast<float *>(&hBits);
return {*measuredWidth, *measuredHeight};
}
} // namespace react } // namespace react
} // namespace facebook } // namespace facebook

Просмотреть файл

@ -8,6 +8,7 @@
#include "TextLayoutManager.h" #include "TextLayoutManager.h"
#include <react/attributedstring/conversions.h> #include <react/attributedstring/conversions.h>
#include <react/core/conversions.h>
#include <react/jni/ReadableNativeMap.h> #include <react/jni/ReadableNativeMap.h>
using namespace facebook::jni; using namespace facebook::jni;
@ -32,7 +33,7 @@ Size TextLayoutManager::measure(
auto clazz = auto clazz =
jni::findClassStatic("com/facebook/fbreact/fabric/FabricUIManager"); jni::findClassStatic("com/facebook/fbreact/fabric/FabricUIManager");
static auto measure = clazz->getMethod<JArrayFloat::javaobject( static auto measure = clazz->getMethod<jlong(
jint, jint,
jstring, jstring,
ReadableNativeMap::javaobject, ReadableNativeMap::javaobject,
@ -49,7 +50,7 @@ Size TextLayoutManager::measure(
int maxWidth = (int)maximumSize.width; int maxWidth = (int)maximumSize.width;
int maxHeight = (int)maximumSize.height; int maxHeight = (int)maximumSize.height;
local_ref<JString> componentName = make_jstring("RCTText"); local_ref<JString> componentName = make_jstring("RCTText");
auto values = measure( return yogaMeassureToSize(measure(
fabricUIManager, fabricUIManager,
reactTag, reactTag,
componentName.get(), componentName.get(),
@ -58,13 +59,7 @@ Size TextLayoutManager::measure(
minWidth, minWidth,
maxWidth, maxWidth,
minHeight, minHeight,
maxHeight); maxHeight));
std::vector<float> indices;
indices.resize(values->size());
values->getRegion(0, values->size(), indices.data());
return {indices[0], indices[1]};
} }
} // namespace react } // namespace react