diff --git a/Libraries/Animated/createAnimatedComponent.js b/Libraries/Animated/createAnimatedComponent.js index f7dd9bb4078888..fda18f0af80744 100644 --- a/Libraries/Animated/createAnimatedComponent.js +++ b/Libraries/Animated/createAnimatedComponent.js @@ -53,16 +53,8 @@ function createAnimatedComponent( ); class AnimatedComponent extends React.Component { - constructor(props) { - super(props); - this._waitForUpdate(); - this._attachProps(this.props); - this._lastProps = this.props; - } - _component: any; // TODO T53738161: flow type this, and the whole file _invokeAnimatedPropsCallbackOnMount: boolean = false; - _lastProps: Object; _prevComponent: any; _propsAnimated: AnimatedProps; _eventDetachers: Array = []; @@ -182,6 +174,10 @@ function createAnimatedComponent( _attachProps(nextProps) { const oldPropsAnimated = this._propsAnimated; + if (nextProps === oldPropsAnimated) { + return; + } + this._propsAnimated = new AnimatedProps( nextProps, this._animatedPropsCallback, @@ -223,11 +219,6 @@ function createAnimatedComponent( }); render() { - if (this._lastProps !== this.props) { - this._waitForUpdate(); - this._attachProps(this.props); - this._lastProps = this.props; - } const {style = {}, ...props} = this._propsAnimated.__getValue() || {}; const {style: passthruStyle = {}, ...passthruProps} = this.props.passthroughAnimatedPropExplicitValues || {}; @@ -272,6 +263,11 @@ function createAnimatedComponent( ); } + UNSAFE_componentWillMount() { + this._waitForUpdate(); + this._attachProps(this.props); + } + componentDidMount() { if (this._invokeAnimatedPropsCallbackOnMount) { this._invokeAnimatedPropsCallbackOnMount = false; @@ -283,6 +279,11 @@ function createAnimatedComponent( this._markUpdateComplete(); } + UNSAFE_componentWillReceiveProps(newProps) { + this._waitForUpdate(); + this._attachProps(newProps); + } + componentDidUpdate(prevProps) { if (this._component !== this._prevComponent) { this._propsAnimated.setNativeView(this._component); diff --git a/React/Fabric/RCTScheduler.mm b/React/Fabric/RCTScheduler.mm index b9d38d6cd869ef..e8dc96ac1384fc 100644 --- a/React/Fabric/RCTScheduler.mm +++ b/React/Fabric/RCTScheduler.mm @@ -45,7 +45,8 @@ void schedulerDidDispatchCommand( [scheduler.delegate schedulerDidDispatchCommand:shadowView commandName:commandName args:args]; } - void schedulerDidSetIsJSResponder(ShadowView const &shadowView, bool isJSResponder) override + void schedulerDidSetIsJSResponder(ShadowView const &shadowView, bool isJSResponder, bool blockNativeResponder) + override { RCTScheduler *scheduler = (__bridge RCTScheduler *)scheduler_; [scheduler.delegate schedulerDidSetIsJSResponder:isJSResponder forShadowView:shadowView]; diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.cpp b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.cpp index 1e4a912384f0cd..f1ff744d17de0b 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.cpp +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.cpp @@ -618,8 +618,7 @@ void Binding::schedulerDidFinishTransaction( auto &mutationType = mutation.type; auto &index = mutation.index; - bool isVirtual = newChildShadowView.layoutMetrics == EmptyLayoutMetrics && - oldChildShadowView.layoutMetrics == EmptyLayoutMetrics; + bool isVirtual = mutation.mutatedViewIsVirtual(); switch (mutationType) { case ShadowViewMutation::Create: { @@ -1190,7 +1189,8 @@ void Binding::schedulerDidSendAccessibilityEvent( void Binding::schedulerDidSetIsJSResponder( ShadowView const &shadowView, - bool isJSResponder) { + bool isJSResponder, + bool blockNativeResponder) { jni::global_ref localJavaUIManager = getJavaUIManager(); if (!localJavaUIManager) { LOG(ERROR) << "Binding::schedulerSetJSResponder: JavaUIManager disappeared"; @@ -1215,7 +1215,7 @@ void Binding::schedulerDidSetIsJSResponder( // be flattened because the only component that uses this feature - // ScrollView - cannot be flattened. shadowView.tag, - (jboolean) true); + (jboolean)blockNativeResponder); } else { clearJSResponder(localJavaUIManager); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.h b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.h index 92015e5bcd6079..b16bd9dc63655e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.h +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.h @@ -147,7 +147,8 @@ class Binding : public jni::HybridClass, void schedulerDidSetIsJSResponder( ShadowView const &shadowView, - bool isJSResponder) override; + bool isJSResponder, + bool blockNativeResponder) override; void setPixelDensity(float pointScaleFactor); diff --git a/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.cpp b/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.cpp index bfe92a75dd1aaa..4937bab9777861 100644 --- a/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.cpp +++ b/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.cpp @@ -406,7 +406,7 @@ void LayoutAnimationKeyFrameManager:: isRemoveMutation || mutation.type == ShadowViewMutation::Type::Insert); // TODO: turn all of this into a lambda and share code? - if (mutatedViewIsVirtual(mutation)) { + if (mutation.mutatedViewIsVirtual()) { PrintMutationInstruction( "[IndexAdjustment] Not calling adjustImmediateMutationIndicesForDelayedMutations, is virtual, for:", mutation); @@ -457,7 +457,7 @@ void LayoutAnimationKeyFrameManager:: if (delayedMutation.type != ShadowViewMutation::Type::Remove) { continue; } - if (mutatedViewIsVirtual(delayedMutation)) { + if (delayedMutation.mutatedViewIsVirtual()) { continue; } if (delayedMutation.oldChildShadowView.tag == @@ -519,7 +519,7 @@ void LayoutAnimationKeyFrameManager::adjustDelayedMutationIndicesForMutation( bool isInsertMutation = mutation.type == ShadowViewMutation::Type::Insert; react_native_assert(isRemoveMutation || isInsertMutation); - if (mutatedViewIsVirtual(mutation)) { + if (mutation.mutatedViewIsVirtual()) { PrintMutationInstruction( "[IndexAdjustment] Not calling adjustDelayedMutationIndicesForMutation, is virtual, for:", mutation); @@ -573,7 +573,7 @@ void LayoutAnimationKeyFrameManager::adjustDelayedMutationIndicesForMutation( if (finalAnimationMutation.type != ShadowViewMutation::Type::Remove) { continue; } - if (mutatedViewIsVirtual(*animatedKeyFrame.finalMutationForKeyFrame)) { + if (animatedKeyFrame.finalMutationForKeyFrame->mutatedViewIsVirtual()) { continue; } @@ -674,8 +674,8 @@ LayoutAnimationKeyFrameManager::getAndEraseConflictingAnimations( // for example, "insert" mutations where the final update needs to set // opacity to "1", even if there's no final ShadowNode update. if (!(animatedKeyFrame.finalMutationForKeyFrame.has_value() && - mutatedViewIsVirtual( - *animatedKeyFrame.finalMutationForKeyFrame))) { + animatedKeyFrame.finalMutationForKeyFrame + ->mutatedViewIsVirtual())) { conflictingAnimations.push_back(animatedKeyFrame); } @@ -777,7 +777,7 @@ LayoutAnimationKeyFrameManager::pullTransaction( continue; } if (keyframe.finalMutationForKeyFrame && - !mutatedViewIsVirtual(*keyframe.finalMutationForKeyFrame)) { + !keyframe.finalMutationForKeyFrame->mutatedViewIsVirtual()) { std::string msg = "Animation " + std::to_string(i) + " keyframe " + std::to_string(j) + ": Final Animation"; PrintMutationInstruction(msg, *keyframe.finalMutationForKeyFrame); @@ -1594,7 +1594,7 @@ LayoutAnimationKeyFrameManager::pullTransaction( continue; } if (keyframe.finalMutationForKeyFrame && - !mutatedViewIsVirtual(*keyframe.finalMutationForKeyFrame)) { + !keyframe.finalMutationForKeyFrame->mutatedViewIsVirtual()) { std::string msg = "Animation " + std::to_string(i) + " keyframe " + std::to_string(j) + ": Final Animation"; PrintMutationInstruction(msg, *keyframe.finalMutationForKeyFrame); @@ -1626,21 +1626,6 @@ LayoutAnimationKeyFrameManager::pullTransaction( surfaceId, transactionNumber, std::move(mutations), telemetry}; } -bool LayoutAnimationKeyFrameManager::mutatedViewIsVirtual( - ShadowViewMutation const &mutation) const { - bool viewIsVirtual = false; - - // TODO: extract this into an Android platform-specific class? - // Explanation: for "Insert" mutations, oldChildShadowView is always empty. - // for "Remove" mutations, newChildShadowView is always empty. -#ifdef ANDROID - viewIsVirtual = - mutation.newChildShadowView.layoutMetrics == EmptyLayoutMetrics && - mutation.oldChildShadowView.layoutMetrics == EmptyLayoutMetrics; -#endif - return viewIsVirtual; -} - bool LayoutAnimationKeyFrameManager::hasComponentDescriptorForShadowView( ShadowView const &shadowView) const { return componentDescriptorRegistry_->hasComponentDescriptorAt( diff --git a/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.h b/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.h index 83c3014ea8f744..2186c2431a49e7 100644 --- a/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.h +++ b/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.h @@ -226,8 +226,6 @@ class LayoutAnimationKeyFrameManager : public UIManagerAnimationDelegate, mutable std::vector surfaceIdsToStop_{}; protected: - bool mutatedViewIsVirtual(ShadowViewMutation const &mutation) const; - bool hasComponentDescriptorForShadowView(ShadowView const &shadowView) const; ComponentDescriptor const &getComponentDescriptorForShadowView( ShadowView const &shadowView) const; diff --git a/ReactCommon/react/renderer/mounting/ShadowViewMutation.cpp b/ReactCommon/react/renderer/mounting/ShadowViewMutation.cpp index dbf4afd227c935..9f0c61d27466d8 100644 --- a/ReactCommon/react/renderer/mounting/ShadowViewMutation.cpp +++ b/ReactCommon/react/renderer/mounting/ShadowViewMutation.cpp @@ -68,6 +68,22 @@ ShadowViewMutation ShadowViewMutation::UpdateMutation( }; } +bool ShadowViewMutation::mutatedViewIsVirtual() const { + bool viewIsVirtual = false; + +#ifdef ANDROID + // Explanation: Even for non-virtual views, + // for "Insert" mutations, oldChildShadowView is always empty. + // for "Remove" mutations, newChildShadowView is always empty. + // Thus, to see if a view is virtual, we need to always check both the old and + // new View. + viewIsVirtual = newChildShadowView.layoutMetrics == EmptyLayoutMetrics && + oldChildShadowView.layoutMetrics == EmptyLayoutMetrics; +#endif + + return viewIsVirtual; +} + #if RN_DEBUG_STRING_CONVERTIBLE std::string getDebugName(ShadowViewMutation const &mutation) { diff --git a/ReactCommon/react/renderer/mounting/ShadowViewMutation.h b/ReactCommon/react/renderer/mounting/ShadowViewMutation.h index 3bd0067d5fdcbc..6eb7f8f1d3abed 100644 --- a/ReactCommon/react/renderer/mounting/ShadowViewMutation.h +++ b/ReactCommon/react/renderer/mounting/ShadowViewMutation.h @@ -69,6 +69,14 @@ struct ShadowViewMutation final { ShadowView oldChildShadowView = {}; ShadowView newChildShadowView = {}; int index = -1; + + public: + // Some platforms can have the notion of virtual views - views that are in the + // ShadowTree hierarchy but never are on the platform. Generally this is used + // so notify the platform that a view exists so that we can keep EventEmitters + // around, to notify JS of something. This mechanism is DEPRECATED and it is + // highly recommended that you NOT make use of this in your platform! + bool mutatedViewIsVirtual() const; }; using ShadowViewMutationList = std::vector; diff --git a/ReactCommon/react/renderer/mounting/StubViewTree.cpp b/ReactCommon/react/renderer/mounting/StubViewTree.cpp index cdcae7e1c28e23..577e88e366b291 100644 --- a/ReactCommon/react/renderer/mounting/StubViewTree.cpp +++ b/ReactCommon/react/renderer/mounting/StubViewTree.cpp @@ -73,62 +73,67 @@ void StubViewTree::mutate(ShadowViewMutationList const &mutations) { } case ShadowViewMutation::Insert: { - react_native_assert(mutation.oldChildShadowView == ShadowView{}); - auto parentTag = mutation.parentShadowView.tag; - react_native_assert(registry.find(parentTag) != registry.end()); - auto parentStubView = registry[parentTag]; - auto childTag = mutation.newChildShadowView.tag; - react_native_assert(registry.find(childTag) != registry.end()); - auto childStubView = registry[childTag]; - react_native_assert(childStubView->parentTag == NO_VIEW_TAG); - childStubView->update(mutation.newChildShadowView); - STUB_VIEW_LOG({ - LOG(ERROR) << "StubView: Insert [" << childTag << "] into [" - << parentTag << "] @" << mutation.index << "(" - << parentStubView->children.size() << " children)"; - }); - react_native_assert(parentStubView->children.size() >= mutation.index); - childStubView->parentTag = parentTag; - parentStubView->children.insert( - parentStubView->children.begin() + mutation.index, childStubView); + if (!mutation.mutatedViewIsVirtual()) { + react_native_assert(mutation.oldChildShadowView == ShadowView{}); + auto parentTag = mutation.parentShadowView.tag; + react_native_assert(registry.find(parentTag) != registry.end()); + auto parentStubView = registry[parentTag]; + auto childTag = mutation.newChildShadowView.tag; + react_native_assert(registry.find(childTag) != registry.end()); + auto childStubView = registry[childTag]; + react_native_assert(childStubView->parentTag == NO_VIEW_TAG); + childStubView->update(mutation.newChildShadowView); + STUB_VIEW_LOG({ + LOG(ERROR) << "StubView: Insert [" << childTag << "] into [" + << parentTag << "] @" << mutation.index << "(" + << parentStubView->children.size() << " children)"; + }); + react_native_assert( + parentStubView->children.size() >= mutation.index); + childStubView->parentTag = parentTag; + parentStubView->children.insert( + parentStubView->children.begin() + mutation.index, childStubView); + } break; } case ShadowViewMutation::Remove: { - react_native_assert(mutation.newChildShadowView == ShadowView{}); - auto parentTag = mutation.parentShadowView.tag; - react_native_assert(registry.find(parentTag) != registry.end()); - auto parentStubView = registry[parentTag]; - auto childTag = mutation.oldChildShadowView.tag; - STUB_VIEW_LOG({ - LOG(ERROR) << "StubView: Remove [" << childTag << "] from [" - << parentTag << "] @" << mutation.index << " with " - << parentStubView->children.size() << " children"; - }); - react_native_assert(parentStubView->children.size() > mutation.index); - react_native_assert(registry.find(childTag) != registry.end()); - auto childStubView = registry[childTag]; - react_native_assert(childStubView->parentTag == parentTag); - STUB_VIEW_LOG({ - std::string strChildList = ""; - int i = 0; - for (auto const &child : parentStubView->children) { - strChildList.append(std::to_string(i)); - strChildList.append(":"); - strChildList.append(std::to_string(child->tag)); - strChildList.append(", "); - i++; - } - LOG(ERROR) << "StubView: BEFORE REMOVE: Children of " << parentTag - << ": " << strChildList; - }); - react_native_assert( - parentStubView->children.size() > mutation.index && - parentStubView->children[mutation.index]->tag == - childStubView->tag); - childStubView->parentTag = NO_VIEW_TAG; - parentStubView->children.erase( - parentStubView->children.begin() + mutation.index); + if (!mutation.mutatedViewIsVirtual()) { + react_native_assert(mutation.newChildShadowView == ShadowView{}); + auto parentTag = mutation.parentShadowView.tag; + react_native_assert(registry.find(parentTag) != registry.end()); + auto parentStubView = registry[parentTag]; + auto childTag = mutation.oldChildShadowView.tag; + STUB_VIEW_LOG({ + LOG(ERROR) << "StubView: Remove [" << childTag << "] from [" + << parentTag << "] @" << mutation.index << " with " + << parentStubView->children.size() << " children"; + }); + react_native_assert(parentStubView->children.size() > mutation.index); + react_native_assert(registry.find(childTag) != registry.end()); + auto childStubView = registry[childTag]; + react_native_assert(childStubView->parentTag == parentTag); + STUB_VIEW_LOG({ + std::string strChildList = ""; + int i = 0; + for (auto const &child : parentStubView->children) { + strChildList.append(std::to_string(i)); + strChildList.append(":"); + strChildList.append(std::to_string(child->tag)); + strChildList.append(", "); + i++; + } + LOG(ERROR) << "StubView: BEFORE REMOVE: Children of " << parentTag + << ": " << strChildList; + }); + react_native_assert( + parentStubView->children.size() > mutation.index && + parentStubView->children[mutation.index]->tag == + childStubView->tag); + childStubView->parentTag = NO_VIEW_TAG; + parentStubView->children.erase( + parentStubView->children.begin() + mutation.index); + } break; } diff --git a/ReactCommon/react/renderer/scheduler/Scheduler.cpp b/ReactCommon/react/renderer/scheduler/Scheduler.cpp index 4e4dd8f95db3c8..c5107c06a0bcc8 100644 --- a/ReactCommon/react/renderer/scheduler/Scheduler.cpp +++ b/ReactCommon/react/renderer/scheduler/Scheduler.cpp @@ -300,10 +300,11 @@ void Scheduler::uiManagerDidSendAccessibilityEvent( */ void Scheduler::uiManagerDidSetIsJSResponder( ShadowNode::Shared const &shadowNode, - bool isJSResponder) { + bool isJSResponder, + bool blockNativeResponder) { if (delegate_) { delegate_->schedulerDidSetIsJSResponder( - ShadowView(*shadowNode), isJSResponder); + ShadowView(*shadowNode), isJSResponder, blockNativeResponder); } } diff --git a/ReactCommon/react/renderer/scheduler/Scheduler.h b/ReactCommon/react/renderer/scheduler/Scheduler.h index a163a66a5e7472..03c8f65d2ea71a 100644 --- a/ReactCommon/react/renderer/scheduler/Scheduler.h +++ b/ReactCommon/react/renderer/scheduler/Scheduler.h @@ -94,7 +94,8 @@ class Scheduler final : public UIManagerDelegate { std::string const &eventType) override; void uiManagerDidSetIsJSResponder( ShadowNode::Shared const &shadowView, - bool isJSResponder) override; + bool isJSResponder, + bool blockNativeResponder) override; private: friend class SurfaceHandler; diff --git a/ReactCommon/react/renderer/scheduler/SchedulerDelegate.h b/ReactCommon/react/renderer/scheduler/SchedulerDelegate.h index 726e7ef937a90a..33e247c631ba32 100644 --- a/ReactCommon/react/renderer/scheduler/SchedulerDelegate.h +++ b/ReactCommon/react/renderer/scheduler/SchedulerDelegate.h @@ -50,7 +50,8 @@ class SchedulerDelegate { */ virtual void schedulerDidSetIsJSResponder( ShadowView const &shadowView, - bool isJSResponder) = 0; + bool isJSResponder, + bool blockNativeResponder) = 0; virtual ~SchedulerDelegate() noexcept = default; }; diff --git a/ReactCommon/react/renderer/uimanager/UIManager.cpp b/ReactCommon/react/renderer/uimanager/UIManager.cpp index 7fca1a5807b4c8..48f4cfaa1d30ff 100644 --- a/ReactCommon/react/renderer/uimanager/UIManager.cpp +++ b/ReactCommon/react/renderer/uimanager/UIManager.cpp @@ -115,9 +115,11 @@ void UIManager::completeSurface( void UIManager::setIsJSResponder( ShadowNode::Shared const &shadowNode, - bool isJSResponder) const { + bool isJSResponder, + bool blockNativeResponder) const { if (delegate_) { - delegate_->uiManagerDidSetIsJSResponder(shadowNode, isJSResponder); + delegate_->uiManagerDidSetIsJSResponder( + shadowNode, isJSResponder, blockNativeResponder); } } diff --git a/ReactCommon/react/renderer/uimanager/UIManager.h b/ReactCommon/react/renderer/uimanager/UIManager.h index 14250046ea006f..dac02a589b5c6c 100644 --- a/ReactCommon/react/renderer/uimanager/UIManager.h +++ b/ReactCommon/react/renderer/uimanager/UIManager.h @@ -131,7 +131,8 @@ class UIManager final : public ShadowTreeDelegate { void setIsJSResponder( ShadowNode::Shared const &shadowNode, - bool isJSResponder) const; + bool isJSResponder, + bool blockNativeResponder) const; ShadowNode::Shared findNodeAtPoint( ShadowNode::Shared const &shadowNode, diff --git a/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp b/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp index dec251ef14e39d..c6f3327bc44b8f 100644 --- a/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp +++ b/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp @@ -321,7 +321,8 @@ jsi::Value UIManagerBinding::get( size_t count) noexcept -> jsi::Value { uiManager->setIsJSResponder( shadowNodeFromValue(runtime, arguments[0]), - arguments[1].getBool()); + arguments[1].getBool(), + arguments[2].getBool()); return jsi::Value::undefined(); }); diff --git a/ReactCommon/react/renderer/uimanager/UIManagerDelegate.h b/ReactCommon/react/renderer/uimanager/UIManagerDelegate.h index 5e993056c42387..a99350fc3c66d8 100644 --- a/ReactCommon/react/renderer/uimanager/UIManagerDelegate.h +++ b/ReactCommon/react/renderer/uimanager/UIManagerDelegate.h @@ -56,7 +56,8 @@ class UIManagerDelegate { */ virtual void uiManagerDidSetIsJSResponder( ShadowNode::Shared const &shadowNode, - bool isJSResponder) = 0; + bool isJSResponder, + bool blockNativeResponder) = 0; virtual ~UIManagerDelegate() noexcept = default; }; diff --git a/ReactCommon/yoga/yoga/YGNode.cpp b/ReactCommon/yoga/yoga/YGNode.cpp index 1ee1bde626e8a6..f4c14bf3d8c9b8 100644 --- a/ReactCommon/yoga/yoga/YGNode.cpp +++ b/ReactCommon/yoga/yoga/YGNode.cpp @@ -50,89 +50,111 @@ void YGNode::print(void* printContext) { } } -YGFloatOptional YGNode::getLeadingPosition( - const YGFlexDirection axis, - const float axisSize) const { - if (YGFlexDirectionIsRow(axis)) { - auto leadingPosition = YGComputedEdgeValue( - style_.position(), YGEdgeStart, CompactValue::ofUndefined()); - if (!leadingPosition.isUndefined()) { - return YGResolveValue(leadingPosition, axisSize); - } +CompactValue YGNode::computeEdgeValueForRow( + const YGStyle::Edges& edges, + YGEdge rowEdge, + YGEdge edge, + CompactValue defaultValue) { + if (!edges[rowEdge].isUndefined()) { + return edges[rowEdge]; + } else if (!edges[edge].isUndefined()) { + return edges[edge]; + } else if (!edges[YGEdgeHorizontal].isUndefined()) { + return edges[YGEdgeHorizontal]; + } else if (!edges[YGEdgeAll].isUndefined()) { + return edges[YGEdgeAll]; + } else { + return defaultValue; } +} - auto leadingPosition = YGComputedEdgeValue( - style_.position(), leading[axis], CompactValue::ofUndefined()); +CompactValue YGNode::computeEdgeValueForColumn( + const YGStyle::Edges& edges, + YGEdge edge, + CompactValue defaultValue) { + if (!edges[edge].isUndefined()) { + return edges[edge]; + } else if (!edges[YGEdgeVertical].isUndefined()) { + return edges[YGEdgeVertical]; + } else if (!edges[YGEdgeAll].isUndefined()) { + return edges[YGEdgeAll]; + } else { + return defaultValue; + } +} - return leadingPosition.isUndefined() - ? YGFloatOptional{0} - : YGResolveValue(leadingPosition, axisSize); +YGFloatOptional YGNode::getLeadingPosition( + const YGFlexDirection axis, + const float axisSize) const { + auto leadingPosition = YGFlexDirectionIsRow(axis) + ? computeEdgeValueForRow( + style_.position(), + YGEdgeStart, + leading[axis], + CompactValue::ofZero()) + : computeEdgeValueForColumn( + style_.position(), leading[axis], CompactValue::ofZero()); + return YGResolveValue(leadingPosition, axisSize); } YGFloatOptional YGNode::getTrailingPosition( const YGFlexDirection axis, const float axisSize) const { - if (YGFlexDirectionIsRow(axis)) { - auto trailingPosition = YGComputedEdgeValue( - style_.position(), YGEdgeEnd, CompactValue::ofUndefined()); - if (!trailingPosition.isUndefined()) { - return YGResolveValue(trailingPosition, axisSize); - } - } - - auto trailingPosition = YGComputedEdgeValue( - style_.position(), trailing[axis], CompactValue::ofUndefined()); - - return trailingPosition.isUndefined() - ? YGFloatOptional{0} - : YGResolveValue(trailingPosition, axisSize); + auto trailingPosition = YGFlexDirectionIsRow(axis) + ? computeEdgeValueForRow( + style_.position(), + YGEdgeEnd, + trailing[axis], + CompactValue::ofZero()) + : computeEdgeValueForColumn( + style_.position(), trailing[axis], CompactValue::ofZero()); + return YGResolveValue(trailingPosition, axisSize); } bool YGNode::isLeadingPositionDefined(const YGFlexDirection axis) const { - return (YGFlexDirectionIsRow(axis) && - !YGComputedEdgeValue( - style_.position(), YGEdgeStart, CompactValue::ofUndefined()) - .isUndefined()) || - !YGComputedEdgeValue( - style_.position(), leading[axis], CompactValue::ofUndefined()) - .isUndefined(); + auto leadingPosition = YGFlexDirectionIsRow(axis) + ? computeEdgeValueForRow( + style_.position(), + YGEdgeStart, + leading[axis], + CompactValue::ofUndefined()) + : computeEdgeValueForColumn( + style_.position(), leading[axis], CompactValue::ofUndefined()); + return !leadingPosition.isUndefined(); } bool YGNode::isTrailingPosDefined(const YGFlexDirection axis) const { - return (YGFlexDirectionIsRow(axis) && - !YGComputedEdgeValue( - style_.position(), YGEdgeEnd, CompactValue::ofUndefined()) - .isUndefined()) || - !YGComputedEdgeValue( - style_.position(), trailing[axis], CompactValue::ofUndefined()) - .isUndefined(); + auto trailingPosition = YGFlexDirectionIsRow(axis) + ? computeEdgeValueForRow( + style_.position(), + YGEdgeEnd, + trailing[axis], + CompactValue::ofUndefined()) + : computeEdgeValueForColumn( + style_.position(), trailing[axis], CompactValue::ofUndefined()); + return !trailingPosition.isUndefined(); } YGFloatOptional YGNode::getLeadingMargin( const YGFlexDirection axis, const float widthSize) const { - if (YGFlexDirectionIsRow(axis) && - !style_.margin()[YGEdgeStart].isUndefined()) { - return YGResolveValueMargin(style_.margin()[YGEdgeStart], widthSize); - } - - return YGResolveValueMargin( - YGComputedEdgeValue( - style_.margin(), leading[axis], CompactValue::ofZero()), - widthSize); + auto leadingMargin = YGFlexDirectionIsRow(axis) + ? computeEdgeValueForRow( + style_.margin(), YGEdgeStart, leading[axis], CompactValue::ofZero()) + : computeEdgeValueForColumn( + style_.margin(), leading[axis], CompactValue::ofZero()); + return YGResolveValueMargin(leadingMargin, widthSize); } YGFloatOptional YGNode::getTrailingMargin( const YGFlexDirection axis, const float widthSize) const { - if (YGFlexDirectionIsRow(axis) && !style_.margin()[YGEdgeEnd].isUndefined()) { - return YGResolveValueMargin(style_.margin()[YGEdgeEnd], widthSize); - } - - return YGResolveValueMargin( - YGComputedEdgeValue( - style_.margin(), trailing[axis], CompactValue::ofZero()), - widthSize); + auto trailingMargin = YGFlexDirectionIsRow(axis) + ? computeEdgeValueForRow( + style_.margin(), YGEdgeEnd, trailing[axis], CompactValue::ofZero()) + : computeEdgeValueForColumn( + style_.margin(), trailing[axis], CompactValue::ofZero()); + return YGResolveValueMargin(trailingMargin, widthSize); } YGFloatOptional YGNode::getMarginForAxis( @@ -147,7 +169,6 @@ YGSize YGNode::measure( float height, YGMeasureMode heightMode, void* layoutContext) { - return facebook::yoga::detail::getBooleanData(flags, measureUsesContext_) ? measure_.withContext( this, width, widthMode, height, heightMode, layoutContext) @@ -448,68 +469,48 @@ bool YGNode::isNodeFlexible() { } float YGNode::getLeadingBorder(const YGFlexDirection axis) const { - YGValue leadingBorder; - if (YGFlexDirectionIsRow(axis) && - !style_.border()[YGEdgeStart].isUndefined()) { - leadingBorder = style_.border()[YGEdgeStart]; - if (leadingBorder.value >= 0) { - return leadingBorder.value; - } - } - - leadingBorder = YGComputedEdgeValue( - style_.border(), leading[axis], CompactValue::ofZero()); - return YGFloatMax(leadingBorder.value, 0.0f); + YGValue leadingBorder = YGFlexDirectionIsRow(axis) + ? computeEdgeValueForRow( + style_.border(), YGEdgeStart, leading[axis], CompactValue::ofZero()) + : computeEdgeValueForColumn( + style_.border(), leading[axis], CompactValue::ofZero()); + return fmaxf(leadingBorder.value, 0.0f); } -float YGNode::getTrailingBorder(const YGFlexDirection flexDirection) const { - YGValue trailingBorder; - if (YGFlexDirectionIsRow(flexDirection) && - !style_.border()[YGEdgeEnd].isUndefined()) { - trailingBorder = style_.border()[YGEdgeEnd]; - if (trailingBorder.value >= 0.0f) { - return trailingBorder.value; - } - } - - trailingBorder = YGComputedEdgeValue( - style_.border(), trailing[flexDirection], CompactValue::ofZero()); - return YGFloatMax(trailingBorder.value, 0.0f); +float YGNode::getTrailingBorder(const YGFlexDirection axis) const { + YGValue trailingBorder = YGFlexDirectionIsRow(axis) + ? computeEdgeValueForRow( + style_.border(), YGEdgeEnd, trailing[axis], CompactValue::ofZero()) + : computeEdgeValueForColumn( + style_.border(), trailing[axis], CompactValue::ofZero()); + return fmaxf(trailingBorder.value, 0.0f); } YGFloatOptional YGNode::getLeadingPadding( const YGFlexDirection axis, const float widthSize) const { - const YGFloatOptional paddingEdgeStart = - YGResolveValue(style_.padding()[YGEdgeStart], widthSize); - if (YGFlexDirectionIsRow(axis) && - !style_.padding()[YGEdgeStart].isUndefined() && - !paddingEdgeStart.isUndefined() && paddingEdgeStart.unwrap() >= 0.0f) { - return paddingEdgeStart; - } - - YGFloatOptional resolvedValue = YGResolveValue( - YGComputedEdgeValue( - style_.padding(), leading[axis], CompactValue::ofZero()), - widthSize); - return YGFloatOptionalMax(resolvedValue, YGFloatOptional(0.0f)); + auto leadingPadding = YGFlexDirectionIsRow(axis) + ? computeEdgeValueForRow( + style_.padding(), + YGEdgeStart, + leading[axis], + CompactValue::ofZero()) + : computeEdgeValueForColumn( + style_.padding(), leading[axis], CompactValue::ofZero()); + return YGFloatOptionalMax( + YGResolveValue(leadingPadding, widthSize), YGFloatOptional(0.0f)); } YGFloatOptional YGNode::getTrailingPadding( const YGFlexDirection axis, const float widthSize) const { - const YGFloatOptional paddingEdgeEnd = - YGResolveValue(style_.padding()[YGEdgeEnd], widthSize); - if (YGFlexDirectionIsRow(axis) && paddingEdgeEnd >= YGFloatOptional{0.0f}) { - return paddingEdgeEnd; - } - - YGFloatOptional resolvedValue = YGResolveValue( - YGComputedEdgeValue( - style_.padding(), trailing[axis], CompactValue::ofZero()), - widthSize); - - return YGFloatOptionalMax(resolvedValue, YGFloatOptional(0.0f)); + auto trailingPadding = YGFlexDirectionIsRow(axis) + ? computeEdgeValueForRow( + style_.padding(), YGEdgeEnd, trailing[axis], CompactValue::ofZero()) + : computeEdgeValueForColumn( + style_.padding(), trailing[axis], CompactValue::ofZero()); + return YGFloatOptionalMax( + YGResolveValue(trailingPadding, widthSize), YGFloatOptional(0.0f)); } YGFloatOptional YGNode::getLeadingPaddingAndBorder( diff --git a/ReactCommon/yoga/yoga/YGNode.h b/ReactCommon/yoga/yoga/YGNode.h index 63d98fe3a1a816..4b6e6277af8aa7 100644 --- a/ReactCommon/yoga/yoga/YGNode.h +++ b/ReactCommon/yoga/yoga/YGNode.h @@ -193,6 +193,17 @@ struct YOGA_EXPORT YGNode { return resolvedDimensions_[index]; } + static CompactValue computeEdgeValueForColumn( + const YGStyle::Edges& edges, + YGEdge edge, + CompactValue defaultValue); + + static CompactValue computeEdgeValueForRow( + const YGStyle::Edges& edges, + YGEdge rowEdge, + YGEdge edge, + CompactValue defaultValue); + // Methods related to positions, margin, padding and border YGFloatOptional getLeadingPosition( const YGFlexDirection axis, diff --git a/ReactCommon/yoga/yoga/YGNodePrint.cpp b/ReactCommon/yoga/yoga/YGNodePrint.cpp index 26efa4858b6885..72d147dbb7b29f 100644 --- a/ReactCommon/yoga/yoga/YGNodePrint.cpp +++ b/ReactCommon/yoga/yoga/YGNodePrint.cpp @@ -104,10 +104,13 @@ static void appendEdgeIfNotUndefined( const string& str, const YGStyle::Edges& edges, const YGEdge edge) { - appendNumberIfNotUndefined( - base, - str, - YGComputedEdgeValue(edges, edge, detail::CompactValue::ofUndefined())); + // TODO: this doesn't take RTL / YGEdgeStart / YGEdgeEnd into account + auto value = (edge == YGEdgeLeft || edge == YGEdgeRight) + ? YGNode::computeEdgeValueForRow( + edges, edge, edge, detail::CompactValue::ofUndefined()) + : YGNode::computeEdgeValueForColumn( + edges, edge, detail::CompactValue::ofUndefined()); + appendNumberIfNotUndefined(base, str, value); } void YGNodeToString( diff --git a/ReactCommon/yoga/yoga/Yoga-internal.h b/ReactCommon/yoga/yoga/Yoga-internal.h index 1a22f24c9c147b..b671f177f02bbe 100644 --- a/ReactCommon/yoga/yoga/Yoga-internal.h +++ b/ReactCommon/yoga/yoga/Yoga-internal.h @@ -144,8 +144,3 @@ static const float kDefaultFlexShrink = 0.0f; static const float kWebDefaultFlexShrink = 1.0f; extern bool YGFloatsEqual(const float a, const float b); -extern facebook::yoga::detail::CompactValue YGComputedEdgeValue( - const facebook::yoga::detail::Values< - facebook::yoga::enums::count()>& edges, - YGEdge edge, - facebook::yoga::detail::CompactValue defaultValue); diff --git a/ReactCommon/yoga/yoga/Yoga.cpp b/ReactCommon/yoga/yoga/Yoga.cpp index f24563df6174a6..9553366ecadf84 100644 --- a/ReactCommon/yoga/yoga/Yoga.cpp +++ b/ReactCommon/yoga/yoga/Yoga.cpp @@ -110,36 +110,6 @@ YOGA_EXPORT bool YGFloatIsUndefined(const float value) { return facebook::yoga::isUndefined(value); } -detail::CompactValue YGComputedEdgeValue( - const YGStyle::Edges& edges, - YGEdge edge, - detail::CompactValue defaultValue) { - if (!edges[edge].isUndefined()) { - return edges[edge]; - } - - if ((edge == YGEdgeTop || edge == YGEdgeBottom) && - !edges[YGEdgeVertical].isUndefined()) { - return edges[YGEdgeVertical]; - } - - if ((edge == YGEdgeLeft || edge == YGEdgeRight || edge == YGEdgeStart || - edge == YGEdgeEnd) && - !edges[YGEdgeHorizontal].isUndefined()) { - return edges[YGEdgeHorizontal]; - } - - if (!edges[YGEdgeAll].isUndefined()) { - return edges[YGEdgeAll]; - } - - if (edge == YGEdgeStart || edge == YGEdgeEnd) { - return detail::CompactValue::ofUndefined(); - } - - return defaultValue; -} - YOGA_EXPORT void* YGNodeGetContext(YGNodeRef node) { return node->getContext(); } @@ -1681,40 +1651,33 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions( availableHeight = YGUndefined; } - const float paddingAndBorderAxisRow = - YGNodePaddingAndBorderForAxis(node, YGFlexDirectionRow, ownerWidth); - const float paddingAndBorderAxisColumn = - YGNodePaddingAndBorderForAxis(node, YGFlexDirectionColumn, ownerWidth); - const float marginAxisRow = - node->getMarginForAxis(YGFlexDirectionRow, ownerWidth).unwrap(); - const float marginAxisColumn = - node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth).unwrap(); + const auto& padding = node->getLayout().padding; + const auto& border = node->getLayout().border; + const float paddingAndBorderAxisRow = padding[YGEdgeLeft] + + padding[YGEdgeRight] + border[YGEdgeLeft] + border[YGEdgeRight]; + const float paddingAndBorderAxisColumn = padding[YGEdgeTop] + + padding[YGEdgeBottom] + border[YGEdgeTop] + border[YGEdgeBottom]; // We want to make sure we don't call measure with negative size const float innerWidth = YGFloatIsUndefined(availableWidth) ? availableWidth - : YGFloatMax(0, availableWidth - marginAxisRow - paddingAndBorderAxisRow); + : YGFloatMax(0, availableWidth - paddingAndBorderAxisRow); const float innerHeight = YGFloatIsUndefined(availableHeight) ? availableHeight - : YGFloatMax( - 0, availableHeight - marginAxisColumn - paddingAndBorderAxisColumn); + : YGFloatMax(0, availableHeight - paddingAndBorderAxisColumn); if (widthMeasureMode == YGMeasureModeExactly && heightMeasureMode == YGMeasureModeExactly) { // Don't bother sizing the text if both dimensions are already defined. node->setLayoutMeasuredDimension( YGNodeBoundAxis( - node, - YGFlexDirectionRow, - availableWidth - marginAxisRow, - ownerWidth, - ownerWidth), + node, YGFlexDirectionRow, availableWidth, ownerWidth, ownerWidth), YGDimensionWidth); node->setLayoutMeasuredDimension( YGNodeBoundAxis( node, YGFlexDirectionColumn, - availableHeight - marginAxisColumn, + availableHeight, ownerHeight, ownerWidth), YGDimensionHeight); @@ -1751,7 +1714,7 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions( (widthMeasureMode == YGMeasureModeUndefined || widthMeasureMode == YGMeasureModeAtMost) ? measuredSize.width + paddingAndBorderAxisRow - : availableWidth - marginAxisRow, + : availableWidth, ownerWidth, ownerWidth), YGDimensionWidth); @@ -1763,7 +1726,7 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions( (heightMeasureMode == YGMeasureModeUndefined || heightMeasureMode == YGMeasureModeAtMost) ? measuredSize.height + paddingAndBorderAxisColumn - : availableHeight - marginAxisColumn, + : availableHeight, ownerHeight, ownerWidth), YGDimensionHeight); @@ -1780,37 +1743,28 @@ static void YGNodeEmptyContainerSetMeasuredDimensions( const YGMeasureMode heightMeasureMode, const float ownerWidth, const float ownerHeight) { - const float paddingAndBorderAxisRow = - YGNodePaddingAndBorderForAxis(node, YGFlexDirectionRow, ownerWidth); - const float paddingAndBorderAxisColumn = - YGNodePaddingAndBorderForAxis(node, YGFlexDirectionColumn, ownerWidth); - const float marginAxisRow = - node->getMarginForAxis(YGFlexDirectionRow, ownerWidth).unwrap(); - const float marginAxisColumn = - node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth).unwrap(); - + const auto& padding = node->getLayout().padding; + const auto& border = node->getLayout().border; + + float width = availableWidth; + if (widthMeasureMode == YGMeasureModeUndefined || + widthMeasureMode == YGMeasureModeAtMost) { + width = padding[YGEdgeLeft] + padding[YGEdgeRight] + border[YGEdgeLeft] + + border[YGEdgeRight]; + } node->setLayoutMeasuredDimension( - YGNodeBoundAxis( - node, - YGFlexDirectionRow, - (widthMeasureMode == YGMeasureModeUndefined || - widthMeasureMode == YGMeasureModeAtMost) - ? paddingAndBorderAxisRow - : availableWidth - marginAxisRow, - ownerWidth, - ownerWidth), + YGNodeBoundAxis(node, YGFlexDirectionRow, width, ownerWidth, ownerWidth), YGDimensionWidth); + float height = availableHeight; + if (heightMeasureMode == YGMeasureModeUndefined || + heightMeasureMode == YGMeasureModeAtMost) { + height = padding[YGEdgeTop] + padding[YGEdgeBottom] + border[YGEdgeTop] + + border[YGEdgeBottom]; + } node->setLayoutMeasuredDimension( YGNodeBoundAxis( - node, - YGFlexDirectionColumn, - (heightMeasureMode == YGMeasureModeUndefined || - heightMeasureMode == YGMeasureModeAtMost) - ? paddingAndBorderAxisColumn - : availableHeight - marginAxisColumn, - ownerHeight, - ownerWidth), + node, YGFlexDirectionColumn, height, ownerHeight, ownerWidth), YGDimensionHeight); } @@ -1828,11 +1782,6 @@ static bool YGNodeFixedSizeSetMeasuredDimensions( heightMeasureMode == YGMeasureModeAtMost && availableHeight <= 0.0f) || (widthMeasureMode == YGMeasureModeExactly && heightMeasureMode == YGMeasureModeExactly)) { - auto marginAxisColumn = - node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth).unwrap(); - auto marginAxisRow = - node->getMarginForAxis(YGFlexDirectionRow, ownerWidth).unwrap(); - node->setLayoutMeasuredDimension( YGNodeBoundAxis( node, @@ -1841,7 +1790,7 @@ static bool YGNodeFixedSizeSetMeasuredDimensions( (widthMeasureMode == YGMeasureModeAtMost && availableWidth < 0.0f) ? 0.0f - : availableWidth - marginAxisRow, + : availableWidth, ownerWidth, ownerWidth), YGDimensionWidth); @@ -1854,7 +1803,7 @@ static bool YGNodeFixedSizeSetMeasuredDimensions( (heightMeasureMode == YGMeasureModeAtMost && availableHeight < 0.0f) ? 0.0f - : availableHeight - marginAxisColumn, + : availableHeight, ownerHeight, ownerWidth), YGDimensionHeight); @@ -1878,21 +1827,11 @@ static void YGZeroOutLayoutRecursivly( static float YGNodeCalculateAvailableInnerDim( const YGNodeConstRef node, - YGFlexDirection axis, - float availableDim, - float ownerDim, - float ownerDimForMarginPadding) { - YGFlexDirection direction = - YGFlexDirectionIsRow(axis) ? YGFlexDirectionRow : YGFlexDirectionColumn; - YGDimension dimension = - YGFlexDirectionIsRow(axis) ? YGDimensionWidth : YGDimensionHeight; - - const float margin = - node->getMarginForAxis(direction, ownerDimForMarginPadding).unwrap(); - const float paddingAndBorder = - YGNodePaddingAndBorderForAxis(node, direction, ownerDimForMarginPadding); - - float availableInnerDim = availableDim - margin - paddingAndBorder; + const YGDimension dimension, + const float availableDim, + const float paddingAndBorder, + const float ownerDim) { + float availableInnerDim = availableDim - paddingAndBorder; // Max dimension overrides predefined dimension value; Min dimension in turn // overrides both of the above if (!YGFloatIsUndefined(availableInnerDim)) { @@ -2779,16 +2718,22 @@ static void YGNodelayoutImpl( const YGEdge startEdge = direction == YGDirectionLTR ? YGEdgeLeft : YGEdgeRight; const YGEdge endEdge = direction == YGDirectionLTR ? YGEdgeRight : YGEdgeLeft; - node->setLayoutMargin( - node->getLeadingMargin(flexRowDirection, ownerWidth).unwrap(), startEdge); - node->setLayoutMargin( - node->getTrailingMargin(flexRowDirection, ownerWidth).unwrap(), endEdge); - node->setLayoutMargin( - node->getLeadingMargin(flexColumnDirection, ownerWidth).unwrap(), - YGEdgeTop); - node->setLayoutMargin( - node->getTrailingMargin(flexColumnDirection, ownerWidth).unwrap(), - YGEdgeBottom); + + const float marginRowLeading = + node->getLeadingMargin(flexRowDirection, ownerWidth).unwrap(); + node->setLayoutMargin(marginRowLeading, startEdge); + const float marginRowTrailing = + node->getTrailingMargin(flexRowDirection, ownerWidth).unwrap(); + node->setLayoutMargin(marginRowTrailing, endEdge); + const float marginColumnLeading = + node->getLeadingMargin(flexColumnDirection, ownerWidth).unwrap(); + node->setLayoutMargin(marginColumnLeading, YGEdgeTop); + const float marginColumnTrailing = + node->getTrailingMargin(flexColumnDirection, ownerWidth).unwrap(); + node->setLayoutMargin(marginColumnTrailing, YGEdgeBottom); + + const float marginAxisRow = marginRowLeading + marginRowTrailing; + const float marginAxisColumn = marginColumnLeading + marginColumnTrailing; node->setLayoutBorder(node->getLeadingBorder(flexRowDirection), startEdge); node->setLayoutBorder(node->getTrailingBorder(flexRowDirection), endEdge); @@ -2811,8 +2756,8 @@ static void YGNodelayoutImpl( if (node->hasMeasureFunc()) { YGNodeWithMeasureFuncSetMeasuredDimensions( node, - availableWidth, - availableHeight, + availableWidth - marginAxisRow, + availableHeight - marginAxisColumn, widthMeasureMode, heightMeasureMode, ownerWidth, @@ -2827,8 +2772,8 @@ static void YGNodelayoutImpl( if (childCount == 0) { YGNodeEmptyContainerSetMeasuredDimensions( node, - availableWidth, - availableHeight, + availableWidth - marginAxisRow, + availableHeight - marginAxisColumn, widthMeasureMode, heightMeasureMode, ownerWidth, @@ -2841,8 +2786,8 @@ static void YGNodelayoutImpl( if (!performLayout && YGNodeFixedSizeSetMeasuredDimensions( node, - availableWidth, - availableHeight, + availableWidth - marginAxisRow, + availableHeight - marginAxisColumn, widthMeasureMode, heightMeasureMode, ownerWidth, @@ -2866,12 +2811,14 @@ static void YGNodelayoutImpl( const float mainAxisownerSize = isMainAxisRow ? ownerWidth : ownerHeight; const float crossAxisownerSize = isMainAxisRow ? ownerHeight : ownerWidth; - const float leadingPaddingAndBorderCross = - node->getLeadingPaddingAndBorder(crossAxis, ownerWidth).unwrap(); const float paddingAndBorderAxisMain = YGNodePaddingAndBorderForAxis(node, mainAxis, ownerWidth); + const float leadingPaddingAndBorderCross = + node->getLeadingPaddingAndBorder(crossAxis, ownerWidth).unwrap(); + const float trailingPaddingAndBorderCross = + node->getTrailingPaddingAndBorder(crossAxis, ownerWidth).unwrap(); const float paddingAndBorderAxisCross = - YGNodePaddingAndBorderForAxis(node, crossAxis, ownerWidth); + leadingPaddingAndBorderCross + trailingPaddingAndBorderCross; YGMeasureMode measureModeMainDim = isMainAxisRow ? widthMeasureMode : heightMeasureMode; @@ -2883,35 +2830,20 @@ static void YGNodelayoutImpl( const float paddingAndBorderAxisColumn = isMainAxisRow ? paddingAndBorderAxisCross : paddingAndBorderAxisMain; - const float marginAxisRow = - node->getMarginForAxis(YGFlexDirectionRow, ownerWidth).unwrap(); - const float marginAxisColumn = - node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth).unwrap(); - - const auto& minDimensions = node->getStyle().minDimensions(); - const auto& maxDimensions = node->getStyle().maxDimensions(); - const float minInnerWidth = - YGResolveValue(minDimensions[YGDimensionWidth], ownerWidth).unwrap() - - paddingAndBorderAxisRow; - const float maxInnerWidth = - YGResolveValue(maxDimensions[YGDimensionWidth], ownerWidth).unwrap() - - paddingAndBorderAxisRow; - const float minInnerHeight = - YGResolveValue(minDimensions[YGDimensionHeight], ownerHeight).unwrap() - - paddingAndBorderAxisColumn; - const float maxInnerHeight = - YGResolveValue(maxDimensions[YGDimensionHeight], ownerHeight).unwrap() - - paddingAndBorderAxisColumn; - - const float minInnerMainDim = isMainAxisRow ? minInnerWidth : minInnerHeight; - const float maxInnerMainDim = isMainAxisRow ? maxInnerWidth : maxInnerHeight; - // STEP 2: DETERMINE AVAILABLE SIZE IN MAIN AND CROSS DIRECTIONS float availableInnerWidth = YGNodeCalculateAvailableInnerDim( - node, YGFlexDirectionRow, availableWidth, ownerWidth, ownerWidth); + node, + YGDimensionWidth, + availableWidth - marginAxisRow, + paddingAndBorderAxisRow, + ownerWidth); float availableInnerHeight = YGNodeCalculateAvailableInnerDim( - node, YGFlexDirectionColumn, availableHeight, ownerHeight, ownerWidth); + node, + YGDimensionHeight, + availableHeight - marginAxisColumn, + paddingAndBorderAxisColumn, + ownerHeight); float availableInnerMainDim = isMainAxisRow ? availableInnerWidth : availableInnerHeight; @@ -2983,6 +2915,28 @@ static void YGNodelayoutImpl( // If we don't measure with exact main dimension we want to ensure we don't // violate min and max if (measureModeMainDim != YGMeasureModeExactly) { + const auto& minDimensions = node->getStyle().minDimensions(); + const auto& maxDimensions = node->getStyle().maxDimensions(); + const float minInnerWidth = + YGResolveValue(minDimensions[YGDimensionWidth], ownerWidth).unwrap() - + paddingAndBorderAxisRow; + const float maxInnerWidth = + YGResolveValue(maxDimensions[YGDimensionWidth], ownerWidth).unwrap() - + paddingAndBorderAxisRow; + const float minInnerHeight = + YGResolveValue(minDimensions[YGDimensionHeight], ownerHeight) + .unwrap() - + paddingAndBorderAxisColumn; + const float maxInnerHeight = + YGResolveValue(maxDimensions[YGDimensionHeight], ownerHeight) + .unwrap() - + paddingAndBorderAxisColumn; + + const float minInnerMainDim = + isMainAxisRow ? minInnerWidth : minInnerHeight; + const float maxInnerMainDim = + isMainAxisRow ? maxInnerWidth : maxInnerHeight; + if (!YGFloatIsUndefined(minInnerMainDim) && collectedFlexItemsValues.sizeConsumedOnCurrentLine < minInnerMainDim) { diff --git a/ReactCommon/yoga/yoga/Yoga.h b/ReactCommon/yoga/yoga/Yoga.h index 87901a280ee84a..86cd65e2f08f07 100644 --- a/ReactCommon/yoga/yoga/Yoga.h +++ b/ReactCommon/yoga/yoga/Yoga.h @@ -107,7 +107,7 @@ WIN_EXPORT void YGNodeMarkDirty(YGNodeRef node); // Marks the current node and all its descendants as dirty. // -// Intended to be used for Uoga benchmarks. Don't use in production, as calling +// Intended to be used for Yoga benchmarks. Don't use in production, as calling // `YGCalculateLayout` will cause the recalculation of each and every node. WIN_EXPORT void YGNodeMarkDirtyAndPropogateToDescendants(YGNodeRef node); diff --git a/packages/rn-tester/js/examples/Animated/AnimatedExample.js b/packages/rn-tester/js/examples/Animated/AnimatedExample.js index 154bc406a4b92e..e8e64ac518f2b1 100644 --- a/packages/rn-tester/js/examples/Animated/AnimatedExample.js +++ b/packages/rn-tester/js/examples/Animated/AnimatedExample.js @@ -12,14 +12,7 @@ const RNTesterButton = require('../../components/RNTesterButton'); const React = require('react'); -const { - Animated, - Easing, - Pressable, - StyleSheet, - Text, - View, -} = require('react-native'); +const {Animated, Easing, StyleSheet, Text, View} = require('react-native'); import type {RNTesterExampleModuleItem} from '../../types/RNTesterTypes'; @@ -90,17 +83,11 @@ exports.examples = ([ } type Props = $ReadOnly<{||}>; - type State = {| - disabled: boolean, - pressCount: number, - show: boolean, - |}; + type State = {|show: boolean|}; class FadeInExample extends React.Component { constructor(props: Props) { super(props); this.state = { - disabled: true, - pressCount: 0, show: true, }; } @@ -110,35 +97,15 @@ exports.examples = ([ { - this.setState(state => ({pressCount: 0, show: !state.show})); + this.setState(state => ({show: !state.show})); }}> Press to {this.state.show ? 'Hide' : 'Show'} - { - this.setState(state => ({disabled: !state.disabled})); - }}> - Press to {this.state.disabled ? 'Enable' : 'Disable'} - {this.state.show && ( - { - this.setState(state => ({ - pressCount: this.state.pressCount + 1, - })); - }}> - - FadeInView - {this.state.disabled - ? '' - : ` Pressable: ${this.state.pressCount}`} - - + + FadeInView + )}