From ca07a5fd5fbf819d870e8fc93e51407cc226b9ba Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Thu, 27 Apr 2017 12:48:53 -0700 Subject: [PATCH] Adopting Yoga's YGConfig in RCTShadowView Reviewed By: javache Differential Revision: D4932540 fbshipit-source-id: 4a5ff3b34fc635b3291dff9a7c1a603179c90fa7 --- React/Views/RCTShadowView.h | 7 +++++++ React/Views/RCTShadowView.m | 16 ++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/React/Views/RCTShadowView.h b/React/Views/RCTShadowView.h index 61154b1d6e4..8ec452d5ed1 100644 --- a/React/Views/RCTShadowView.h +++ b/React/Views/RCTShadowView.h @@ -35,6 +35,13 @@ typedef void (^RCTApplierBlock)(NSDictionary *viewRegistry */ @interface RCTShadowView : NSObject +/** + * Yoga Config which will be used to create `yogaNode` property. + * Override in subclass to enable special Yoga features. + * Defaults to suitable to current device configuration. + */ ++ (YGConfigRef)yogaConfig; + /** * RCTComponent interface. */ diff --git a/React/Views/RCTShadowView.m b/React/Views/RCTShadowView.m index 8de41aaca7f..c8e926ca189 100644 --- a/React/Views/RCTShadowView.m +++ b/React/Views/RCTShadowView.m @@ -46,6 +46,18 @@ typedef NS_ENUM(unsigned int, meta_prop_t) { YGValue _borderMetaProps[META_PROP_COUNT]; } ++ (YGConfigRef)yogaConfig +{ + static YGConfigRef yogaConfig; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + yogaConfig = YGConfigNew(); + // Turnig off pixel rounding. + YGConfigSetPointScaleFactor(yogaConfig, 0.0); + }); + return yogaConfig; +} + @synthesize reactTag = _reactTag; // YogaNode API @@ -318,7 +330,6 @@ static void RCTProcessMetaPropsBorder(const YGValue metaProps[META_PROP_COUNT], - (instancetype)init { if ((self = [super init])) { - _frame = CGRectMake(0, 0, YGUndefined, YGUndefined); for (unsigned int ii = 0; ii < META_PROP_COUNT; ii++) { @@ -335,7 +346,8 @@ static void RCTProcessMetaPropsBorder(const YGValue metaProps[META_PROP_COUNT], _reactSubviews = [NSMutableArray array]; - _yogaNode = YGNodeNew(); + _yogaNode = YGNodeNewWithConfig([[self class] yogaConfig]); + YGNodeSetContext(_yogaNode, (__bridge void *)self); YGNodeSetPrintFunc(_yogaNode, RCTPrint); }