Skip to content

Commit 110b191

Browse files
rshestfacebook-github-bot
authored andcommitted
Refactor ViewPropsMapBuffer -> general MapBuffer props mechanism
Summary: Previously, ViewPropsMapBuffer conversions were hardcoded deep in Android infrastructrue. I've generalized this into a different mechanism to allow any Props struct to support MapBuffer props. There are still some things that need to be cleaned up and this should be treated as experimental. One thing we likely want to do is remove the hardcoded IDs (fine for codegen'd code; less so for handwritten) and use compile-time-hashed IDs instead with human-readable string names. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D38708719 fbshipit-source-id: 64603dee7f21828be31346c555d99862dab304ea
1 parent 2319f75 commit 110b191

18 files changed

+870
-351
lines changed

ReactAndroid/src/main/java/com/facebook/react/views/view/ReactMapBufferPropSetter.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ object ReactMapBufferPropSetter {
6262
private const val VP_POINTER_OUT_CAPTURE = 42
6363
private const val VP_POINTER_OVER = 43
6464
private const val VP_POINTER_OVER_CAPTURE = 44
65+
private const val VP_BORDER_CURVES = 45 // iOS only
66+
private const val VP_FG_COLOR = 46 // iOS only?
6567

6668
// Yoga values
6769
private const val YG_BORDER_WIDTH = 100
@@ -141,14 +143,20 @@ object ReactMapBufferPropSetter {
141143
// TODO: color for some reason can be object in Java but not in C++
142144
viewManager.backgroundColor(view, entry.intValue)
143145
}
146+
VP_FG_COLOR -> {
147+
// Prop not used on Android?
148+
}
144149
VP_BORDER_COLOR -> {
145150
viewManager.borderColor(view, entry.mapBufferValue)
146151
}
147152
VP_BORDER_RADII -> {
148153
viewManager.borderRadius(view, entry.mapBufferValue)
149154
}
150155
VP_BORDER_STYLE -> {
151-
viewManager.borderStyle(view, entry.intValue)
156+
val styleBuffer = entry.mapBufferValue
157+
if (styleBuffer.contains(CORNER_ALL)) {
158+
viewManager.borderStyle(view, (styleBuffer.getDouble(CORNER_ALL)).toInt())
159+
}
152160
}
153161
VP_ELEVATION -> {
154162
viewManager.setElevation(view, entry.doubleValue.toFloat())

ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "CppViewMutationsWrapper.h"
1010
#include "EventEmitterWrapper.h"
1111
#include "StateWrapperImpl.h"
12-
#include "viewPropConversions.h"
1312

1413
#include <react/jni/ReadableNativeMap.h>
1514
#include <react/renderer/components/scrollview/ScrollViewProps.h>
@@ -264,12 +263,11 @@ local_ref<jobject> FabricMountingManager::getProps(
264263
react_native_assert(
265264
newShadowView.props->rawProps.empty() &&
266265
"Raw props must be empty when views are using mapbuffer");
267-
auto oldProps = oldShadowView.props != nullptr
268-
? static_cast<ViewProps const &>(*oldShadowView.props)
269-
: ViewProps{};
270-
auto newProps = static_cast<ViewProps const &>(*newShadowView.props);
271-
return JReadableMapBuffer::createWithContents(
272-
viewPropsDiff(oldProps, newProps));
266+
267+
// MapBufferBuilder must be constructed and live in this scope,
268+
MapBufferBuilder builder;
269+
newShadowView.props->propsDiffMapBuffer(&*oldShadowView.props, builder);
270+
return JReadableMapBuffer::createWithContents(builder.build());
273271
} else {
274272
return ReadableNativeMap::newObjectCxxArgs(newShadowView.props->rawProps);
275273
}

0 commit comments

Comments
 (0)