From 36c052ad966f4e12c4df102523fee5efee09d427 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Fri, 22 Jun 2018 11:53:50 -0700 Subject: [PATCH] Fabric: Default support of `displayType` and `layoutDirection` layout metrics Summary: @public Quite trivial. Reviewed By: mdvacca Differential Revision: D8528922 fbshipit-source-id: 1e21f988317eecc7aa659fd9b51600b9e2b7d69f --- .../Mounting/UIView+ComponentViewProtocol.mm | 27 +++++++++++++------ .../fabric/core/primitives/Sealable.cpp | 8 +++--- ReactCommon/fabric/core/primitives/Sealable.h | 8 +++--- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/React/Fabric/Mounting/UIView+ComponentViewProtocol.mm b/React/Fabric/Mounting/UIView+ComponentViewProtocol.mm index eeb645811..579f45723 100644 --- a/React/Fabric/Mounting/UIView+ComponentViewProtocol.mm +++ b/React/Fabric/Mounting/UIView+ComponentViewProtocol.mm @@ -10,6 +10,8 @@ #import #import "RCTConversions.h" +using namespace facebook::react; + @implementation UIView (ComponentViewProtocol) - (void)mountChildComponentView:(UIView *)childComponentView @@ -25,31 +27,40 @@ [childComponentView removeFromSuperview]; } -- (void)updateProps:(facebook::react::SharedProps)props - oldProps:(facebook::react::SharedProps)oldProps +- (void)updateProps:(SharedProps)props + oldProps:(SharedProps)oldProps { // Default implementation does nothing. } -- (void)updateEventEmitter:(facebook::react::SharedEventEmitter)eventEmitter +- (void)updateEventEmitter:(SharedEventEmitter)eventEmitter { // Default implementation does nothing. } -- (void)updateLocalData:(facebook::react::SharedLocalData)localData - oldLocalData:(facebook::react::SharedLocalData)oldLocalData +- (void)updateLocalData:(SharedLocalData)localData + oldLocalData:(SharedLocalData)oldLocalData { // Default implementation does nothing. } -- (void)updateLayoutMetrics:(facebook::react::LayoutMetrics)layoutMetrics - oldLayoutMetrics:(facebook::react::LayoutMetrics)oldLayoutMetrics +- (void)updateLayoutMetrics:(LayoutMetrics)layoutMetrics + oldLayoutMetrics:(LayoutMetrics)oldLayoutMetrics { if (layoutMetrics.frame != oldLayoutMetrics.frame) { self.frame = RCTCGRectFromRect(layoutMetrics.frame); } - // TODO: Apply another layout metrics here. + if (layoutMetrics.layoutDirection != oldLayoutMetrics.layoutDirection) { + self.semanticContentAttribute = + layoutMetrics.layoutDirection == LayoutDirection::RightToLeft ? + UISemanticContentAttributeForceRightToLeft : + UISemanticContentAttributeForceLeftToRight; + } + + if (layoutMetrics.displayType != oldLayoutMetrics.displayType) { + self.hidden = layoutMetrics.displayType == DisplayType::None; + } } - (void)prepareForRecycle diff --git a/ReactCommon/fabric/core/primitives/Sealable.cpp b/ReactCommon/fabric/core/primitives/Sealable.cpp index a93f640db..a44181ee1 100644 --- a/ReactCommon/fabric/core/primitives/Sealable.cpp +++ b/ReactCommon/fabric/core/primitives/Sealable.cpp @@ -26,18 +26,18 @@ namespace react { Sealable::Sealable(): sealed_(false) {} -Sealable::Sealable(const Sealable& other): sealed_(false) {}; +Sealable::Sealable(const Sealable &other): sealed_(false) {}; -Sealable::Sealable(Sealable&& other) noexcept: sealed_(false) {}; +Sealable::Sealable(Sealable &&other) noexcept: sealed_(false) {}; Sealable::~Sealable() noexcept {}; -Sealable& Sealable::operator= (const Sealable& other) { +Sealable &Sealable::operator=(const Sealable &other) { ensureUnsealed(); return *this; } -Sealable& Sealable::operator= (Sealable&& other) noexcept { +Sealable &Sealable::operator=(Sealable &&other) noexcept { ensureUnsealed(); return *this; }; diff --git a/ReactCommon/fabric/core/primitives/Sealable.h b/ReactCommon/fabric/core/primitives/Sealable.h index 7f07819a1..8cc3c6ed9 100644 --- a/ReactCommon/fabric/core/primitives/Sealable.h +++ b/ReactCommon/fabric/core/primitives/Sealable.h @@ -43,11 +43,11 @@ namespace react { class Sealable { public: Sealable(); - Sealable(const Sealable& other); - Sealable(Sealable&& other) noexcept; + Sealable(const Sealable &other); + Sealable(Sealable &&other) noexcept; ~Sealable() noexcept; - Sealable& operator=(const Sealable& other); - Sealable& operator=(Sealable&& other) noexcept; + Sealable &operator=(const Sealable &other); + Sealable &operator=(Sealable &&other) noexcept; /* * Seals the object. This operation is irreversible;