Pass context through to all prop parser (props structs changes)

Summary:
See previous diffs for context. This updates all of the relevant props structs.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D29855426

fbshipit-source-id: 30177c3380ef82ecf8f2a4321f128cfbe8a576e0
This commit is contained in:
Joshua Gross
2021-07-28 20:16:53 -07:00
committed by Facebook GitHub Bot
parent 09b9422516
commit 5d33e65694
47 changed files with 599 additions and 223 deletions
@@ -12,26 +12,45 @@
namespace facebook {
namespace react {
ImageProps::ImageProps(const ImageProps &sourceProps, const RawProps &rawProps)
: ViewProps(sourceProps, rawProps),
sources(convertRawProp(rawProps, "source", sourceProps.sources, {})),
ImageProps::ImageProps(
const PropsParserContext &context,
const ImageProps &sourceProps,
const RawProps &rawProps)
: ViewProps(context, sourceProps, rawProps),
sources(
convertRawProp(context, rawProps, "source", sourceProps.sources, {})),
defaultSources(convertRawProp(
context,
rawProps,
"defaultSource",
sourceProps.defaultSources,
{})),
resizeMode(convertRawProp(
context,
rawProps,
"resizeMode",
sourceProps.resizeMode,
ImageResizeMode::Stretch)),
blurRadius(
convertRawProp(rawProps, "blurRadius", sourceProps.blurRadius, {})),
capInsets(
convertRawProp(rawProps, "capInsets", sourceProps.capInsets, {})),
tintColor(
convertRawProp(rawProps, "tintColor", sourceProps.tintColor, {})),
blurRadius(convertRawProp(
context,
rawProps,
"blurRadius",
sourceProps.blurRadius,
{})),
capInsets(convertRawProp(
context,
rawProps,
"capInsets",
sourceProps.capInsets,
{})),
tintColor(convertRawProp(
context,
rawProps,
"tintColor",
sourceProps.tintColor,
{})),
internal_analyticTag(convertRawProp(
context,
rawProps,
"internal_analyticTag",
sourceProps.internal_analyticTag,
@@ -6,6 +6,7 @@
*/
#include <react/renderer/components/view/ViewProps.h>
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/graphics/Color.h>
#include <react/renderer/imagemanager/primitives.h>
@@ -16,7 +17,10 @@ namespace react {
class ImageProps final : public ViewProps {
public:
ImageProps() = default;
ImageProps(const ImageProps &sourceProps, const RawProps &rawProps);
ImageProps(
const PropsParserContext &context,
const ImageProps &sourceProps,
const RawProps &rawProps);
#pragma mark - Props
@@ -12,12 +12,14 @@ namespace facebook {
namespace react {
LegacyViewManagerInteropViewProps::LegacyViewManagerInteropViewProps(
const PropsParserContext &context,
const LegacyViewManagerInteropViewProps &sourceProps,
const RawProps &rawProps)
: ViewProps(sourceProps, rawProps),
otherProps(
mergeDynamicProps(sourceProps.otherProps, (folly::dynamic)rawProps)) {
}
: ViewProps(context, sourceProps, rawProps),
otherProps(mergeDynamicProps(
context,
sourceProps.otherProps,
(folly::dynamic)rawProps)) {}
} // namespace react
} // namespace facebook
@@ -7,6 +7,7 @@
#include <folly/dynamic.h>
#include <react/renderer/components/view/ViewProps.h>
#include <react/renderer/core/PropsParserContext.h>
#include <unordered_map>
namespace facebook {
@@ -16,6 +17,7 @@ class LegacyViewManagerInteropViewProps final : public ViewProps {
public:
LegacyViewManagerInteropViewProps() = default;
LegacyViewManagerInteropViewProps(
const PropsParserContext &context,
const LegacyViewManagerInteropViewProps &sourceProps,
const RawProps &rawProps);
@@ -13,10 +13,20 @@
namespace facebook {
namespace react {
RootProps::RootProps(RootProps const &sourceProps, RawProps const &rawProps)
: ViewProps(sourceProps, rawProps) {}
// Note that a default/empty context may be passed here from RootShadowNode.
// If that's a problem and the context is necesary here, refactor RootShadowNode
// first.
RootProps::RootProps(
const PropsParserContext &context,
RootProps const &sourceProps,
RawProps const &rawProps)
: ViewProps(context, sourceProps, rawProps) {}
// Note that a default/empty context may be passed here from RootShadowNode.
// If that's a problem and the context is necesary here, refactor RootShadowNode
// first.
RootProps::RootProps(
const PropsParserContext &context,
RootProps const &sourceProps,
LayoutConstraints const &layoutConstraints,
LayoutContext const &layoutContext)
@@ -12,6 +12,7 @@
#include <react/renderer/components/view/ViewProps.h>
#include <react/renderer/core/LayoutConstraints.h>
#include <react/renderer/core/LayoutContext.h>
#include <react/renderer/core/PropsParserContext.h>
namespace facebook {
namespace react {
@@ -19,8 +20,12 @@ namespace react {
class RootProps final : public ViewProps {
public:
RootProps() = default;
RootProps(RootProps const &sourceProps, RawProps const &rawProps);
RootProps(
const PropsParserContext &context,
RootProps const &sourceProps,
RawProps const &rawProps);
RootProps(
const PropsParserContext &context,
RootProps const &sourceProps,
LayoutConstraints const &layoutConstraints,
LayoutContext const &layoutContext);
@@ -39,10 +39,11 @@ Transform RootShadowNode::getTransform() const {
}
RootShadowNode::Unshared RootShadowNode::clone(
PropsParserContext const &propsParserContext,
LayoutConstraints const &layoutConstraints,
LayoutContext const &layoutContext) const {
auto props = std::make_shared<RootProps const>(
getConcreteProps(), layoutConstraints, layoutContext);
propsParserContext, getConcreteProps(), layoutConstraints, layoutContext);
auto newRootShadowNode = std::make_shared<RootShadowNode>(
*this,
ShadowNodeFragment{
@@ -12,6 +12,7 @@
#include <react/renderer/components/root/RootProps.h>
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
#include <react/renderer/core/LayoutContext.h>
#include <react/renderer/core/PropsParserContext.h>
namespace facebook {
namespace react {
@@ -51,6 +52,7 @@ class RootShadowNode final
* Clones the node with given `layoutConstraints` and `layoutContext`.
*/
RootShadowNode::Unshared clone(
PropsParserContext const &propsParserContext,
LayoutConstraints const &layoutConstraints,
LayoutContext const &layoutContext) const;
@@ -17,163 +17,204 @@ namespace facebook {
namespace react {
ScrollViewProps::ScrollViewProps(
const PropsParserContext &context,
ScrollViewProps const &sourceProps,
RawProps const &rawProps)
: ViewProps(sourceProps, rawProps),
: ViewProps(context, sourceProps, rawProps),
alwaysBounceHorizontal(convertRawProp(
context,
rawProps,
"alwaysBounceHorizontal",
sourceProps.alwaysBounceHorizontal,
{})),
alwaysBounceVertical(convertRawProp(
context,
rawProps,
"alwaysBounceVertical",
sourceProps.alwaysBounceVertical,
{})),
bounces(convertRawProp(rawProps, "bounces", sourceProps.bounces, true)),
bounces(convertRawProp(
context,
rawProps,
"bounces",
sourceProps.bounces,
true)),
bouncesZoom(convertRawProp(
context,
rawProps,
"bouncesZoom",
sourceProps.bouncesZoom,
true)),
canCancelContentTouches(convertRawProp(
context,
rawProps,
"canCancelContentTouches",
sourceProps.canCancelContentTouches,
true)),
centerContent(convertRawProp(
context,
rawProps,
"centerContent",
sourceProps.centerContent,
{})),
automaticallyAdjustContentInsets(convertRawProp(
context,
rawProps,
"automaticallyAdjustContentInsets",
sourceProps.automaticallyAdjustContentInsets,
{})),
automaticallyAdjustsScrollIndicatorInsets(convertRawProp(
context,
rawProps,
"automaticallyAdjustsScrollIndicatorInsets",
sourceProps.automaticallyAdjustsScrollIndicatorInsets,
true)),
decelerationRate(convertRawProp(
context,
rawProps,
"decelerationRate",
sourceProps.decelerationRate,
(Float)0.998)),
directionalLockEnabled(convertRawProp(
context,
rawProps,
"directionalLockEnabled",
sourceProps.directionalLockEnabled,
{})),
indicatorStyle(convertRawProp(
context,
rawProps,
"indicatorStyle",
sourceProps.indicatorStyle,
{})),
keyboardDismissMode(convertRawProp(
context,
rawProps,
"keyboardDismissMode",
sourceProps.keyboardDismissMode,
{})),
maximumZoomScale(convertRawProp(
context,
rawProps,
"maximumZoomScale",
sourceProps.maximumZoomScale,
(Float)1.0)),
minimumZoomScale(convertRawProp(
context,
rawProps,
"minimumZoomScale",
sourceProps.minimumZoomScale,
(Float)1.0)),
scrollEnabled(convertRawProp(
context,
rawProps,
"scrollEnabled",
sourceProps.scrollEnabled,
true)),
pagingEnabled(convertRawProp(
context,
rawProps,
"pagingEnabled",
sourceProps.pagingEnabled,
{})),
pinchGestureEnabled(convertRawProp(
context,
rawProps,
"pinchGestureEnabled",
sourceProps.pinchGestureEnabled,
true)),
scrollsToTop(convertRawProp(
context,
rawProps,
"scrollsToTop",
sourceProps.scrollsToTop,
true)),
showsHorizontalScrollIndicator(convertRawProp(
context,
rawProps,
"showsHorizontalScrollIndicator",
sourceProps.showsHorizontalScrollIndicator,
true)),
showsVerticalScrollIndicator(convertRawProp(
context,
rawProps,
"showsVerticalScrollIndicator",
sourceProps.showsVerticalScrollIndicator,
true)),
scrollEventThrottle(convertRawProp(
context,
rawProps,
"scrollEventThrottle",
sourceProps.scrollEventThrottle,
{})),
zoomScale(convertRawProp(
context,
rawProps,
"zoomScale",
sourceProps.zoomScale,
(Float)1.0)),
contentInset(convertRawProp(
context,
rawProps,
"contentInset",
sourceProps.contentInset,
{})),
contentOffset(convertRawProp(
context,
rawProps,
"contentOffset",
sourceProps.contentOffset,
{})),
scrollIndicatorInsets(convertRawProp(
context,
rawProps,
"scrollIndicatorInsets",
sourceProps.scrollIndicatorInsets,
{})),
snapToInterval(convertRawProp(
context,
rawProps,
"snapToInterval",
sourceProps.snapToInterval,
{})),
snapToAlignment(convertRawProp(
context,
rawProps,
"snapToAlignment",
sourceProps.snapToAlignment,
{})),
disableIntervalMomentum(convertRawProp(
context,
rawProps,
"disableIntervalMomentum",
sourceProps.disableIntervalMomentum,
{})),
snapToOffsets(convertRawProp(
context,
rawProps,
"snapToOffsets",
sourceProps.snapToOffsets,
{})),
snapToStart(convertRawProp(
context,
rawProps,
"snapToStart",
sourceProps.snapToStart,
true)),
snapToEnd(
convertRawProp(rawProps, "snapToEnd", sourceProps.snapToEnd, true)),
snapToEnd(convertRawProp(
context,
rawProps,
"snapToEnd",
sourceProps.snapToEnd,
true)),
contentInsetAdjustmentBehavior(convertRawProp(
context,
rawProps,
"contentInsetAdjustmentBehavior",
sourceProps.contentInsetAdjustmentBehavior,
{ContentInsetAdjustmentBehavior::Never})),
scrollToOverflowEnabled(convertRawProp(
context,
rawProps,
"scrollToOverflowEnabled",
sourceProps.scrollToOverflowEnabled,
@@ -9,6 +9,7 @@
#include <react/renderer/components/scrollview/primitives.h>
#include <react/renderer/components/view/ViewProps.h>
#include <react/renderer/core/PropsParserContext.h>
namespace facebook {
namespace react {
@@ -17,7 +18,10 @@ namespace react {
class ScrollViewProps final : public ViewProps {
public:
ScrollViewProps() = default;
ScrollViewProps(ScrollViewProps const &sourceProps, RawProps const &rawProps);
ScrollViewProps(
const PropsParserContext &context,
ScrollViewProps const &sourceProps,
RawProps const &rawProps);
#pragma mark - Props
@@ -16,6 +16,7 @@ namespace facebook {
namespace react {
static TextAttributes convertRawProp(
const PropsParserContext &context,
const RawProps &rawProps,
const TextAttributes sourceTextAttributes,
const TextAttributes defaultTextAttributes) {
@@ -23,16 +24,19 @@ static TextAttributes convertRawProp(
// Color
textAttributes.foregroundColor = convertRawProp(
context,
rawProps,
"color",
sourceTextAttributes.foregroundColor,
defaultTextAttributes.foregroundColor);
textAttributes.backgroundColor = convertRawProp(
context,
rawProps,
"backgroundColor",
sourceTextAttributes.backgroundColor,
defaultTextAttributes.backgroundColor);
textAttributes.opacity = convertRawProp(
context,
rawProps,
"opacity",
sourceTextAttributes.opacity,
@@ -40,46 +44,55 @@ static TextAttributes convertRawProp(
// Font
textAttributes.fontFamily = convertRawProp(
context,
rawProps,
"fontFamily",
sourceTextAttributes.fontFamily,
defaultTextAttributes.fontFamily);
textAttributes.fontSize = convertRawProp(
context,
rawProps,
"fontSize",
sourceTextAttributes.fontSize,
defaultTextAttributes.fontSize);
textAttributes.fontSizeMultiplier = convertRawProp(
context,
rawProps,
"fontSizeMultiplier",
sourceTextAttributes.fontSizeMultiplier,
defaultTextAttributes.fontSizeMultiplier);
textAttributes.fontWeight = convertRawProp(
context,
rawProps,
"fontWeight",
sourceTextAttributes.fontWeight,
defaultTextAttributes.fontWeight);
textAttributes.fontStyle = convertRawProp(
context,
rawProps,
"fontStyle",
sourceTextAttributes.fontStyle,
defaultTextAttributes.fontStyle);
textAttributes.fontVariant = convertRawProp(
context,
rawProps,
"fontVariant",
sourceTextAttributes.fontVariant,
defaultTextAttributes.fontVariant);
textAttributes.allowFontScaling = convertRawProp(
context,
rawProps,
"allowFontScaling",
sourceTextAttributes.allowFontScaling,
defaultTextAttributes.allowFontScaling);
textAttributes.letterSpacing = convertRawProp(
context,
rawProps,
"letterSpacing",
sourceTextAttributes.letterSpacing,
defaultTextAttributes.letterSpacing);
textAttributes.textTransform = convertRawProp(
context,
rawProps,
"textTransform",
sourceTextAttributes.textTransform,
@@ -87,16 +100,19 @@ static TextAttributes convertRawProp(
// Paragraph
textAttributes.lineHeight = convertRawProp(
context,
rawProps,
"lineHeight",
sourceTextAttributes.lineHeight,
defaultTextAttributes.lineHeight);
textAttributes.alignment = convertRawProp(
context,
rawProps,
"textAlign",
sourceTextAttributes.alignment,
defaultTextAttributes.alignment);
textAttributes.baseWritingDirection = convertRawProp(
context,
rawProps,
"baseWritingDirection",
sourceTextAttributes.baseWritingDirection,
@@ -104,21 +120,25 @@ static TextAttributes convertRawProp(
// Decoration
textAttributes.textDecorationColor = convertRawProp(
context,
rawProps,
"textDecorationColor",
sourceTextAttributes.textDecorationColor,
defaultTextAttributes.textDecorationColor);
textAttributes.textDecorationLineType = convertRawProp(
context,
rawProps,
"textDecorationLine",
sourceTextAttributes.textDecorationLineType,
defaultTextAttributes.textDecorationLineType);
textAttributes.textDecorationLineStyle = convertRawProp(
context,
rawProps,
"textDecorationLineStyle",
sourceTextAttributes.textDecorationLineStyle,
defaultTextAttributes.textDecorationLineStyle);
textAttributes.textDecorationLinePattern = convertRawProp(
context,
rawProps,
"textDecorationLinePattern",
sourceTextAttributes.textDecorationLinePattern,
@@ -126,16 +146,19 @@ static TextAttributes convertRawProp(
// Shadow
textAttributes.textShadowOffset = convertRawProp(
context,
rawProps,
"textShadowOffset",
sourceTextAttributes.textShadowOffset,
defaultTextAttributes.textShadowOffset);
textAttributes.textShadowRadius = convertRawProp(
context,
rawProps,
"textShadowRadius",
sourceTextAttributes.textShadowRadius,
defaultTextAttributes.textShadowRadius);
textAttributes.textShadowColor = convertRawProp(
context,
rawProps,
"textShadowColor",
sourceTextAttributes.textShadowColor,
@@ -143,12 +166,14 @@ static TextAttributes convertRawProp(
// Special
textAttributes.isHighlighted = convertRawProp(
context,
rawProps,
"isHighlighted",
sourceTextAttributes.isHighlighted,
defaultTextAttributes.isHighlighted);
textAttributes.accessibilityRole = convertRawProp(
context,
rawProps,
"accessibilityRole",
sourceTextAttributes.accessibilityRole,
@@ -158,9 +183,11 @@ static TextAttributes convertRawProp(
}
BaseTextProps::BaseTextProps(
const PropsParserContext &context,
const BaseTextProps &sourceProps,
const RawProps &rawProps)
: textAttributes(convertRawProp(
context,
rawProps,
sourceProps.textAttributes,
TextAttributes{})){};
@@ -9,6 +9,7 @@
#include <react/renderer/attributedstring/TextAttributes.h>
#include <react/renderer/core/Props.h>
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/graphics/Color.h>
#include <react/renderer/graphics/Geometry.h>
@@ -22,7 +23,10 @@ namespace react {
class BaseTextProps {
public:
BaseTextProps() = default;
BaseTextProps(const BaseTextProps &sourceProps, const RawProps &rawProps);
BaseTextProps(
const PropsParserContext &context,
const BaseTextProps &sourceProps,
const RawProps &rawProps);
#pragma mark - Props
@@ -33,10 +33,11 @@ class ParagraphComponentDescriptor final
}
virtual SharedProps interpolateProps(
const PropsParserContext &context,
float animationProgress,
const SharedProps &props,
const SharedProps &newProps) const override {
SharedProps interpolatedPropsShared = cloneProps(newProps, {});
SharedProps interpolatedPropsShared = cloneProps(context, newProps, {});
interpolateViewProps(
animationProgress, props, newProps, interpolatedPropsShared);
@@ -18,18 +18,24 @@ namespace facebook {
namespace react {
ParagraphProps::ParagraphProps(
const PropsParserContext &context,
ParagraphProps const &sourceProps,
RawProps const &rawProps)
: ViewProps(sourceProps, rawProps),
BaseTextProps(sourceProps, rawProps),
paragraphAttributes(
convertRawProp(rawProps, sourceProps.paragraphAttributes, {})),
: ViewProps(context, sourceProps, rawProps),
BaseTextProps(context, sourceProps, rawProps),
paragraphAttributes(convertRawProp(
context,
rawProps,
sourceProps.paragraphAttributes,
{})),
isSelectable(convertRawProp(
context,
rawProps,
"selectable",
sourceProps.isSelectable,
false)),
onTextLayout(convertRawProp(
context,
rawProps,
"onTextLayout",
sourceProps.onTextLayout,
@@ -14,6 +14,7 @@
#include <react/renderer/components/text/BaseTextProps.h>
#include <react/renderer/components/view/ViewProps.h>
#include <react/renderer/core/Props.h>
#include <react/renderer/core/PropsParserContext.h>
namespace facebook {
namespace react {
@@ -26,7 +27,10 @@ namespace react {
class ParagraphProps : public ViewProps, public BaseTextProps {
public:
ParagraphProps() = default;
ParagraphProps(ParagraphProps const &sourceProps, RawProps const &rawProps);
ParagraphProps(
const PropsParserContext &context,
ParagraphProps const &sourceProps,
RawProps const &rawProps);
#pragma mark - Props
@@ -14,10 +14,11 @@ namespace facebook {
namespace react {
RawTextProps::RawTextProps(
const PropsParserContext &context,
const RawTextProps &sourceProps,
const RawProps &rawProps)
: Props(sourceProps, rawProps),
text(convertRawProp(rawProps, "text", sourceProps.text, {})){};
: Props(context, sourceProps, rawProps),
text(convertRawProp(context, rawProps, "text", sourceProps.text, {})){};
#pragma mark - DebugStringConvertible
@@ -10,6 +10,7 @@
#include <memory>
#include <react/renderer/core/Props.h>
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/debug/DebugStringConvertible.h>
namespace facebook {
@@ -22,7 +23,10 @@ using SharedRawTextProps = std::shared_ptr<const RawTextProps>;
class RawTextProps : public Props {
public:
RawTextProps() = default;
RawTextProps(const RawTextProps &sourceProps, const RawProps &rawProps);
RawTextProps(
const PropsParserContext &context,
const RawTextProps &sourceProps,
const RawProps &rawProps);
#pragma mark - Props
@@ -10,9 +10,12 @@
namespace facebook {
namespace react {
TextProps::TextProps(const TextProps &sourceProps, const RawProps &rawProps)
: Props(sourceProps, rawProps),
BaseTextProps::BaseTextProps(sourceProps, rawProps){};
TextProps::TextProps(
const PropsParserContext &context,
const TextProps &sourceProps,
const RawProps &rawProps)
: Props(context, sourceProps, rawProps),
BaseTextProps::BaseTextProps(context, sourceProps, rawProps){};
#pragma mark - DebugStringConvertible
@@ -10,6 +10,7 @@
#include <react/renderer/attributedstring/TextAttributes.h>
#include <react/renderer/components/text/BaseTextProps.h>
#include <react/renderer/core/Props.h>
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/graphics/Color.h>
#include <react/renderer/graphics/Geometry.h>
@@ -19,7 +20,10 @@ namespace react {
class TextProps : public Props, public BaseTextProps {
public:
TextProps() = default;
TextProps(const TextProps &sourceProps, const RawProps &rawProps);
TextProps(
const PropsParserContext &context,
const TextProps &sourceProps,
const RawProps &rawProps);
#pragma mark - DebugStringConvertible
@@ -37,215 +37,182 @@ static bool hasValue(
}
AndroidTextInputProps::AndroidTextInputProps(
const PropsParserContext &context,
const AndroidTextInputProps &sourceProps,
const RawProps &rawProps)
: ViewProps(sourceProps, rawProps),
BaseTextProps(sourceProps, rawProps),
: ViewProps(context, sourceProps, rawProps),
BaseTextProps(context, sourceProps, rawProps),
autoCompleteType(convertRawProp(
context,
rawProps,
"autoCompleteType",
sourceProps.autoCompleteType,
{})),
returnKeyLabel(convertRawProp(
rawProps,
returnKeyLabel(convertRawProp(context, rawProps,
"returnKeyLabel",
sourceProps.returnKeyLabel,
{})),
numberOfLines(convertRawProp(
rawProps,
numberOfLines(convertRawProp(context, rawProps,
"numberOfLines",
sourceProps.numberOfLines,
{0})),
disableFullscreenUI(convertRawProp(
rawProps,
disableFullscreenUI(convertRawProp(context, rawProps,
"disableFullscreenUI",
sourceProps.disableFullscreenUI,
{false})),
textBreakStrategy(convertRawProp(
rawProps,
textBreakStrategy(convertRawProp(context, rawProps,
"textBreakStrategy",
sourceProps.textBreakStrategy,
{})),
underlineColorAndroid(convertRawProp(
rawProps,
underlineColorAndroid(convertRawProp(context, rawProps,
"underlineColorAndroid",
sourceProps.underlineColorAndroid,
{})),
inlineImageLeft(convertRawProp(
rawProps,
inlineImageLeft(convertRawProp(context, rawProps,
"inlineImageLeft",
sourceProps.inlineImageLeft,
{})),
inlineImagePadding(convertRawProp(
rawProps,
inlineImagePadding(convertRawProp(context, rawProps,
"inlineImagePadding",
sourceProps.inlineImagePadding,
{0})),
importantForAutofill(convertRawProp(
rawProps,
importantForAutofill(convertRawProp(context, rawProps,
"importantForAutofill",
sourceProps.importantForAutofill,
{})),
showSoftInputOnFocus(convertRawProp(
rawProps,
showSoftInputOnFocus(convertRawProp(context, rawProps,
"showSoftInputOnFocus",
sourceProps.showSoftInputOnFocus,
{false})),
autoCapitalize(convertRawProp(
rawProps,
autoCapitalize(convertRawProp(context, rawProps,
"autoCapitalize",
sourceProps.autoCapitalize,
{})),
autoCorrect(convertRawProp(
rawProps,
autoCorrect(convertRawProp(context, rawProps,
"autoCorrect",
sourceProps.autoCorrect,
{false})),
autoFocus(convertRawProp(
rawProps,
autoFocus(convertRawProp(context, rawProps,
"autoFocus",
sourceProps.autoFocus,
{false})),
allowFontScaling(convertRawProp(
rawProps,
allowFontScaling(convertRawProp(context, rawProps,
"allowFontScaling",
sourceProps.allowFontScaling,
{false})),
maxFontSizeMultiplier(convertRawProp(
rawProps,
maxFontSizeMultiplier(convertRawProp(context, rawProps,
"maxFontSizeMultiplier",
sourceProps.maxFontSizeMultiplier,
{0.0})),
editable(
convertRawProp(rawProps, "editable", sourceProps.editable, {false})),
keyboardType(convertRawProp(
rawProps,
convertRawProp(context, rawProps, "editable", sourceProps.editable, {false})),
keyboardType(convertRawProp(context, rawProps,
"keyboardType",
sourceProps.keyboardType,
{})),
returnKeyType(convertRawProp(
rawProps,
returnKeyType(convertRawProp(context, rawProps,
"returnKeyType",
sourceProps.returnKeyType,
{})),
maxLength(
convertRawProp(rawProps, "maxLength", sourceProps.maxLength, {0})),
multiline(convertRawProp(
rawProps,
convertRawProp(context, rawProps, "maxLength", sourceProps.maxLength, {0})),
multiline(convertRawProp(context, rawProps,
"multiline",
sourceProps.multiline,
{false})),
placeholder(
convertRawProp(rawProps, "placeholder", sourceProps.placeholder, {})),
placeholderTextColor(convertRawProp(
rawProps,
convertRawProp(context, rawProps, "placeholder", sourceProps.placeholder, {})),
placeholderTextColor(convertRawProp(context, rawProps,
"placeholderTextColor",
sourceProps.placeholderTextColor,
{})),
secureTextEntry(convertRawProp(
rawProps,
secureTextEntry(convertRawProp(context, rawProps,
"secureTextEntry",
sourceProps.secureTextEntry,
{false})),
selectionColor(convertRawProp(
rawProps,
selectionColor(convertRawProp(context, rawProps,
"selectionColor",
sourceProps.selectionColor,
{})),
selection(
convertRawProp(rawProps, "selection", sourceProps.selection, {})),
value(convertRawProp(rawProps, "value", sourceProps.value, {})),
defaultValue(convertRawProp(
rawProps,
convertRawProp(context, rawProps, "selection", sourceProps.selection, {})),
value(convertRawProp(context, rawProps, "value", sourceProps.value, {})),
defaultValue(convertRawProp(context, rawProps,
"defaultValue",
sourceProps.defaultValue,
{})),
selectTextOnFocus(convertRawProp(
rawProps,
selectTextOnFocus(convertRawProp(context, rawProps,
"selectTextOnFocus",
sourceProps.selectTextOnFocus,
{false})),
blurOnSubmit(convertRawProp(
rawProps,
blurOnSubmit(convertRawProp(context, rawProps,
"blurOnSubmit",
sourceProps.blurOnSubmit,
{false})),
caretHidden(convertRawProp(
rawProps,
caretHidden(convertRawProp(context, rawProps,
"caretHidden",
sourceProps.caretHidden,
{false})),
contextMenuHidden(convertRawProp(
rawProps,
contextMenuHidden(convertRawProp(context, rawProps,
"contextMenuHidden",
sourceProps.contextMenuHidden,
{false})),
textShadowColor(convertRawProp(
rawProps,
textShadowColor(convertRawProp(context, rawProps,
"textShadowColor",
sourceProps.textShadowColor,
{})),
textShadowRadius(convertRawProp(
rawProps,
textShadowRadius(convertRawProp(context, rawProps,
"textShadowRadius",
sourceProps.textShadowRadius,
{0.0})),
textDecorationLine(convertRawProp(
rawProps,
textDecorationLine(convertRawProp(context, rawProps,
"textDecorationLine",
sourceProps.textDecorationLine,
{})),
fontStyle(
convertRawProp(rawProps, "fontStyle", sourceProps.fontStyle, {})),
textShadowOffset(convertRawProp(
rawProps,
convertRawProp(context, rawProps, "fontStyle", sourceProps.fontStyle, {})),
textShadowOffset(convertRawProp(context, rawProps,
"textShadowOffset",
sourceProps.textShadowOffset,
{})),
lineHeight(convertRawProp(
rawProps,
lineHeight(convertRawProp(context, rawProps,
"lineHeight",
sourceProps.lineHeight,
{0.0})),
textTransform(convertRawProp(
rawProps,
textTransform(convertRawProp(context, rawProps,
"textTransform",
sourceProps.textTransform,
{})),
color(convertRawProp(rawProps, "color", sourceProps.color, {0})),
letterSpacing(convertRawProp(
rawProps,
color(0 /*convertRawProp(context, rawProps, "color", sourceProps.color, {0})*/),
letterSpacing(convertRawProp(context, rawProps,
"letterSpacing",
sourceProps.letterSpacing,
{0.0})),
fontSize(
convertRawProp(rawProps, "fontSize", sourceProps.fontSize, {0.0})),
convertRawProp(context, rawProps, "fontSize", sourceProps.fontSize, {0.0})),
textAlign(
convertRawProp(rawProps, "textAlign", sourceProps.textAlign, {})),
includeFontPadding(convertRawProp(
rawProps,
convertRawProp(context, rawProps, "textAlign", sourceProps.textAlign, {})),
includeFontPadding(convertRawProp(context, rawProps,
"includeFontPadding",
sourceProps.includeFontPadding,
{false})),
fontWeight(
convertRawProp(rawProps, "fontWeight", sourceProps.fontWeight, {})),
convertRawProp(context, rawProps, "fontWeight", sourceProps.fontWeight, {})),
fontFamily(
convertRawProp(rawProps, "fontFamily", sourceProps.fontFamily, {})),
textAlignVertical(convertRawProp(
rawProps,
convertRawProp(context, rawProps, "fontFamily", sourceProps.fontFamily, {})),
textAlignVertical(convertRawProp(context, rawProps,
"textAlignVertical",
sourceProps.textAlignVertical,
{})),
cursorColor(
convertRawProp(rawProps, "cursorColor", sourceProps.cursorColor, {})),
mostRecentEventCount(convertRawProp(
rawProps,
convertRawProp(context, rawProps, "cursorColor", sourceProps.cursorColor, {})),
mostRecentEventCount(convertRawProp(context, rawProps,
"mostRecentEventCount",
sourceProps.mostRecentEventCount,
{0})),
text(convertRawProp(rawProps, "text", sourceProps.text, {})),
text(convertRawProp(context, rawProps, "text", sourceProps.text, {})),
paragraphAttributes(
convertRawProp(rawProps, sourceProps.paragraphAttributes, {})),
convertRawProp(context, rawProps, sourceProps.paragraphAttributes, {})),
// See AndroidTextInputComponentDescriptor for usage
// TODO T63008435: can these, and this feature, be removed entirely?
hasPadding(hasValue(rawProps, sourceProps.hasPadding, "", "padding", "")),
@@ -16,6 +16,7 @@
#include <react/renderer/attributedstring/conversions.h>
#include <react/renderer/components/text/BaseTextProps.h>
#include <react/renderer/components/view/ViewProps.h>
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/core/propsConversions.h>
#include <react/renderer/graphics/Color.h>
#include <react/renderer/imagemanager/primitives.h>
@@ -31,17 +32,18 @@ struct AndroidTextInputSelectionStruct {
};
static inline void fromRawValue(
const PropsParserContext &context,
const RawValue &value,
AndroidTextInputSelectionStruct &result) {
auto map = (better::map<std::string, RawValue>)value;
auto start = map.find("start");
if (start != map.end()) {
fromRawValue(start->second, result.start);
fromRawValue(context, start->second, result.start);
}
auto end = map.find("end");
if (end != map.end()) {
fromRawValue(end->second, result.end);
fromRawValue(context, end->second, result.end);
}
}
@@ -56,17 +58,18 @@ struct AndroidTextInputTextShadowOffsetStruct {
};
static inline void fromRawValue(
const PropsParserContext &context,
const RawValue &value,
AndroidTextInputTextShadowOffsetStruct &result) {
auto map = (better::map<std::string, RawValue>)value;
auto width = map.find("width");
if (width != map.end()) {
fromRawValue(width->second, result.width);
fromRawValue(context, width->second, result.width);
}
auto height = map.find("height");
if (height != map.end()) {
fromRawValue(height->second, result.height);
fromRawValue(context, height->second, result.height);
}
}
@@ -96,6 +99,7 @@ class AndroidTextInputProps final : public ViewProps, public BaseTextProps {
public:
AndroidTextInputProps() = default;
AndroidTextInputProps(
const PropsParserContext &context,
const AndroidTextInputProps &sourceProps,
const RawProps &rawProps);
@@ -16,48 +16,74 @@ namespace facebook {
namespace react {
TextInputProps::TextInputProps(
const PropsParserContext &context,
TextInputProps const &sourceProps,
RawProps const &rawProps)
: ViewProps(sourceProps, rawProps),
BaseTextProps(sourceProps, rawProps),
traits(convertRawProp(rawProps, sourceProps.traits, {})),
paragraphAttributes(
convertRawProp(rawProps, sourceProps.paragraphAttributes, {})),
: ViewProps(context, sourceProps, rawProps),
BaseTextProps(context, sourceProps, rawProps),
traits(convertRawProp(context, rawProps, sourceProps.traits, {})),
paragraphAttributes(convertRawProp(
context,
rawProps,
sourceProps.paragraphAttributes,
{})),
defaultValue(convertRawProp(
context,
rawProps,
"defaultValue",
sourceProps.defaultValue,
{})),
placeholder(
convertRawProp(rawProps, "placeholder", sourceProps.placeholder, {})),
placeholder(convertRawProp(
context,
rawProps,
"placeholder",
sourceProps.placeholder,
{})),
placeholderTextColor(convertRawProp(
context,
rawProps,
"placeholderTextColor",
sourceProps.placeholderTextColor,
{})),
maxLength(
convertRawProp(rawProps, "maxLength", sourceProps.maxLength, {})),
cursorColor(
convertRawProp(rawProps, "cursorColor", sourceProps.cursorColor, {})),
maxLength(convertRawProp(
context,
rawProps,
"maxLength",
sourceProps.maxLength,
{})),
cursorColor(convertRawProp(
context,
rawProps,
"cursorColor",
sourceProps.cursorColor,
{})),
selectionColor(convertRawProp(
context,
rawProps,
"selectionColor",
sourceProps.selectionColor,
{})),
underlineColorAndroid(convertRawProp(
context,
rawProps,
"underlineColorAndroid",
sourceProps.underlineColorAndroid,
{})),
text(convertRawProp(rawProps, "text", sourceProps.text, {})),
text(convertRawProp(context, rawProps, "text", sourceProps.text, {})),
mostRecentEventCount(convertRawProp(
context,
rawProps,
"mostRecentEventCount",
sourceProps.mostRecentEventCount,
{})),
autoFocus(
convertRawProp(rawProps, "autoFocus", sourceProps.autoFocus, {})),
autoFocus(convertRawProp(
context,
rawProps,
"autoFocus",
sourceProps.autoFocus,
{})),
inputAccessoryViewID(convertRawProp(
context,
rawProps,
"inputAccessoryViewID",
sourceProps.inputAccessoryViewID,
@@ -14,6 +14,7 @@
#include <react/renderer/components/text/BaseTextProps.h>
#include <react/renderer/components/view/ViewProps.h>
#include <react/renderer/core/Props.h>
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/core/propsConversions.h>
#include <react/renderer/graphics/Color.h>
#include <react/renderer/imagemanager/primitives.h>
@@ -25,7 +26,10 @@ namespace react {
class TextInputProps final : public ViewProps, public BaseTextProps {
public:
TextInputProps() = default;
TextInputProps(TextInputProps const &sourceProps, RawProps const &rawProps);
TextInputProps(
const PropsParserContext &context,
TextInputProps const &sourceProps,
RawProps const &rawProps);
#pragma mark - Props
@@ -8,12 +8,14 @@
#pragma once
#include <react/renderer/components/iostextinput/primitives.h>
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/core/propsConversions.h>
namespace facebook {
namespace react {
inline void fromRawValue(
const PropsParserContext &context,
const RawValue &value,
AutocapitalizationType &result) {
auto string = (std::string)value;
@@ -36,7 +38,10 @@ inline void fromRawValue(
abort();
}
inline void fromRawValue(const RawValue &value, KeyboardAppearance &result) {
inline void fromRawValue(
const PropsParserContext &context,
const RawValue &value,
KeyboardAppearance &result) {
auto string = (std::string)value;
if (string == "default") {
result = KeyboardAppearance::Default;
@@ -53,7 +58,10 @@ inline void fromRawValue(const RawValue &value, KeyboardAppearance &result) {
abort();
}
inline void fromRawValue(const RawValue &value, ReturnKeyType &result) {
inline void fromRawValue(
const PropsParserContext &context,
const RawValue &value,
ReturnKeyType &result) {
auto string = (std::string)value;
if (string == "default") {
result = ReturnKeyType::Default;
@@ -119,6 +127,7 @@ inline void fromRawValue(const RawValue &value, ReturnKeyType &result) {
}
inline void fromRawValue(
const PropsParserContext &context,
const RawValue &value,
TextInputAccessoryVisibilityMode &result) {
auto string = (std::string)value;
@@ -141,7 +150,10 @@ inline void fromRawValue(
abort();
}
inline void fromRawValue(const RawValue &value, KeyboardType &result) {
inline void fromRawValue(
const PropsParserContext &context,
const RawValue &value,
KeyboardType &result) {
auto string = (std::string)value;
if (string == "default") {
result = KeyboardType::Default;
@@ -8,107 +8,135 @@
#pragma once
#include <react/renderer/components/iostextinput/primitives.h>
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/core/propsConversions.h>
namespace facebook {
namespace react {
static TextInputTraits convertRawProp(
const PropsParserContext &context,
RawProps const &rawProps,
TextInputTraits const &sourceTraits,
TextInputTraits const &defaultTraits) {
auto traits = TextInputTraits{};
traits.multiline = convertRawProp(
rawProps, "multiline", sourceTraits.multiline, defaultTraits.multiline);
context,
rawProps,
"multiline",
sourceTraits.multiline,
defaultTraits.multiline);
traits.autocapitalizationType = convertRawProp(
context,
rawProps,
"autoCapitalize",
sourceTraits.autocapitalizationType,
defaultTraits.autocapitalizationType);
traits.autoCorrect = convertRawProp(
context,
rawProps,
"autoCorrect",
sourceTraits.autoCorrect,
defaultTraits.autoCorrect);
traits.contextMenuHidden = convertRawProp(
context,
rawProps,
"contextMenuHidden",
sourceTraits.contextMenuHidden,
defaultTraits.contextMenuHidden);
traits.editable = convertRawProp(
rawProps, "editable", sourceTraits.editable, defaultTraits.editable);
context,
rawProps,
"editable",
sourceTraits.editable,
defaultTraits.editable);
traits.enablesReturnKeyAutomatically = convertRawProp(
context,
rawProps,
"enablesReturnKeyAutomatically",
sourceTraits.enablesReturnKeyAutomatically,
defaultTraits.enablesReturnKeyAutomatically);
traits.keyboardAppearance = convertRawProp(
context,
rawProps,
"keyboardAppearance",
sourceTraits.keyboardAppearance,
defaultTraits.keyboardAppearance);
traits.spellCheck = convertRawProp(
context,
rawProps,
"spellCheck",
sourceTraits.spellCheck,
defaultTraits.spellCheck);
traits.caretHidden = convertRawProp(
context,
rawProps,
"caretHidden",
sourceTraits.caretHidden,
defaultTraits.caretHidden);
traits.clearButtonMode = convertRawProp(
context,
rawProps,
"clearButtonMode",
sourceTraits.clearButtonMode,
defaultTraits.clearButtonMode);
traits.scrollEnabled = convertRawProp(
context,
rawProps,
"scrollEnabled",
sourceTraits.scrollEnabled,
defaultTraits.scrollEnabled);
traits.secureTextEntry = convertRawProp(
context,
rawProps,
"secureTextEntry",
sourceTraits.secureTextEntry,
defaultTraits.secureTextEntry);
traits.blurOnSubmit = convertRawProp(
context,
rawProps,
"blurOnSubmit",
sourceTraits.blurOnSubmit,
defaultTraits.blurOnSubmit);
traits.clearTextOnFocus = convertRawProp(
context,
rawProps,
"clearTextOnFocus",
sourceTraits.clearTextOnFocus,
defaultTraits.clearTextOnFocus);
traits.keyboardType = convertRawProp(
context,
rawProps,
"keyboardType",
sourceTraits.keyboardType,
defaultTraits.keyboardType);
traits.showSoftInputOnFocus = convertRawProp(
context,
rawProps,
"showSoftInputOnFocus",
sourceTraits.showSoftInputOnFocus,
defaultTraits.showSoftInputOnFocus);
traits.returnKeyType = convertRawProp(
context,
rawProps,
"returnKeyType",
sourceTraits.returnKeyType,
defaultTraits.returnKeyType);
traits.selectTextOnFocus = convertRawProp(
context,
rawProps,
"selectTextOnFocus",
sourceTraits.selectTextOnFocus,
defaultTraits.selectTextOnFocus);
traits.textContentType = convertRawProp(
context,
rawProps,
"textContentType",
sourceTraits.textContentType,
defaultTraits.textContentType);
traits.passwordRules = convertRawProp(
context,
rawProps,
"passwordRules",
sourceTraits.passwordRules,
@@ -8,6 +8,7 @@
#pragma once
#include <react/renderer/components/view/ViewProps.h>
#include <react/renderer/core/PropsParserContext.h>
namespace facebook {
namespace react {
@@ -16,79 +16,96 @@ namespace facebook {
namespace react {
AccessibilityProps::AccessibilityProps(
const PropsParserContext &context,
AccessibilityProps const &sourceProps,
RawProps const &rawProps)
: accessible(convertRawProp(
context,
rawProps,
"accessible",
sourceProps.accessible,
false)),
accessibilityTraits(convertRawProp(
context,
rawProps,
"accessibilityRole",
sourceProps.accessibilityTraits,
AccessibilityTraits::None)),
accessibilityState(convertRawProp(
context,
rawProps,
"accessibilityState",
sourceProps.accessibilityState,
{})),
accessibilityLabel(convertRawProp(
context,
rawProps,
"accessibilityLabel",
sourceProps.accessibilityLabel,
"")),
accessibilityHint(convertRawProp(
context,
rawProps,
"accessibilityHint",
sourceProps.accessibilityHint,
"")),
accessibilityActions(convertRawProp(
context,
rawProps,
"accessibilityActions",
sourceProps.accessibilityActions,
{})),
accessibilityViewIsModal(convertRawProp(
context,
rawProps,
"accessibilityViewIsModal",
sourceProps.accessibilityViewIsModal,
false)),
accessibilityElementsHidden(convertRawProp(
context,
rawProps,
"accessibilityElementsHidden",
sourceProps.accessibilityElementsHidden,
false)),
accessibilityIgnoresInvertColors(convertRawProp(
context,
rawProps,
"accessibilityIgnoresInvertColors",
sourceProps.accessibilityIgnoresInvertColors,
false)),
onAccessibilityTap(convertRawProp(
context,
rawProps,
"onAccessibilityTap",
sourceProps.onAccessibilityTap,
{})),
onAccessibilityMagicTap(convertRawProp(
context,
rawProps,
"onAccessibilityMagicTap",
sourceProps.onAccessibilityMagicTap,
{})),
onAccessibilityEscape(convertRawProp(
context,
rawProps,
"onAccessibilityEscape",
sourceProps.onAccessibilityEscape,
{})),
onAccessibilityAction(convertRawProp(
context,
rawProps,
"onAccessibilityAction",
sourceProps.onAccessibilityAction,
{})),
importantForAccessibility(convertRawProp(
context,
rawProps,
"importantForAccessibility",
sourceProps.importantForAccessibility,
ImportantForAccessibility::Auto)),
testId(convertRawProp(rawProps, "testID", sourceProps.testId, "")) {}
testId(
convertRawProp(context, rawProps, "testID", sourceProps.testId, "")) {
}
#pragma mark - DebugStringConvertible
@@ -9,6 +9,7 @@
#include <react/renderer/components/view/AccessibilityPrimitives.h>
#include <react/renderer/core/Props.h>
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/core/ReactPrimitives.h>
#include <react/renderer/debug/DebugStringConvertible.h>
@@ -19,6 +20,7 @@ class AccessibilityProps {
public:
AccessibilityProps() = default;
AccessibilityProps(
const PropsParserContext &context,
AccessibilityProps const &sourceProps,
RawProps const &rawProps);
@@ -22,6 +22,7 @@ class ViewComponentDescriptor
: ConcreteComponentDescriptor<ViewShadowNode>(parameters) {}
virtual SharedProps interpolateProps(
const PropsParserContext &context,
float animationProgress,
const SharedProps &props,
const SharedProps &newProps) const override {
@@ -29,10 +30,10 @@ class ViewComponentDescriptor
// On Android only, the merged props should have the same RawProps as the
// final props struct
SharedProps interpolatedPropsShared =
(newProps != nullptr ? cloneProps(newProps, newProps->rawProps)
: cloneProps(newProps, {}));
(newProps != nullptr ? cloneProps(context, newProps, newProps->rawProps)
: cloneProps(context, newProps, {}));
#else
SharedProps interpolatedPropsShared = cloneProps(newProps, {});
SharedProps interpolatedPropsShared = cloneProps(context, newProps, {});
#endif
interpolateViewProps(
@@ -18,88 +18,131 @@
namespace facebook {
namespace react {
ViewProps::ViewProps(ViewProps const &sourceProps, RawProps const &rawProps)
: YogaStylableProps(sourceProps, rawProps),
AccessibilityProps(sourceProps, rawProps),
opacity(
convertRawProp(rawProps, "opacity", sourceProps.opacity, (Float)1.0)),
ViewProps::ViewProps(
const PropsParserContext &context,
ViewProps const &sourceProps,
RawProps const &rawProps)
: YogaStylableProps(context, sourceProps, rawProps),
AccessibilityProps(context, sourceProps, rawProps),
opacity(convertRawProp(
context,
rawProps,
"opacity",
sourceProps.opacity,
(Float)1.0)),
foregroundColor(convertRawProp(
context,
rawProps,
"foregroundColor",
sourceProps.foregroundColor,
{})),
backgroundColor(convertRawProp(
context,
rawProps,
"backgroundColor",
sourceProps.backgroundColor,
{})),
borderRadii(convertRawProp(
context,
rawProps,
"border",
"Radius",
sourceProps.borderRadii,
{})),
borderColors(convertRawProp(
context,
rawProps,
"border",
"Color",
sourceProps.borderColors,
{})),
borderStyles(convertRawProp(
context,
rawProps,
"border",
"Style",
sourceProps.borderStyles,
{})),
shadowColor(
convertRawProp(rawProps, "shadowColor", sourceProps.shadowColor, {})),
shadowColor(convertRawProp(
context,
rawProps,
"shadowColor",
sourceProps.shadowColor,
{})),
shadowOffset(convertRawProp(
context,
rawProps,
"shadowOffset",
sourceProps.shadowOffset,
{})),
shadowOpacity(convertRawProp(
context,
rawProps,
"shadowOpacity",
sourceProps.shadowOpacity,
{})),
shadowRadius(convertRawProp(
context,
rawProps,
"shadowRadius",
sourceProps.shadowRadius,
{})),
transform(
convertRawProp(rawProps, "transform", sourceProps.transform, {})),
transform(convertRawProp(
context,
rawProps,
"transform",
sourceProps.transform,
{})),
backfaceVisibility(convertRawProp(
context,
rawProps,
"backfaceVisibility",
sourceProps.backfaceVisibility,
{})),
shouldRasterize(convertRawProp(
context,
rawProps,
"shouldRasterize",
sourceProps.shouldRasterize,
{})),
zIndex(convertRawProp(rawProps, "zIndex", sourceProps.zIndex, {})),
zIndex(
convertRawProp(context, rawProps, "zIndex", sourceProps.zIndex, {})),
pointerEvents(convertRawProp(
context,
rawProps,
"pointerEvents",
sourceProps.pointerEvents,
{})),
hitSlop(convertRawProp(rawProps, "hitSlop", sourceProps.hitSlop, {})),
onLayout(convertRawProp(rawProps, "onLayout", sourceProps.onLayout, {})),
hitSlop(convertRawProp(
context,
rawProps,
"hitSlop",
sourceProps.hitSlop,
{})),
onLayout(convertRawProp(
context,
rawProps,
"onLayout",
sourceProps.onLayout,
{})),
collapsable(convertRawProp(
context,
rawProps,
"collapsable",
sourceProps.collapsable,
true)),
removeClippedSubviews(convertRawProp(
context,
rawProps,
"removeClippedSubviews",
sourceProps.removeClippedSubviews,
false)),
elevation(
convertRawProp(rawProps, "elevation", sourceProps.elevation, {})){};
elevation(convertRawProp(
context,
rawProps,
"elevation",
sourceProps.elevation,
{})){};
#pragma mark - Convenience Methods
@@ -12,6 +12,7 @@
#include <react/renderer/components/view/primitives.h>
#include <react/renderer/core/LayoutMetrics.h>
#include <react/renderer/core/Props.h>
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/graphics/Color.h>
#include <react/renderer/graphics/Geometry.h>
#include <react/renderer/graphics/Transform.h>
@@ -26,7 +27,10 @@ using SharedViewProps = std::shared_ptr<ViewProps const>;
class ViewProps : public YogaStylableProps, public AccessibilityProps {
public:
ViewProps() = default;
ViewProps(ViewProps const &sourceProps, RawProps const &rawProps);
ViewProps(
const PropsParserContext &context,
ViewProps const &sourceProps,
RawProps const &rawProps);
#pragma mark - Props
@@ -20,10 +20,11 @@ namespace facebook {
namespace react {
YogaStylableProps::YogaStylableProps(
const PropsParserContext &context,
YogaStylableProps const &sourceProps,
RawProps const &rawProps)
: Props(sourceProps, rawProps),
yogaStyle(convertRawProp(rawProps, sourceProps.yogaStyle)){};
: Props(context, sourceProps, rawProps),
yogaStyle(convertRawProp(context, rawProps, sourceProps.yogaStyle)){};
#pragma mark - DebugStringConvertible
@@ -10,6 +10,7 @@
#include <yoga/YGStyle.h>
#include <react/renderer/core/Props.h>
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/debug/DebugStringConvertible.h>
namespace facebook {
@@ -19,6 +20,7 @@ class YogaStylableProps : public Props {
public:
YogaStylableProps() = default;
YogaStylableProps(
const PropsParserContext &context,
YogaStylableProps const &sourceProps,
RawProps const &rawProps);
@@ -11,6 +11,7 @@
#include <glog/logging.h>
#include <react/debug/react_native_assert.h>
#include <react/renderer/components/view/AccessibilityPrimitives.h>
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/core/propsConversions.h>
namespace facebook {
@@ -96,7 +97,10 @@ inline void fromString(const std::string &string, AccessibilityTraits &result) {
result = AccessibilityTraits::None;
}
inline void fromRawValue(const RawValue &value, AccessibilityTraits &result) {
inline void fromRawValue(
const PropsParserContext &context,
const RawValue &value,
AccessibilityTraits &result) {
if (value.hasType<std::string>()) {
fromString((std::string)value, result);
return;
@@ -117,15 +121,18 @@ inline void fromRawValue(const RawValue &value, AccessibilityTraits &result) {
}
}
inline void fromRawValue(const RawValue &value, AccessibilityState &result) {
inline void fromRawValue(
const PropsParserContext &context,
const RawValue &value,
AccessibilityState &result) {
auto map = (better::map<std::string, RawValue>)value;
auto selected = map.find("selected");
if (selected != map.end()) {
fromRawValue(selected->second, result.selected);
fromRawValue(context, selected->second, result.selected);
}
auto disabled = map.find("disabled");
if (disabled != map.end()) {
fromRawValue(disabled->second, result.disabled);
fromRawValue(context, disabled->second, result.disabled);
}
auto checked = map.find("checked");
if (checked != map.end()) {
@@ -147,11 +154,11 @@ inline void fromRawValue(const RawValue &value, AccessibilityState &result) {
}
auto busy = map.find("busy");
if (busy != map.end()) {
fromRawValue(busy->second, result.busy);
fromRawValue(context, busy->second, result.busy);
}
auto expanded = map.find("expanded");
if (expanded != map.end()) {
fromRawValue(expanded->second, result.expanded);
fromRawValue(context, expanded->second, result.expanded);
}
}
@@ -170,6 +177,7 @@ inline std::string toString(
}
inline void fromRawValue(
const PropsParserContext &context,
const RawValue &value,
ImportantForAccessibility &result) {
react_native_assert(value.hasType<std::string>());
@@ -192,13 +200,16 @@ inline void fromRawValue(
}
}
inline void fromRawValue(const RawValue &value, AccessibilityAction &result) {
inline void fromRawValue(
const PropsParserContext &context,
const RawValue &value,
AccessibilityAction &result) {
auto map = (better::map<std::string, RawValue>)value;
auto name = map.find("name");
react_native_assert(name != map.end() && name->second.hasType<std::string>());
if (name != map.end()) {
fromRawValue(name->second, result.name);
fromRawValue(context, name->second, result.name);
}
auto label = map.find("label");
@@ -9,6 +9,7 @@
#include <react/renderer/core/EventDispatcher.h>
#include <react/renderer/core/Props.h>
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/core/RawPropsParser.h>
#include <react/renderer/core/ShadowNode.h>
#include <react/renderer/core/State.h>
@@ -101,6 +102,7 @@ class ComponentDescriptor {
* Must return an object which is NOT pointer equal to `props`.
*/
virtual SharedProps cloneProps(
const PropsParserContext &context,
const SharedProps &props,
const RawProps &rawProps) const = 0;
@@ -109,6 +111,7 @@ class ComponentDescriptor {
* between `props` and `newProps`.
*/
virtual SharedProps interpolateProps(
const PropsParserContext &context,
float animationProgress,
const SharedProps &props,
const SharedProps &newProps) const = 0;
@@ -14,6 +14,7 @@
#include <react/renderer/core/ComponentDescriptor.h>
#include <react/renderer/core/EventDispatcher.h>
#include <react/renderer/core/Props.h>
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/core/ShadowNode.h>
#include <react/renderer/core/ShadowNodeFragment.h>
#include <react/renderer/core/State.h>
@@ -103,6 +104,7 @@ class ConcreteComponentDescriptor : public ComponentDescriptor {
}
virtual SharedProps cloneProps(
const PropsParserContext &context,
const SharedProps &props,
const RawProps &rawProps) const override {
react_native_assert(
@@ -119,12 +121,13 @@ class ConcreteComponentDescriptor : public ComponentDescriptor {
return ShadowNodeT::defaultSharedProps();
}
rawProps.parse(rawPropsParser_);
rawProps.parse(rawPropsParser_, context);
return ShadowNodeT::Props(rawProps, props);
return ShadowNodeT::Props(context, rawProps, props);
};
virtual SharedProps interpolateProps(
const PropsParserContext &context,
float animationProgress,
const SharedProps &props,
const SharedProps &newProps) const override {
@@ -133,11 +136,11 @@ class ConcreteComponentDescriptor : public ComponentDescriptor {
// On Android only, the merged props should have the same RawProps as the
// final props struct
if (newProps != nullptr) {
return cloneProps(newProps, newProps->rawProps);
return cloneProps(context, newProps, newProps->rawProps);
}
#endif
return cloneProps(newProps, {});
return cloneProps(context, newProps, {});
};
virtual State::Shared createInitialState(
@@ -10,6 +10,7 @@
#include <react/debug/react_native_assert.h>
#include <react/renderer/core/ConcreteState.h>
#include <react/renderer/core/Props.h>
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/core/ShadowNode.h>
#include <react/renderer/core/StateData.h>
@@ -68,9 +69,11 @@ class ConcreteShadowNode : public BaseShadowNodeT {
}
static SharedConcreteProps Props(
const PropsParserContext &context,
RawProps const &rawProps,
SharedProps const &baseProps = nullptr) {
return std::make_shared<PropsT const>(
context,
baseProps ? static_cast<PropsT const &>(*baseProps) : PropsT(),
rawProps);
}
+10 -2
View File
@@ -13,8 +13,16 @@
namespace facebook {
namespace react {
Props::Props(const Props &sourceProps, const RawProps &rawProps)
: nativeId(convertRawProp(rawProps, "nativeID", sourceProps.nativeId, {})),
Props::Props(
const PropsParserContext &context,
const Props &sourceProps,
const RawProps &rawProps)
: nativeId(convertRawProp(
context,
rawProps,
"nativeID",
sourceProps.nativeId,
{})),
revision(sourceProps.revision + 1)
#ifdef ANDROID
,
+5 -1
View File
@@ -9,6 +9,7 @@
#include <folly/dynamic.h>
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/core/ReactPrimitives.h>
#include <react/renderer/core/Sealable.h>
#include <react/renderer/debug/DebugStringConvertible.h>
@@ -28,7 +29,10 @@ class Props : public virtual Sealable, public virtual DebugStringConvertible {
using Shared = std::shared_ptr<Props const>;
Props() = default;
Props(Props const &sourceProps, RawProps const &rawProps);
Props(
const PropsParserContext &context,
const Props &sourceProps,
RawProps const &rawProps);
virtual ~Props() = default;
std::string nativeId;
@@ -0,0 +1,28 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <react/utils/ContextContainer.h>
namespace facebook {
namespace react {
// For props requiring some context to parse, this toolbox can be used.
// It should be used as infrequently as possible - most props can and should
// be parsed without any context.
struct PropsParserContext {
// Non-copyable
PropsParserContext(const PropsParserContext &) = delete;
PropsParserContext &operator=(const PropsParserContext &) = delete;
int surfaceId; // TODO: use SurfaceId type
const ContextContainer &contextContainer;
};
} // namespace react
} // namespace facebook
+2 -1
View File
@@ -47,7 +47,8 @@ RawProps::RawProps(folly::dynamic const &dynamic) noexcept {
dynamic_ = dynamic;
}
void RawProps::parse(RawPropsParser const &parser) const noexcept {
void RawProps::parse(RawPropsParser const &parser, const PropsParserContext &)
const noexcept {
react_native_assert(parser_ == nullptr && "A parser was already assigned.");
parser_ = &parser;
parser.preparse(*this);
+3 -1
View File
@@ -16,6 +16,7 @@
#include <folly/dynamic.h>
#include <jsi/JSIDynamic.h>
#include <jsi/jsi.h>
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/core/RawPropsKey.h>
#include <react/renderer/core/RawPropsPrimitives.h>
#include <react/renderer/core/RawValue.h>
@@ -74,7 +75,8 @@ class RawProps final {
RawProps(RawProps const &other) noexcept = delete;
RawProps &operator=(RawProps const &other) noexcept = delete;
void parse(RawPropsParser const &parser) const noexcept;
void parse(RawPropsParser const &parser, const PropsParserContext &)
const noexcept;
/*
* Deprecated. Do not use.
@@ -10,6 +10,7 @@
#include <better/map.h>
#include <better/small_vector.h>
#include <react/renderer/core/Props.h>
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/core/RawProps.h>
#include <react/renderer/core/RawPropsKey.h>
#include <react/renderer/core/RawPropsKeyMap.h>
@@ -40,8 +41,16 @@ class RawPropsParser final {
std::is_base_of<Props, PropsT>::value,
"PropsT must be a descendant of Props");
RawProps emptyRawProps{};
emptyRawProps.parse(*this);
PropsT({}, emptyRawProps);
// Create a stub parser context.
// Since this prepares the parser by passing in
// empty props, no prop parsers should actually reference the
// ContextContainer or SurfaceId here.
ContextContainer contextContainer{};
PropsParserContext parserContext{-1, contextContainer};
emptyRawProps.parse(*this, parserContext);
PropsT(parserContext, {}, emptyRawProps);
postPrepare();
}
@@ -10,6 +10,7 @@
#include <gtest/gtest.h>
#include <react/debug/flags.h>
#include <react/renderer/core/ConcreteShadowNode.h>
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/core/ShadowNode.h>
#include <react/renderer/core/propsConversions.h>
@@ -21,9 +22,11 @@ class PropsSingleFloat : public Props {
public:
PropsSingleFloat() = default;
PropsSingleFloat(
const PropsParserContext &context,
const PropsSingleFloat &sourceProps,
const RawProps &rawProps)
: floatValue(convertRawProp(
context,
rawProps,
"floatValue",
sourceProps.floatValue,
@@ -37,9 +40,11 @@ class PropsSingleDouble : public Props {
public:
PropsSingleDouble() = default;
PropsSingleDouble(
const PropsParserContext &context,
const PropsSingleDouble &sourceProps,
const RawProps &rawProps)
: doubleValue(convertRawProp(
context,
rawProps,
"doubleValue",
sourceProps.doubleValue,
@@ -52,9 +57,16 @@ class PropsSingleDouble : public Props {
class PropsSingleInt : public Props {
public:
PropsSingleInt() = default;
PropsSingleInt(const PropsSingleInt &sourceProps, const RawProps &rawProps)
: intValue(
convertRawProp(rawProps, "intValue", sourceProps.intValue, 17)) {}
PropsSingleInt(
const PropsParserContext &context,
const PropsSingleInt &sourceProps,
const RawProps &rawProps)
: intValue(convertRawProp(
context,
rawProps,
"intValue",
sourceProps.intValue,
17)) {}
private:
const int intValue{17};
@@ -64,26 +76,35 @@ class PropsPrimitiveTypes : public Props {
public:
PropsPrimitiveTypes() = default;
PropsPrimitiveTypes(
const PropsParserContext &context,
const PropsPrimitiveTypes &sourceProps,
const RawProps &rawProps)
: intValue(
convertRawProp(rawProps, "intValue", sourceProps.intValue, 17)),
: intValue(convertRawProp(
context,
rawProps,
"intValue",
sourceProps.intValue,
17)),
doubleValue(convertRawProp(
context,
rawProps,
"doubleValue",
sourceProps.doubleValue,
17.56)),
floatValue(convertRawProp(
context,
rawProps,
"floatValue",
sourceProps.floatValue,
56.75)),
stringValue(convertRawProp(
context,
rawProps,
"stringValue",
sourceProps.stringValue,
"")),
boolValue(convertRawProp(
context,
rawProps,
"boolValue",
sourceProps.boolValue,
@@ -101,9 +122,11 @@ class PropsMultiLookup : public Props {
public:
PropsMultiLookup() = default;
PropsMultiLookup(
const PropsParserContext &context,
const PropsMultiLookup &sourceProps,
const RawProps &rawProps)
: floatValue(convertRawProp(
context,
rawProps,
"floatValue",
sourceProps.floatValue,
@@ -112,7 +135,12 @@ class PropsMultiLookup : public Props {
// pattern that does occur a lot: nested structs that access props we
// have already accessed populating Props
derivedFloatValue(
convertRawProp(rawProps, "floatValue", sourceProps.floatValue, 40) *
convertRawProp(
context,
rawProps,
"floatValue",
sourceProps.floatValue,
40) *
2) {}
const float floatValue{17.5};
@@ -123,7 +151,7 @@ TEST(RawPropsTest, handleProps) {
const auto &raw = RawProps(folly::dynamic::object("nativeID", "abc"));
auto parser = RawPropsParser();
parser.prepare<Props>();
raw.parse(parser);
raw.parse(parser, {});
auto props = std::make_shared<Props>(Props(), raw);
@@ -137,7 +165,7 @@ TEST(RawPropsTest, handleRawPropsSingleString) {
const auto &raw = RawProps(folly::dynamic::object("nativeID", "abc"));
auto parser = RawPropsParser();
parser.prepare<Props>();
raw.parse(parser);
raw.parse(parser, {});
std::string value = (std::string)*raw.at("nativeID", nullptr, nullptr);
@@ -149,7 +177,7 @@ TEST(RawPropsTest, handleRawPropsSingleFloat) {
RawProps(folly::dynamic::object("floatValue", (float)42.42));
auto parser = RawPropsParser();
parser.prepare<PropsSingleFloat>();
raw.parse(parser);
raw.parse(parser, {});
float value = (float)*raw.at("floatValue", nullptr, nullptr);
@@ -161,7 +189,7 @@ TEST(RawPropsTest, handleRawPropsSingleDouble) {
RawProps(folly::dynamic::object("doubleValue", (double)42.42));
auto parser = RawPropsParser();
parser.prepare<PropsSingleDouble>();
raw.parse(parser);
raw.parse(parser, {});
double value = (double)*raw.at("doubleValue", nullptr, nullptr);
@@ -172,7 +200,7 @@ TEST(RawPropsTest, handleRawPropsSingleInt) {
const auto &raw = RawProps(folly::dynamic::object("intValue", (int)42.42));
auto parser = RawPropsParser();
parser.prepare<PropsSingleInt>();
raw.parse(parser);
raw.parse(parser, {});
int value = (int)*raw.at("intValue", nullptr, nullptr);
@@ -183,7 +211,7 @@ TEST(RawPropsTest, handleRawPropsSingleIntGetManyTimes) {
const auto &raw = RawProps(folly::dynamic::object("intValue", (int)42.42));
auto parser = RawPropsParser();
parser.prepare<PropsSingleInt>();
raw.parse(parser);
raw.parse(parser, {});
EXPECT_EQ((int)*raw.at("intValue", nullptr, nullptr), 42);
EXPECT_EQ((int)*raw.at("intValue", nullptr, nullptr), 42);
@@ -198,7 +226,7 @@ TEST(RawPropsTest, handleRawPropsPrimitiveTypes) {
auto parser = RawPropsParser();
parser.prepare<PropsPrimitiveTypes>();
raw.parse(parser);
raw.parse(parser, {});
EXPECT_EQ((int)*raw.at("intValue", nullptr, nullptr), 42);
EXPECT_NEAR((double)*raw.at("doubleValue", nullptr, nullptr), 17.42, 0.0001);
@@ -217,7 +245,7 @@ TEST(RawPropsTest, handleRawPropsPrimitiveTypesGetTwice) {
auto parser = RawPropsParser();
parser.prepare<PropsPrimitiveTypes>();
raw.parse(parser);
raw.parse(parser, {});
EXPECT_EQ((int)*raw.at("intValue", nullptr, nullptr), 42);
EXPECT_NEAR((double)*raw.at("doubleValue", nullptr, nullptr), 17.42, 0.0001);
@@ -244,7 +272,7 @@ TEST(RawPropsTest, handleRawPropsPrimitiveTypesGetOutOfOrder) {
auto parser = RawPropsParser();
parser.prepare<PropsPrimitiveTypes>();
raw.parse(parser);
raw.parse(parser, {});
EXPECT_EQ((int)*raw.at("intValue", nullptr, nullptr), 42);
EXPECT_NEAR((double)*raw.at("doubleValue", nullptr, nullptr), 17.42, 0.0001);
@@ -268,7 +296,7 @@ TEST(RawPropsTest, handleRawPropsPrimitiveTypesIncomplete) {
auto parser = RawPropsParser();
parser.prepare<PropsPrimitiveTypes>();
raw.parse(parser);
raw.parse(parser, {});
EXPECT_EQ((int)*raw.at("intValue", nullptr, nullptr), 42);
EXPECT_EQ(raw.at("doubleValue", nullptr, nullptr), nullptr);
@@ -285,7 +313,7 @@ TEST(RawPropsTest, handleRawPropsPrimitiveTypesIncorrectLookup) {
auto parser = RawPropsParser();
parser.prepare<PropsPrimitiveTypes>();
raw.parse(parser);
raw.parse(parser, {});
// Before D18662135, looking up an invalid key would trigger
// an infinite loop. This is out of contract, so we should only
@@ -299,7 +327,7 @@ TEST(RawPropsTest, handlePropsMultiLookup) {
const auto &raw = RawProps(folly::dynamic::object("floatValue", (float)10.0));
auto parser = RawPropsParser();
parser.prepare<PropsMultiLookup>();
raw.parse(parser);
raw.parse(parser, {});
auto props = std::make_shared<PropsMultiLookup>(PropsMultiLookup(), raw);
@@ -11,6 +11,7 @@
#include <folly/dynamic.h>
#include <glog/logging.h>
#include <react/debug/react_native_assert.h>
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/core/RawProps.h>
#include <react/renderer/graphics/Color.h>
#include <react/renderer/graphics/Geometry.h>
@@ -20,7 +21,10 @@ namespace react {
#pragma mark - Color
inline void fromRawValue(const RawValue &value, SharedColor &result) {
inline void fromRawValue(
const PropsParserContext &context,
const RawValue &value,
SharedColor &result) {
float red = 0;
float green = 0;
float blue = 0;
@@ -81,7 +85,10 @@ inline std::string toString(const SharedColor &value) {
#pragma mark - Geometry
inline void fromRawValue(const RawValue &value, Point &result) {
inline void fromRawValue(
const PropsParserContext &context,
const RawValue &value,
Point &result) {
if (value.hasType<better::map<std::string, Float>>()) {
auto map = (better::map<std::string, Float>)value;
for (const auto &pair : map) {
@@ -109,7 +116,10 @@ inline void fromRawValue(const RawValue &value, Point &result) {
}
}
inline void fromRawValue(const RawValue &value, Size &result) {
inline void fromRawValue(
const PropsParserContext &context,
const RawValue &value,
Size &result) {
if (value.hasType<better::map<std::string, Float>>()) {
auto map = (better::map<std::string, Float>)value;
for (const auto &pair : map) {
@@ -140,7 +150,10 @@ inline void fromRawValue(const RawValue &value, Size &result) {
}
}
inline void fromRawValue(const RawValue &value, EdgeInsets &result) {
inline void fromRawValue(
const PropsParserContext &context,
const RawValue &value,
EdgeInsets &result) {
if (value.hasType<Float>()) {
auto number = (Float)value;
result = {number, number, number, number};
@@ -180,7 +193,10 @@ inline void fromRawValue(const RawValue &value, EdgeInsets &result) {
}
}
inline void fromRawValue(const RawValue &value, CornerInsets &result) {
inline void fromRawValue(
const PropsParserContext &context,
const RawValue &value,
CornerInsets &result) {
if (value.hasType<Float>()) {
auto number = (Float)value;
result = {number, number, number, number};
@@ -40,6 +40,7 @@ namespace react {
const componentTemplate = `
::_CLASSNAME_::::::_CLASSNAME_::(
const PropsParserContext &context,
const ::_CLASSNAME_:: &sourceProps,
const RawProps &rawProps):::_EXTEND_CLASSES_::
@@ -51,7 +52,7 @@ function generatePropsString(componentName: string, component: ComponentShape) {
return component.props
.map(prop => {
const defaultValue = convertDefaultTypeToString(componentName, prop);
return `${prop.name}(convertRawProp(rawProps, "${prop.name}", sourceProps.${prop.name}, {${defaultValue}}))`;
return `${prop.name}(convertRawProp(context, rawProps, "${prop.name}", sourceProps.${prop.name}, {${defaultValue}}))`;
})
.join(',\n' + ' ');
}
@@ -65,7 +66,7 @@ function getClassExtendString(component): string {
case 'ReactNativeBuiltInType':
switch (extendProps.knownTypeName) {
case 'ReactNativeCoreViewProps':
return 'ViewProps(sourceProps, rawProps)';
return 'ViewProps(context, sourceProps, rawProps)';
default:
(extendProps.knownTypeName: empty);
throw new Error('Invalid knownTypeName');
@@ -91,6 +92,7 @@ module.exports = {
const fileName = 'Props.cpp';
const allImports: Set<string> = new Set([
'#include <react/renderer/core/propsConversions.h>',
'#include <react/renderer/core/PropsParserContext.h>',
]);
const componentProps = Object.keys(schema.modules)
@@ -60,7 +60,7 @@ const classTemplate = `
class ::_CLASSNAME_:: final::_EXTEND_CLASSES_:: {
public:
::_CLASSNAME_::() = default;
::_CLASSNAME_::(const ::_CLASSNAME_:: &sourceProps, const RawProps &rawProps);
::_CLASSNAME_::(const PropsParserContext& context, const ::_CLASSNAME_:: &sourceProps, const RawProps &rawProps);
#pragma mark - Props
@@ -71,7 +71,7 @@ class ::_CLASSNAME_:: final::_EXTEND_CLASSES_:: {
const enumTemplate = `
enum class ::_ENUM_NAME_:: { ::_VALUES_:: };
static inline void fromRawValue(const RawValue &value, ::_ENUM_NAME_:: &result) {
static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ::_ENUM_NAME_:: &result) {
auto string = (std::string)value;
::_FROM_CASES_::
abort();
@@ -87,7 +87,7 @@ static inline std::string toString(const ::_ENUM_NAME_:: &value) {
const intEnumTemplate = `
enum class ::_ENUM_NAME_:: { ::_VALUES_:: };
static inline void fromRawValue(const RawValue &value, ::_ENUM_NAME_:: &result) {
static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ::_ENUM_NAME_:: &result) {
assert(value.hasType<int>());
auto integerValue = (int)value;
switch (integerValue) {::_FROM_CASES_::
@@ -106,7 +106,7 @@ const structTemplate = `struct ::_STRUCT_NAME_:: {
::_FIELDS_::
};
static inline void fromRawValue(const RawValue &value, ::_STRUCT_NAME_:: &result) {
static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ::_STRUCT_NAME_:: &result) {
auto map = (better::map<std::string, RawValue>)value;
::_FROM_CASES_::
@@ -117,23 +117,23 @@ static inline std::string toString(const ::_STRUCT_NAME_:: &value) {
}
`.trim();
const arrayConversionFunction = `static inline void fromRawValue(const RawValue &value, std::vector<::_STRUCT_NAME_::> &result) {
const arrayConversionFunction = `static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, std::vector<::_STRUCT_NAME_::> &result) {
auto items = (std::vector<RawValue>)value;
for (const auto &item : items) {
::_STRUCT_NAME_:: newItem;
fromRawValue(item, newItem);
fromRawValue(context, item, newItem);
result.emplace_back(newItem);
}
}
`;
const doubleArrayConversionFunction = `static inline void fromRawValue(const RawValue &value, std::vector<std::vector<::_STRUCT_NAME_::>> &result) {
const doubleArrayConversionFunction = `static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, std::vector<std::vector<::_STRUCT_NAME_::>> &result) {
auto items = (std::vector<std::vector<RawValue>>)value;
for (const std::vector<RawValue> &item : items) {
auto nestedArray = std::vector<::_STRUCT_NAME_::>{};
for (const RawValue &nestedItem : item) {
::_STRUCT_NAME_:: newItem;
fromRawValue(nestedItem, newItem);
fromRawValue(context, nestedItem, newItem);
nestedArray.emplace_back(newItem);
}
result.emplace_back(nestedArray);
@@ -166,7 +166,7 @@ constexpr void operator|=(
lhs = lhs | static_cast<::_ENUM_MASK_::>(rhs);
}
static inline void fromRawValue(const RawValue &value, ::_ENUM_MASK_:: &result) {
static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ::_ENUM_MASK_:: &result) {
auto items = std::vector<std::string>{value};
for (const auto &item : items) {
::_FROM_CASES_::
@@ -460,6 +460,8 @@ function getExtendsImports(
): Set<string> {
const imports: Set<string> = new Set();
imports.add('#include <react/renderer/core/PropsParserContext.h>');
extendsProps.forEach(extendProps => {
switch (extendProps.type) {
case 'ReactNativeBuiltInType':
@@ -737,7 +739,7 @@ function generateStruct(
const variable = property.name;
return `auto ${variable} = map.find("${property.name}");
if (${variable} != map.end()) {
fromRawValue(${variable}->second, result.${variable});
fromRawValue(context, ${variable}->second, result.${variable});
}`;
})
.join('\n ');