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

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

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

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

@ -32,6 +32,7 @@ import com.facebook.react.uimanager.ReactStylesDiffMap;
import com.facebook.react.uimanager.ViewDefaults;
import com.facebook.yoga.YogaConstants;
import com.facebook.yoga.YogaMeasureMode;
import com.facebook.yoga.YogaMeasureOutput;
import java.awt.font.TextAttribute;
import java.util.ArrayList;
import java.util.List;
@ -189,7 +190,7 @@ public class TextLayoutManager {
return sb;
}
public static float[] measureText(
public static long measureText(
ReactContext context,
ReactTextView view,
ReadableNativeMap attributedString,
@ -296,7 +297,7 @@ public class TextLayoutManager {
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 {

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

@ -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 facebook

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

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