Skip to content

Commit

Permalink
Refactor ViewPropsMapBuffer -> general MapBuffer props mechanism
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rshest authored and facebook-github-bot committed Oct 3, 2022
1 parent 2319f75 commit 110b191
Show file tree
Hide file tree
Showing 18 changed files with 870 additions and 351 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ object ReactMapBufferPropSetter {
private const val VP_POINTER_OUT_CAPTURE = 42
private const val VP_POINTER_OVER = 43
private const val VP_POINTER_OVER_CAPTURE = 44
private const val VP_BORDER_CURVES = 45 // iOS only
private const val VP_FG_COLOR = 46 // iOS only?

// Yoga values
private const val YG_BORDER_WIDTH = 100
Expand Down Expand Up @@ -141,14 +143,20 @@ object ReactMapBufferPropSetter {
// TODO: color for some reason can be object in Java but not in C++
viewManager.backgroundColor(view, entry.intValue)
}
VP_FG_COLOR -> {
// Prop not used on Android?
}
VP_BORDER_COLOR -> {
viewManager.borderColor(view, entry.mapBufferValue)
}
VP_BORDER_RADII -> {
viewManager.borderRadius(view, entry.mapBufferValue)
}
VP_BORDER_STYLE -> {
viewManager.borderStyle(view, entry.intValue)
val styleBuffer = entry.mapBufferValue
if (styleBuffer.contains(CORNER_ALL)) {
viewManager.borderStyle(view, (styleBuffer.getDouble(CORNER_ALL)).toInt())
}
}
VP_ELEVATION -> {
viewManager.setElevation(view, entry.doubleValue.toFloat())
Expand Down
12 changes: 5 additions & 7 deletions ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "CppViewMutationsWrapper.h"
#include "EventEmitterWrapper.h"
#include "StateWrapperImpl.h"
#include "viewPropConversions.h"

#include <react/jni/ReadableNativeMap.h>
#include <react/renderer/components/scrollview/ScrollViewProps.h>
Expand Down Expand Up @@ -264,12 +263,11 @@ local_ref<jobject> FabricMountingManager::getProps(
react_native_assert(
newShadowView.props->rawProps.empty() &&
"Raw props must be empty when views are using mapbuffer");
auto oldProps = oldShadowView.props != nullptr
? static_cast<ViewProps const &>(*oldShadowView.props)
: ViewProps{};
auto newProps = static_cast<ViewProps const &>(*newShadowView.props);
return JReadableMapBuffer::createWithContents(
viewPropsDiff(oldProps, newProps));

// MapBufferBuilder must be constructed and live in this scope,
MapBufferBuilder builder;
newShadowView.props->propsDiffMapBuffer(&*oldShadowView.props, builder);
return JReadableMapBuffer::createWithContents(builder.build());
} else {
return ReadableNativeMap::newObjectCxxArgs(newShadowView.props->rawProps);
}
Expand Down
Loading

0 comments on commit 110b191

Please sign in to comment.