diff --git a/packages/react-native/ReactCommon/react/nativemodule/intersectionobserver/NativeIntersectionObserver.cpp b/packages/react-native/ReactCommon/react/nativemodule/intersectionobserver/NativeIntersectionObserver.cpp index 0db0734e202d..9e3fedd7d15c 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/intersectionobserver/NativeIntersectionObserver.cpp +++ b/packages/react-native/ReactCommon/react/nativemodule/intersectionobserver/NativeIntersectionObserver.cpp @@ -63,6 +63,7 @@ jsi::Object NativeIntersectionObserver::observeV2( auto thresholds = options.thresholds; auto rootThresholds = options.rootThresholds; auto rootMargin = options.rootMargin; + auto scrollMargin = options.scrollMargin; auto& uiManager = getUIManagerFromRuntime(runtime); intersectionObserverManager_.observe( @@ -72,6 +73,7 @@ jsi::Object NativeIntersectionObserver::observeV2( thresholds, rootThresholds, rootMargin, + scrollMargin, uiManager); return tokenFromShadowNodeFamily(runtime, shadowNodeFamily); diff --git a/packages/react-native/ReactCommon/react/nativemodule/intersectionobserver/NativeIntersectionObserver.h b/packages/react-native/ReactCommon/react/nativemodule/intersectionobserver/NativeIntersectionObserver.h index 17b5ddd9eabe..5df586498ac1 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/intersectionobserver/NativeIntersectionObserver.h +++ b/packages/react-native/ReactCommon/react/nativemodule/intersectionobserver/NativeIntersectionObserver.h @@ -37,6 +37,8 @@ using NativeIntersectionObserverObserveOptions = NativeIntersectionObserverNativ // rootThresholds std::optional>, // rootMargin + std::optional, + // scrollMargin std::optional>; template <> diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp b/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp index 6f3e3b2682b4..69a3bed4168a 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp @@ -178,6 +178,23 @@ bool YogaLayoutableShadowNode::getIsLayoutClean() const { return !YGNodeIsDirty(&yogaNode_); } +bool YogaLayoutableShadowNode::hasContentClip() const { + return YGNodeStyleGetOverflow(&yogaNode_) != YGOverflowVisible; +} + +bool YogaLayoutableShadowNode::isScrollContainer() const { + // No `default`, so new `overflow` values must be classified explicitly + // (-Wswitch). + switch (YGNodeStyleGetOverflow(&yogaNode_)) { + case YGOverflowHidden: + case YGOverflowScroll: + return true; + case YGOverflowVisible: + return false; + } + return false; +} + #pragma mark - Mutating Methods void YogaLayoutableShadowNode::enableMeasurement() { diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.h b/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.h index 60a5f15f5b30..f6a22a1950bd 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.h +++ b/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.h @@ -79,6 +79,10 @@ class YogaLayoutableShadowNode : public LayoutableShadowNode { void dirtyLayout() override; bool getIsLayoutClean() const override; + bool hasContentClip() const override; + + bool isScrollContainer() const override; + /* * Computes layout using Yoga layout engine. * See `LayoutableShadowNode` for more details. diff --git a/packages/react-native/ReactCommon/react/renderer/core/LayoutableShadowNode.cpp b/packages/react-native/ReactCommon/react/renderer/core/LayoutableShadowNode.cpp index 4892fa75ec68..5ca1da204293 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/LayoutableShadowNode.cpp +++ b/packages/react-native/ReactCommon/react/renderer/core/LayoutableShadowNode.cpp @@ -181,11 +181,21 @@ LayoutMetrics LayoutableShadowNode::computeRelativeLayoutMetrics( resultFrame.origin += currentShadowNode->getContentOriginOffset(true); } + // Only nodes with a content clip clip their content. Clipping + // `overflow: visible` nodes to their content bounds would cut off content + // that a dilated (clipMargin) scroll container below them has revealed. if (policy.enableOverflowClipping && - (i != size - 1 || policy.clipSpecifiedAncestor)) { - auto overflowInset = currentShadowNode->getLayoutMetrics().overflowInset; - auto overflowRect = insetBy( - currentFrame * currentShadowNode->getTransform(), overflowInset); + (i != size - 1 || policy.clipSpecifiedAncestor) && + currentShadowNode->hasContentClip()) { + auto overflowRect = currentFrame * currentShadowNode->getTransform(); + // Only scroll containers are dilated, and the measured node is not its + // own container, so its clip is never dilated. + if (policy.clipMargin.has_value() && i != 0 && + currentShadowNode->isScrollContainer()) { + overflowRect = outsetBy( + overflowRect, + resolveEdgeMargins(*policy.clipMargin, overflowRect.size)); + } resultFrame = Rect::intersect(resultFrame, overflowRect); if (resultFrame.size.width == 0 && resultFrame.size.height == 0) { return EmptyLayoutMetrics; @@ -224,6 +234,14 @@ Point LayoutableShadowNode::getContentOriginOffset( return {.x = 0, .y = 0}; } +bool LayoutableShadowNode::hasContentClip() const { + return false; +} + +bool LayoutableShadowNode::isScrollContainer() const { + return false; +} + bool LayoutableShadowNode::canBeTouchTarget() const { return false; } diff --git a/packages/react-native/ReactCommon/react/renderer/core/LayoutableShadowNode.h b/packages/react-native/ReactCommon/react/renderer/core/LayoutableShadowNode.h index 2fdf36483d89..84908dc387ef 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/LayoutableShadowNode.h +++ b/packages/react-native/ReactCommon/react/renderer/core/LayoutableShadowNode.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -42,12 +43,19 @@ class LayoutableShadowNode : public ShadowNode { struct LayoutInspectingPolicy { bool includeTransform{true}; bool includeViewportOffset{false}; + // Clip against every node with a content clip (see hasContentClip) on the + // way up from the measured node. bool enableOverflowClipping{false}; // When enableOverflowClipping is true, also clip against the ancestor // passed as the reference node. IntersectionObserver sets this false: // the spec clips ancestors *until* the root, then intersects with the // rootMargin-expanded root intersection rectangle. bool clipSpecifiedAncestor{true}; + // When enableOverflowClipping is true, expand the clip rect of every + // scroll container ancestor (see isScrollContainer) by these margins + // before clipping (not the measured node's own clip). Percentages resolve + // against each clip rect. This is IntersectionObserver's `scrollMargin`. + std::optional clipMargin{}; }; using UnsharedList = std::vector; @@ -140,6 +148,21 @@ class LayoutableShadowNode : public ShadowNode { */ virtual Point getContentOriginOffset(bool includeTransform) const; + /* + * Whether the node clips its content to its bounds (CSS "content clip"), + * e.g. `overflow` other than `visible`. + * Default implementation returns `false`. + */ + virtual bool hasContentClip() const; + + /* + * Whether the node is a scroll container in the CSS sense (`overflow: + * hidden` or `scroll`). Every scroll container has a content clip, but not + * every content clip is a scroll container (e.g. CSS `overflow: clip`). + * Default implementation returns `false`. + */ + virtual bool isScrollContainer() const; + /* * Sets layout metrics for the shadow node. */ diff --git a/packages/react-native/ReactCommon/react/renderer/graphics/RectangleEdges.h b/packages/react-native/ReactCommon/react/renderer/graphics/RectangleEdges.h index 7d55d84d2d24..e555a3a1f262 100644 --- a/packages/react-native/ReactCommon/react/renderer/graphics/RectangleEdges.h +++ b/packages/react-native/ReactCommon/react/renderer/graphics/RectangleEdges.h @@ -82,6 +82,40 @@ inline Rect outsetBy(const Rect &rect, const EdgeInsets &outsets) noexcept .height = rect.size.height + outsets.top + outsets.bottom}}; } +/* + * A margin value that is either an absolute length in points or a percentage + * of the size it is resolved against. + */ +struct MarginValue { + Float value{}; + bool isPercentage{false}; + + bool operator==(const MarginValue &rhs) const noexcept = default; +}; + +/* + * EdgeMargins + */ +using EdgeMargins = RectangleEdges; + +/* + * Resolves margins into absolute insets against the given size. + * Percentages on the vertical edges resolve against the height, and those on + * the horizontal edges resolve against the width. + */ +inline EdgeInsets resolveEdgeMargins(const EdgeMargins &margins, const Size &size) noexcept +{ + const auto resolve = [](const MarginValue &margin, Float basis) { + return margin.isPercentage ? margin.value / 100.0f * basis : margin.value; + }; + + return EdgeInsets{ + resolve(margins.left, size.width), + resolve(margins.top, size.height), + resolve(margins.right, size.width), + resolve(margins.bottom, size.height)}; +} + } // namespace facebook::react namespace std { diff --git a/packages/react-native/ReactCommon/react/renderer/observers/intersection/IntersectionObserver.cpp b/packages/react-native/ReactCommon/react/renderer/observers/intersection/IntersectionObserver.cpp index 325f0b6692ee..3bb371f2103c 100644 --- a/packages/react-native/ReactCommon/react/renderer/observers/intersection/IntersectionObserver.cpp +++ b/packages/react-native/ReactCommon/react/renderer/observers/intersection/IntersectionObserver.cpp @@ -18,16 +18,14 @@ namespace facebook::react { -// Parse a normalized rootMargin string that's always in the format: +// Parse a normalized margin string that's always in the format: // "top right bottom left" where each value is either "Npx" or "N%" // The string is already validated and normalized by JS. -// Returns a vector of 4 MarginValue structures (top, right, bottom, left). -// Returns an empty vector if parsing fails. -std::vector parseNormalizedRootMargin( - const std::string& marginStr) { - // If unset or set to default, return empty so we don't apply any margins +// Returns std::nullopt if the margin is a no-op or parsing fails. +std::optional parseNormalizedMargin(const std::string& marginStr) { + // If unset or set to default, return nullopt so we don't apply any margins if (marginStr.empty() || marginStr == "0px 0px 0px 0px") { - return {}; + return std::nullopt; } std::vector values; @@ -45,9 +43,9 @@ std::vector parseNormalizedRootMargin( if (std::holds_alternative(parsed)) { auto length = std::get(parsed); - // Only support px units for rootMargin (per W3C spec) + // Only support px units for margins (per W3C spec) if (length.unit != CSSLengthUnit::Px) { - return {}; + return std::nullopt; } values.push_back({length.value, false}); } else if (std::holds_alternative(parsed)) { @@ -55,57 +53,38 @@ std::vector parseNormalizedRootMargin( values.push_back({percentage.value, true}); } else { // Invalid token - return {}; + return std::nullopt; } } // Should have exactly 4 values since JS normalizes to this format if (values.size() != 4) { - return {}; + return std::nullopt; } - return values; -} - -namespace { - -// Convert margin values to actual pixel values based on root rect. -// Per W3C spec: top/bottom percentages use height, left/right use width. -EdgeInsets calculateRootMarginInsets( - const std::vector& margins, - const Rect& rootRect) { - Float top = margins[0].isPercentage - ? (margins[0].value / 100.0f) * rootRect.size.height - : margins[0].value; - Float right = margins[1].isPercentage - ? (margins[1].value / 100.0f) * rootRect.size.width - : margins[1].value; - Float bottom = margins[2].isPercentage - ? (margins[2].value / 100.0f) * rootRect.size.height - : margins[2].value; - Float left = margins[3].isPercentage - ? (margins[3].value / 100.0f) * rootRect.size.width - : margins[3].value; - - return EdgeInsets{left, top, right, bottom}; + return EdgeMargins{ + .left = values[3], + .top = values[0], + .right = values[1], + .bottom = values[2]}; } -} // namespace - IntersectionObserver::IntersectionObserver( IntersectionObserverObserverId intersectionObserverId, std::optional observationRootShadowNodeFamily, ShadowNodeFamily::Shared targetShadowNodeFamily, std::vector thresholds, std::optional> rootThresholds, - std::vector rootMargins) + std::optional rootMargins, + std::optional scrollMargins) : intersectionObserverId_(intersectionObserverId), observationRootShadowNodeFamily_( std::move(observationRootShadowNodeFamily)), targetShadowNodeFamily_(std::move(targetShadowNodeFamily)), thresholds_(std::move(thresholds)), rootThresholds_(std::move(rootThresholds)), - rootMargins_(std::move(rootMargins)) {} + rootMargins_(rootMargins), + scrollMargins_(scrollMargins) {} static std::shared_ptr getShadowNode( const ShadowNodeFamily::AncestorList& ancestors) { @@ -152,13 +131,15 @@ static Rect getBoundingRect(const ShadowNodeFamily::AncestorList& ancestors) { // Returns std::nullopt if the target is entirely clipped by an ancestor. static std::optional getClippedTargetBoundingRect( - const ShadowNodeFamily::AncestorList& targetAncestors) { + const ShadowNodeFamily::AncestorList& targetAncestors, + const std::optional& scrollMargins) { auto layoutMetrics = LayoutableShadowNode::computeRelativeLayoutMetrics( targetAncestors, {/* .includeTransform = */ .includeTransform = true, /* .includeViewportOffset = */ .includeViewportOffset = true, /* .applyParentClipping = */ .enableOverflowClipping = true, - /* .clipSpecifiedAncestor = */ .clipSpecifiedAncestor = false}); + /* .clipSpecifiedAncestor = */ .clipSpecifiedAncestor = false, + /* .clipMargin = */ .clipMargin = scrollMargins}); if (layoutMetrics == EmptyLayoutMetrics) { return std::nullopt; @@ -198,24 +179,26 @@ static std::optional intersectOrNull( // https://w3c.github.io/IntersectionObserver/#calculate-intersection-rect-algo static std::optional computeIntersection( const Rect& rootBoundingRect, - const Rect& rootMarginBoundingRect, + const Rect& rootClipRect, const Rect& targetBoundingRect, const ShadowNodeFamily::AncestorList& targetToRootAncestors, - bool hasExplicitRoot) { + bool hasExplicitRoot, + const std::optional& scrollMargins) { // Use intersectOrNull to properly distinguish between edge-adjacent // (valid intersection) and separated rectangles (no intersection) auto absoluteIntersectionRect = - intersectOrNull(rootMarginBoundingRect, targetBoundingRect); + intersectOrNull(rootClipRect, targetBoundingRect); if (!absoluteIntersectionRect.has_value()) { return std::nullopt; } // Clip against ancestors *until* the observation root (scroll views or - // overflow: hidden between target and root). The root itself is not a - // clipper here; intersecting with rootMarginBoundingRect is the spec's - // final clip against the root intersection rectangle. + // overflow: hidden between target and root), dilating each of those clip + // rects by scrollMargin. The root itself is not a clipper here; intersecting + // with rootClipRect is the spec's final clip against the root intersection + // rectangle. auto clippedTargetFromRoot = - getClippedTargetBoundingRect(targetToRootAncestors); + getClippedTargetBoundingRect(targetToRootAncestors, scrollMargins); if (!clippedTargetFromRoot.has_value()) { // Don't fall through with an empty rect: at the origin, it would count as // edge-adjacent to any root rect containing the origin. @@ -229,7 +212,7 @@ static std::optional computeIntersection( .size=clippedTargetFromRoot->size} : *clippedTargetFromRoot; - return intersectOrNull(rootMarginBoundingRect, clippedTargetBoundingRect); + return intersectOrNull(rootClipRect, clippedTargetBoundingRect); } static Float getHighestThresholdCrossed( @@ -264,15 +247,29 @@ IntersectionObserver::updateIntersectionObservation( auto rootMarginBoundingRect = rootBoundingRect; // Apply rootMargin to expand/contract the root bounding rect - if (!rootMargins_.empty()) { + if (rootMargins_.has_value()) { // Calculate the actual insets based on current root dimensions // (converts percentages to pixels) - auto insets = calculateRootMarginInsets(rootMargins_, rootBoundingRect); + auto insets = resolveEdgeMargins(*rootMargins_, rootBoundingRect.size); // Use outsetBy to expand the root rect (positive values expand, negative // contract) rootMarginBoundingRect = outsetBy(rootBoundingRect, insets); } + // Per spec, scrollMargin also applies to a scrollable root. It only dilates + // the rect targets are clipped against, not `rootBounds` (the root + // intersection rectangle, which only rootMargin dilates). + auto rootClipRect = rootMarginBoundingRect; + if (scrollMargins_.has_value() && hasExplicitRoot) { + auto rootNode = std::dynamic_pointer_cast( + getShadowNode(rootAncestors)); + if (rootNode != nullptr && rootNode->isScrollContainer()) { + rootClipRect = outsetBy( + rootClipRect, + resolveEdgeMargins(*scrollMargins_, rootBoundingRect.size)); + } + } + auto targetAncestors = targetShadowNodeFamily_->getAncestors(rootShadowNode); // Absolute coordinates of the target @@ -290,10 +287,11 @@ IntersectionObserver::updateIntersectionObservation( auto intersection = computeIntersection( rootBoundingRect, - rootMarginBoundingRect, + rootClipRect, targetBoundingRect, targetToRootAncestors, - hasExplicitRoot); + hasExplicitRoot, + scrollMargins_); auto intersectionRect = intersection.has_value() ? intersection.value() : Rect{}; diff --git a/packages/react-native/ReactCommon/react/renderer/observers/intersection/IntersectionObserver.h b/packages/react-native/ReactCommon/react/renderer/observers/intersection/IntersectionObserver.h index 9fa5cce71df7..81aee4d41483 100644 --- a/packages/react-native/ReactCommon/react/renderer/observers/intersection/IntersectionObserver.h +++ b/packages/react-native/ReactCommon/react/renderer/observers/intersection/IntersectionObserver.h @@ -13,24 +13,20 @@ #include #include #include +#include #include +#include #include "IntersectionObserverState.h" namespace facebook::react { using IntersectionObserverObserverId = int32_t; -// Structure to hold a margin value that can be either pixels or percentage -struct MarginValue { - Float value; - bool isPercentage; -}; - -// Parse a normalized rootMargin string that's always in the format: -// "top right bottom left" where each value is either "Npx" or "N%" +// Parse a normalized margin string that's always in the format: +// "top right bottom left" where each value is either "Npx" or "N%". // The string is already validated and normalized by JS. -// Returns a vector of 4 MarginValue structures (top, right, bottom, left). -std::vector parseNormalizedRootMargin(const std::string &marginStr); +// Returns std::nullopt if the margin is a no-op or cannot be parsed. +std::optional parseNormalizedMargin(const std::string &marginStr); struct IntersectionObserverEntry { IntersectionObserverObserverId intersectionObserverId; @@ -55,7 +51,8 @@ class IntersectionObserver { ShadowNodeFamily::Shared targetShadowNodeFamily, std::vector thresholds, std::optional> rootThresholds, - std::vector rootMargins); + std::optional rootMargins, + std::optional scrollMargins); // Partially equivalent to // https://w3c.github.io/IntersectionObserver/#update-intersection-observations-algo @@ -100,8 +97,11 @@ class IntersectionObserver { ShadowNodeFamily::Shared targetShadowNodeFamily_; std::vector thresholds_; std::optional> rootThresholds_; - // Parsed and expanded rootMargin values (top, right, bottom, left) - std::vector rootMargins_; + // Parsed rootMargin, dilating the root intersection rectangle + std::optional rootMargins_; + // Parsed scrollMargin, dilating the clip rect of every scrollport between + // the root and the target + std::optional scrollMargins_; mutable IntersectionObserverState state_ = IntersectionObserverState::Initial(); }; diff --git a/packages/react-native/ReactCommon/react/renderer/observers/intersection/IntersectionObserverManager.cpp b/packages/react-native/ReactCommon/react/renderer/observers/intersection/IntersectionObserverManager.cpp index 7369935a9b46..83ede53064ec 100644 --- a/packages/react-native/ReactCommon/react/renderer/observers/intersection/IntersectionObserverManager.cpp +++ b/packages/react-native/ReactCommon/react/renderer/observers/intersection/IntersectionObserverManager.cpp @@ -45,6 +45,7 @@ void IntersectionObserverManager::observe( std::vector thresholds, std::optional> rootThresholds, std::optional rootMargin, + std::optional scrollMargin, const UIManager& /*uiManager*/) { TraceSection s("IntersectionObserverManager::observe"); @@ -55,10 +56,12 @@ void IntersectionObserverManager::observe( auto& observers = observersBySurfaceId_[surfaceId]; - // Parse rootMargin string into MarginValue structures + // Parse the margin strings into EdgeMargins // Default to "0px 0px 0px 0px" if not provided auto parsedRootMargin = - parseNormalizedRootMargin(rootMargin.value_or("0px 0px 0px 0px")); + parseNormalizedMargin(rootMargin.value_or("0px 0px 0px 0px")); + auto parsedScrollMargin = + parseNormalizedMargin(scrollMargin.value_or("0px 0px 0px 0px")); observers.emplace_back( std::make_unique( @@ -67,7 +70,8 @@ void IntersectionObserverManager::observe( shadowNodeFamily, std::move(thresholds), std::move(rootThresholds), - std::move(parsedRootMargin))); + parsedRootMargin, + parsedScrollMargin)); observersPendingInitialization_.emplace_back(observers.back().get()); } diff --git a/packages/react-native/ReactCommon/react/renderer/observers/intersection/IntersectionObserverManager.h b/packages/react-native/ReactCommon/react/renderer/observers/intersection/IntersectionObserverManager.h index ddd3cb1af6ad..be86caa7ef05 100644 --- a/packages/react-native/ReactCommon/react/renderer/observers/intersection/IntersectionObserverManager.h +++ b/packages/react-native/ReactCommon/react/renderer/observers/intersection/IntersectionObserverManager.h @@ -33,6 +33,7 @@ class IntersectionObserverManager final : public UIManagerMountHook, std::vector thresholds, std::optional> rootThresholds, std::optional rootMargin, + std::optional scrollMargin, const UIManager &uiManager); void unobserve(IntersectionObserverObserverId intersectionObserverId, const ShadowNodeFamily::Shared &shadowNode); diff --git a/packages/react-native/flow/bom.js.flow b/packages/react-native/flow/bom.js.flow index a4e8e90c1d97..703d2bf07bc7 100644 --- a/packages/react-native/flow/bom.js.flow +++ b/packages/react-native/flow/bom.js.flow @@ -436,6 +436,7 @@ declare type IntersectionObserverCallback = ( declare type IntersectionObserverOptions = { root?: Node | null, rootMargin?: string, + scrollMargin?: string, threshold?: number | Array, // React Native-specific extension. Thresholds expressed as a fraction of the // root's size (instead of the target's size). @@ -443,8 +444,8 @@ declare type IntersectionObserverOptions = { ... }; -// The `delay`, `scrollMargin` and `trackVisibility` options are not supported -// in React Native and will throw if provided. +// The `delay` and `trackVisibility` options are not supported in React Native +// and will throw if provided. declare class IntersectionObserver { constructor( callback: IntersectionObserverCallback, @@ -454,6 +455,7 @@ declare class IntersectionObserver { observe(target: Element): void; readonly root: Element | null; readonly rootMargin: string; + readonly scrollMargin: string; // React Native-specific extension. The thresholds expressed as a fraction of // the root's size (set via the `rnRootThreshold` option). readonly rnRootThresholds: ReadonlyArray | null; diff --git a/packages/react-native/src/private/webapis/intersectionobserver/IntersectionObserver.js b/packages/react-native/src/private/webapis/intersectionobserver/IntersectionObserver.js index f75e7c0375a7..48c8e800fff6 100644 --- a/packages/react-native/src/private/webapis/intersectionobserver/IntersectionObserver.js +++ b/packages/react-native/src/private/webapis/intersectionobserver/IntersectionObserver.js @@ -25,6 +25,7 @@ export type IntersectionObserverCallback = ( export interface IntersectionObserverInit { root?: ?ReactNativeElement; rootMargin?: string; + scrollMargin?: string; threshold?: number | ReadonlyArray; /** @@ -56,8 +57,9 @@ export interface IntersectionObserverInit { * changes in degree of visibility; however, you can watch multiple target * elements with the same observer. * - * This implementation supports `threshold`, `root`, and `rootMargin` options and - * provides a React Native specific option `rnRootThreshold`. + * This implementation supports `threshold`, `root`, `rootMargin` and + * `scrollMargin` options and provides a React Native specific option + * `rnRootThreshold`. * */ export default class IntersectionObserver { @@ -68,6 +70,7 @@ export default class IntersectionObserver { _rootThresholds: ReadonlyArray | null; _root: ReactNativeElement | null; _rootMargin: string; + _scrollMargin: string; constructor( callback: IntersectionObserverCallback, @@ -100,12 +103,6 @@ export default class IntersectionObserver { ); } - if (options != null && 'scrollMargin' in options) { - throw new Error( - "Failed to construct 'IntersectionObserver': The 'scrollMargin' option is not supported.", - ); - } - if (options != null && 'trackVisibility' in options) { throw new Error( "Failed to construct 'IntersectionObserver': The 'trackVisibility' option is not supported.", @@ -120,7 +117,8 @@ export default class IntersectionObserver { this._rootThresholds != null, // only provide default if no rootThreshold ); this._root = options?.root ?? null; - this._rootMargin = normalizeRootMargin(options?.rootMargin); + this._rootMargin = normalizeMargin(options?.rootMargin, 'rootMargin'); + this._scrollMargin = normalizeMargin(options?.scrollMargin, 'scrollMargin'); } /** @@ -181,13 +179,16 @@ export default class IntersectionObserver { } /** - * The `scrollMargin` option is not supported. - * @throws {Error} Always throws an error indicating this property is not supported. + * String with syntax similar to that of the CSS `margin` property. + * Each side of the rectangle represented by `scrollMargin` is added to the + * corresponding side of the clipping box of every scroll container between + * the root and the target, before the intersection test is performed. + * + * Unlike `rootMargin`, this does not affect the root itself, and so it does + * not affect the reported `rootBounds`. */ get scrollMargin(): string { - throw new Error( - "Failed to read the 'scrollMargin' property from 'IntersectionObserver': This property is not supported.", - ); + return this._scrollMargin; } /** @@ -392,25 +393,25 @@ function normalizeThresholdValue( } /** - * Validates and normalizes the rootMargin value. + * Validates and normalizes a margin value (`rootMargin` or `scrollMargin`). * Accepts CSS margin syntax (e.g., "10px", "10px 20px", "10px 20px 30px 40px"). * Returns the normalized string or throws an error if invalid. * - * Per W3C spec, rootMargin must be specified in pixels or percent. + * Per W3C spec, margins must be specified in pixels or percent. * This implementation validates the basic format. */ -function normalizeRootMargin(rootMargin: unknown): string { - if (rootMargin == null || rootMargin === '') { +function normalizeMargin(margin: unknown, propertyName: string): string { + if (margin == null || margin === '') { return '0px 0px 0px 0px'; } - if (typeof rootMargin !== 'string') { + if (typeof margin !== 'string') { throw new TypeError( - "Failed to construct 'IntersectionObserver': Failed to read the 'rootMargin' property from 'IntersectionObserverInit': The provided value is not of type 'string'.", + `Failed to construct 'IntersectionObserver': Failed to read the '${propertyName}' property from 'IntersectionObserverInit': The provided value is not of type 'string'.`, ); } - const marginStr = rootMargin.trim(); + const marginStr = margin.trim(); if (marginStr === '') { return '0px 0px 0px 0px'; } @@ -419,7 +420,7 @@ function normalizeRootMargin(rootMargin: unknown): string { const parts = marginStr.split(/\s+/); if (parts.length > 4) { throw new SyntaxError( - "Failed to construct 'IntersectionObserver': Failed to parse rootMargin: Too many values (expected 1-4).", + `Failed to construct 'IntersectionObserver': Failed to parse ${propertyName}: Too many values (expected 1-4).`, ); } @@ -428,7 +429,7 @@ function normalizeRootMargin(rootMargin: unknown): string { for (const part of parts) { if (!validPattern.test(part)) { throw new SyntaxError( - `Failed to construct 'IntersectionObserver': Failed to parse rootMargin: '${part}' is not a valid length. Only 'px' and '%' units are allowed.`, + `Failed to construct 'IntersectionObserver': Failed to parse ${propertyName}: '${part}' is not a valid length. Only 'px' and '%' units are allowed.`, ); } } @@ -454,7 +455,7 @@ function normalizeRootMargin(rootMargin: unknown): string { break; default: throw new SyntaxError( - "Failed to construct 'IntersectionObserver': Failed to parse rootMargin.", + `Failed to construct 'IntersectionObserver': Failed to parse ${propertyName}.`, ); } diff --git a/packages/react-native/src/private/webapis/intersectionobserver/__tests__/IntersectionObserver-itest.js b/packages/react-native/src/private/webapis/intersectionobserver/__tests__/IntersectionObserver-itest.js index 543a6a26a35e..7b3e7b2b16e6 100644 --- a/packages/react-native/src/private/webapis/intersectionobserver/__tests__/IntersectionObserver-itest.js +++ b/packages/react-native/src/private/webapis/intersectionobserver/__tests__/IntersectionObserver-itest.js @@ -60,7 +60,7 @@ describe('IntersectionObserver', () => { }); }); - describe('constructor(callback, {root, rootMargin, threshold, rnRootThreshold})', () => { + describe('constructor(callback, {root, rootMargin, scrollMargin, threshold, rnRootThreshold})', () => { it('should throw if `callback` is not provided', () => { expect(() => { // $FlowExpectedError[incompatible-type] @@ -239,6 +239,124 @@ describe('IntersectionObserver', () => { }); }); + describe('scrollMargin', () => { + it('should parse single value scrollMargin', () => { + observer = new IntersectionObserver(() => {}, {scrollMargin: '10px'}); + expect(observer.scrollMargin).toBe('10px 10px 10px 10px'); + }); + + it('should parse two value scrollMargin', () => { + observer = new IntersectionObserver(() => {}, { + scrollMargin: '10px 20px', + }); + expect(observer.scrollMargin).toBe('10px 20px 10px 20px'); + }); + + it('should parse three value scrollMargin', () => { + observer = new IntersectionObserver(() => {}, { + scrollMargin: '10px 20px 30px', + }); + expect(observer.scrollMargin).toBe('10px 20px 30px 20px'); + }); + + it('should parse four value scrollMargin', () => { + observer = new IntersectionObserver(() => {}, { + scrollMargin: '10px 20px 30px 40px', + }); + expect(observer.scrollMargin).toBe('10px 20px 30px 40px'); + }); + + it('should handle negative scrollMargin values', () => { + observer = new IntersectionObserver(() => {}, { + scrollMargin: '-10px -20px', + }); + expect(observer.scrollMargin).toBe('-10px -20px -10px -20px'); + }); + + it('should handle percentage scrollMargin values', () => { + observer = new IntersectionObserver(() => {}, { + scrollMargin: '10% 20%', + }); + expect(observer.scrollMargin).toBe('10% 20% 10% 20%'); + }); + + it('should be independent from rootMargin', () => { + observer = new IntersectionObserver(() => {}, { + // $FlowExpectedError[prop-missing] rootMargin is not even defined in Flow. + rootMargin: '5px', + scrollMargin: '10px', + }); + expect(observer.rootMargin).toBe('5px 5px 5px 5px'); + expect(observer.scrollMargin).toBe('10px 10px 10px 10px'); + }); + + describe('default values', () => { + it('should default to "0px 0px 0px 0px" when scrollMargin is not provided', () => { + observer = new IntersectionObserver(() => {}); + expect(observer.scrollMargin).toBe('0px 0px 0px 0px'); + }); + + it('should default to "0px 0px 0px 0px" when scrollMargin is undefined', () => { + observer = new IntersectionObserver(() => {}, { + scrollMargin: undefined, + }); + expect(observer.scrollMargin).toBe('0px 0px 0px 0px'); + }); + + it('should default to "0px 0px 0px 0px" when scrollMargin is empty string', () => { + observer = new IntersectionObserver(() => {}, {scrollMargin: ''}); + expect(observer.scrollMargin).toBe('0px 0px 0px 0px'); + }); + }); + + describe('parsing failures', () => { + it('should throw when scrollMargin is not a string', () => { + expect(() => { + // $FlowExpectedError[incompatible-type] + return new IntersectionObserver(() => {}, {scrollMargin: 123}); + }).toThrow( + "Failed to construct 'IntersectionObserver': Failed to read the 'scrollMargin' property from 'IntersectionObserverInit': The provided value is not of type 'string'.", + ); + }); + + it('should throw when scrollMargin has too many values', () => { + expect(() => { + return new IntersectionObserver(() => {}, { + scrollMargin: '10px 20px 30px 40px 50px', + }); + }).toThrow( + "Failed to construct 'IntersectionObserver': Failed to parse scrollMargin: Too many values (expected 1-4).", + ); + }); + + it('should throw when scrollMargin value is missing unit', () => { + expect(() => { + return new IntersectionObserver(() => {}, {scrollMargin: '10'}); + }).toThrow( + "Failed to construct 'IntersectionObserver': Failed to parse scrollMargin: '10' is not a valid length. Only 'px' and '%' units are allowed.", + ); + }); + + it('should throw when scrollMargin value has invalid unit', () => { + expect(() => { + return new IntersectionObserver(() => {}, {scrollMargin: '10em'}); + }).toThrow( + "Failed to construct 'IntersectionObserver': Failed to parse scrollMargin: '10em' is not a valid length. Only 'px' and '%' units are allowed.", + ); + }); + + it('should throw when scrollMargin has mixed valid and invalid values', () => { + expect(() => { + return new IntersectionObserver(() => {}, { + scrollMargin: '10px invalid', + }); + }).toThrow( + "Failed to construct 'IntersectionObserver': Failed to parse scrollMargin: 'invalid' is not a valid length. Only 'px' and '%' units are allowed.", + ); + }); + }); + }); + it('should throw if `threshold` contains a value lower than 0 or greater than 1', () => { expect(() => { return new IntersectionObserver(() => {}, {threshold: 1.01}); @@ -484,15 +602,6 @@ describe('IntersectionObserver', () => { ); }); - it('should throw if `scrollMargin` option is specified', () => { - expect(() => { - // $FlowExpectedError[prop-missing] scrollMargin is not defined in Flow. - return new IntersectionObserver(() => {}, {scrollMargin: '10px'}); - }).toThrow( - "Failed to construct 'IntersectionObserver': The 'scrollMargin' option is not supported.", - ); - }); - it('should throw if `trackVisibility` option is specified', () => { expect(() => { // $FlowExpectedError[prop-missing] trackVisibility is not defined in Flow. @@ -511,15 +620,6 @@ describe('IntersectionObserver', () => { ); }); - it('should throw if `scrollMargin` option is set to null explicitly', () => { - expect(() => { - // $FlowExpectedError[prop-missing] scrollMargin is not defined in Flow. - return new IntersectionObserver(() => {}, {scrollMargin: null}); - }).toThrow( - "Failed to construct 'IntersectionObserver': The 'scrollMargin' option is not supported.", - ); - }); - it('should not throw when unsupported options are not specified', () => { expect(() => { return new IntersectionObserver(() => {}, { @@ -552,15 +652,6 @@ describe('IntersectionObserver', () => { ); }); - it('should throw when accessing scrollMargin getter', () => { - observer = new IntersectionObserver(() => {}); - expect(() => { - return observer.scrollMargin; - }).toThrow( - "Failed to read the 'scrollMargin' property from 'IntersectionObserver': This property is not supported.", - ); - }); - it('should throw when accessing trackVisibility getter', () => { observer = new IntersectionObserver(() => {}); expect(() => { @@ -4039,6 +4130,595 @@ describe('IntersectionObserver', () => { expect(entries[0].intersectionRatio).toBe(0); }); }); + + describe('scrollMargin', () => { + // Same layout as the `rootMargin` cases above: a 100x100 ScrollView + // clipping a 50x50 target that sits 150px down, entirely below the fold. + // `rootMargin` cannot reach past an intermediate clipper, `scrollMargin` + // can. + function renderTargetBelowTheFoldOfAScrollView(marginTop: number = 150) { + const nodeRef = React.createRef(); + + const root = Fantom.createRoot({ + viewportWidth: 1000, + viewportHeight: 1000, + }); + Fantom.runTask(() => { + root.render( + + + , + ); + }); + + return nullthrows(nodeRef.current); + } + + it('should see past an intermediate ScrollView', () => { + const node = renderTargetBelowTheFoldOfAScrollView(); + + const intersectionObserverCallback = jest.fn(); + + Fantom.runTask(() => { + observer = new IntersectionObserver(intersectionObserverCallback, { + scrollMargin: '0px 0px 150px 0px', + threshold: [0.01], + }); + observer.observe(node); + }); + + expect(intersectionObserverCallback).toHaveBeenCalledTimes(1); + const [entries] = intersectionObserverCallback.mock.lastCall; + expect(entries.length).toBe(1); + expect(entries[0].isIntersecting).toBe(true); + expect(entries[0].intersectionRatio).toBe(1); + expectRectEquals(entries[0].intersectionRect, { + x: 0, + y: 150, + width: 50, + height: 50, + }); + // Unlike `rootMargin`, `scrollMargin` must not affect `rootBounds`. + expectRectEquals(entries[0].rootBounds, { + x: 0, + y: 0, + width: 1000, + height: 1000, + }); + }); + + it('should partially reveal a target when the margin does not fully cover it', () => { + const node = renderTargetBelowTheFoldOfAScrollView(); + + const intersectionObserverCallback = jest.fn(); + + Fantom.runTask(() => { + observer = new IntersectionObserver(intersectionObserverCallback, { + // Expands the scrollport's clip to 0..175, revealing the first + // 25px of the target (which spans 150..200). + scrollMargin: '0px 0px 75px 0px', + threshold: [0.01], + }); + observer.observe(node); + }); + + const [entries] = intersectionObserverCallback.mock.lastCall; + expect(entries[0].isIntersecting).toBe(true); + expect(entries[0].intersectionRatio).toBe(0.5); + expectRectEquals(entries[0].intersectionRect, { + x: 0, + y: 150, + width: 50, + height: 25, + }); + }); + + it('should not reveal a target still beyond the expanded clip', () => { + const node = renderTargetBelowTheFoldOfAScrollView(); + + const intersectionObserverCallback = jest.fn(); + + Fantom.runTask(() => { + observer = new IntersectionObserver(intersectionObserverCallback, { + // Expands the clip to 0..125, still short of the target at 150. + scrollMargin: '0px 0px 25px 0px', + threshold: [0.01], + }); + observer.observe(node); + }); + + const [entries] = intersectionObserverCallback.mock.lastCall; + expect(entries[0].isIntersecting).toBe(false); + expect(entries[0].intersectionRatio).toBe(0); + }); + + it('should resolve percentages against the scrollport, not the root', () => { + const node = renderTargetBelowTheFoldOfAScrollView(); + + const intersectionObserverCallback = jest.fn(); + + Fantom.runTask(() => { + observer = new IntersectionObserver(intersectionObserverCallback, { + // 60% of the 100px scrollport is 60px, expanding its clip to + // 0..160 and revealing 10px of the target. Were this resolved + // against the 1000px viewport it would reveal the target entirely. + scrollMargin: '0% 0% 60% 0%', + threshold: [0.01], + }); + observer.observe(node); + }); + + const [entries] = intersectionObserverCallback.mock.lastCall; + expect(entries[0].isIntersecting).toBe(true); + expect(entries[0].intersectionRatio).toBe(0.2); + expectRectEquals(entries[0].intersectionRect, { + x: 0, + y: 150, + width: 50, + height: 10, + }); + }); + + it('should contract the scrollport clip with negative values', () => { + // Target spans 60..110, so the unmodified scrollport clips it to + // 60..100 (80% visible). + const node = renderTargetBelowTheFoldOfAScrollView(60); + + const intersectionObserverCallback = jest.fn(); + + Fantom.runTask(() => { + observer = new IntersectionObserver(intersectionObserverCallback, { + // Contracts the clip to 0..80, leaving only 60..80 visible. + scrollMargin: '0px 0px -20px 0px', + threshold: [0.01], + }); + observer.observe(node); + }); + + const [entries] = intersectionObserverCallback.mock.lastCall; + expect(entries[0].isIntersecting).toBe(true); + expect(entries[0].intersectionRatio).toBe(0.4); + expectRectEquals(entries[0].intersectionRect, { + x: 0, + y: 60, + width: 50, + height: 20, + }); + }); + + function observeAndGetEntry( + target: HostInstance, + options: { + root?: HostInstance, + rootMargin?: string, + scrollMargin?: string, + }, + ): { + readonly isIntersecting: boolean, + readonly intersectionRatio: number, + readonly intersectionRect: DOMRectReadOnly, + readonly rootBounds: ?DOMRectReadOnly, + ... + } { + const intersectionObserverCallback = jest.fn(); + + Fantom.runTask(() => { + observer = new IntersectionObserver(intersectionObserverCallback, { + threshold: [0.01], + ...options, + }); + observer.observe(target); + }); + + expect(intersectionObserverCallback).toHaveBeenCalledTimes(1); + const [entries] = intersectionObserverCallback.mock.lastCall; + expect(entries.length).toBe(1); + return entries[0]; + } + + describe('non-scroll containers', () => { + it('should not apply negative values to the clip of `overflow: visible` ancestors', () => { + const nodeRef = React.createRef(); + + const root = Fantom.createRoot({ + viewportWidth: 1000, + viewportHeight: 1000, + }); + Fantom.runTask(() => { + root.render( + + + , + ); + }); + + // There are no scroll containers between the target and the root, + // so per spec `scrollMargin` must have no effect at all. + const entry = observeAndGetEntry(nullthrows(nodeRef.current), { + scrollMargin: '-10px', + }); + + expect(entry.isIntersecting).toBe(true); + expect(entry.intersectionRatio).toBe(1); + expectRectEquals(entry.intersectionRect, { + x: 20, + y: 20, + width: 50, + height: 50, + }); + }); + + it('should not apply negative values to `overflow: visible` ancestors inside a scroll container', () => { + const nodeRef = React.createRef(); + + const root = Fantom.createRoot({ + viewportWidth: 1000, + viewportHeight: 1000, + }); + Fantom.runTask(() => { + root.render( + + + + + , + ); + }); + + // Contracts only the scrollport's clip to 10..100, which still + // contains the target at 20..70. The wrapping view is not a scroll + // container and must not be contracted. + const entry = observeAndGetEntry(nullthrows(nodeRef.current), { + scrollMargin: '-10px 0px 0px 0px', + }); + + expect(entry.isIntersecting).toBe(true); + expect(entry.intersectionRatio).toBe(1); + expectRectEquals(entry.intersectionRect, { + x: 0, + y: 20, + width: 50, + height: 50, + }); + }); + + it('should not apply to the target itself, even if it is a scroll container', () => { + const nodeRef = React.createRef(); + + const root = Fantom.createRoot({ + viewportWidth: 1000, + viewportHeight: 1000, + }); + Fantom.runTask(() => { + root.render( + , + ); + }); + + // The spec starts the clipping walk at the target's containing + // block, so the target's own clip is never dilated. + const entry = observeAndGetEntry(nullthrows(nodeRef.current), { + scrollMargin: '-10px', + }); + + expect(entry.isIntersecting).toBe(true); + expect(entry.intersectionRatio).toBe(1); + expectRectEquals(entry.intersectionRect, { + x: 20, + y: 20, + width: 50, + height: 50, + }); + }); + + it('should apply to `overflow: hidden` ancestors (which are scroll containers)', () => { + const nodeRef = React.createRef(); + + const root = Fantom.createRoot({ + viewportWidth: 1000, + viewportHeight: 1000, + }); + Fantom.runTask(() => { + root.render( + + + , + ); + }); + + // Expands the clip to 0..175, revealing 150..175 of the target. + const entry = observeAndGetEntry(nullthrows(nodeRef.current), { + scrollMargin: '0px 0px 75px 0px', + }); + + expect(entry.isIntersecting).toBe(true); + expect(entry.intersectionRatio).toBe(0.5); + expectRectEquals(entry.intersectionRect, { + x: 0, + y: 150, + width: 50, + height: 25, + }); + }); + }); + + describe('explicit root', () => { + function renderTargetBelowTheFoldOfAScrollViewRoot(): { + scrollNode: HostInstance, + node: HostInstance, + } { + const scrollNodeRef = React.createRef(); + const nodeRef = React.createRef(); + + const root = Fantom.createRoot({ + viewportWidth: 1000, + viewportHeight: 1000, + }); + Fantom.runTask(() => { + root.render( + + + , + ); + }); + + return { + scrollNode: nullthrows(scrollNodeRef.current), + node: nullthrows(nodeRef.current), + }; + } + + it('should apply to a scrollable root', () => { + const {scrollNode, node} = + renderTargetBelowTheFoldOfAScrollViewRoot(); + + // Per spec, both `rootMargin` and `scrollMargin` apply to a + // scrollable root. Expands the root's clip to 0..175. + const entry = observeAndGetEntry(node, { + root: scrollNode, + scrollMargin: '0px 0px 75px 0px', + }); + + expect(entry.isIntersecting).toBe(true); + expect(entry.intersectionRatio).toBe(0.5); + expectRectEquals(entry.intersectionRect, { + x: 0, + y: 150, + width: 50, + height: 25, + }); + // `rootBounds` is the root intersection rectangle, which only + // `rootMargin` dilates. + expectRectEquals(nullthrows(entry.rootBounds), { + x: 0, + y: 0, + width: 100, + height: 100, + }); + }); + + it('should combine with rootMargin on a scrollable root, resolving both against the undilated root', () => { + const {scrollNode, node} = + renderTargetBelowTheFoldOfAScrollViewRoot(); + + // rootMargin adds 40px and scrollMargin 25% of the undilated 100px + // root (25px), so the clip is 0..165. Resolving the percentage + // against the rootMargin-dilated root (140px) would give 0..175. + const entry = observeAndGetEntry(node, { + root: scrollNode, + rootMargin: '0px 0px 40px 0px', + scrollMargin: '0% 0% 25% 0%', + }); + + expect(entry.isIntersecting).toBe(true); + expect(entry.intersectionRatio).toBe(0.3); + expectRectEquals(entry.intersectionRect, { + x: 0, + y: 150, + width: 50, + height: 15, + }); + expectRectEquals(nullthrows(entry.rootBounds), { + x: 0, + y: 0, + width: 100, + height: 140, + }); + }); + + it('should not apply to a root that is not a scroll container', () => { + const rootNodeRef = React.createRef(); + const nodeRef = React.createRef(); + + const root = Fantom.createRoot({ + viewportWidth: 1000, + viewportHeight: 1000, + }); + Fantom.runTask(() => { + root.render( + + + , + ); + }); + + const entry = observeAndGetEntry(nullthrows(nodeRef.current), { + root: nullthrows(rootNodeRef.current), + scrollMargin: '0px 0px 75px 0px', + }); + + expect(entry.isIntersecting).toBe(false); + expect(entry.intersectionRatio).toBe(0); + }); + }); + + it('should apply to every scroll container between the root and the target', () => { + const nodeRef = React.createRef(); + + const root = Fantom.createRoot({ + viewportWidth: 1000, + viewportHeight: 1000, + }); + Fantom.runTask(() => { + root.render( + + + + + , + ); + }); + + // Both scrollports span 0..100. Each must expand to 0..175 for the + // target to be revealed: if either were not dilated, its 0..100 clip + // would hide the target entirely. + const entry = observeAndGetEntry(nullthrows(nodeRef.current), { + scrollMargin: '0px 0px 75px 0px', + }); + + expect(entry.isIntersecting).toBe(true); + expect(entry.intersectionRatio).toBe(0.5); + expectRectEquals(entry.intersectionRect, { + x: 0, + y: 150, + width: 50, + height: 25, + }); + }); + + it('should apply to the horizontal edges', () => { + const nodeRef = React.createRef(); + + const root = Fantom.createRoot({ + viewportWidth: 1000, + viewportHeight: 1000, + }); + Fantom.runTask(() => { + root.render( + + + , + ); + }); + + // Expands the scrollport's clip to 0..175 horizontally. + const entry = observeAndGetEntry(nullthrows(nodeRef.current), { + scrollMargin: '0px 75px 0px 0px', + }); + + expect(entry.isIntersecting).toBe(true); + expect(entry.intersectionRatio).toBe(0.5); + expectRectEquals(entry.intersectionRect, { + x: 150, + y: 0, + width: 25, + height: 50, + }); + }); + + it('should reveal a target scrolled above the scrollport through the top edge', () => { + const scrollNodeRef = React.createRef(); + const nodeRef = React.createRef(); + + const root = Fantom.createRoot({ + viewportWidth: 1000, + viewportHeight: 1000, + }); + Fantom.runTask(() => { + root.render( + + + + , + ); + }); + + // The scrollport spans 100..200 in the viewport. Scrolling by 200 + // moves the target (150..200 in the content) to 50..100, just above + // it. + Fantom.scrollTo(nullthrows(scrollNodeRef.current), { + x: 0, + y: 200, + }); + + // Expands the scrollport's clip to 75..200. + const entry = observeAndGetEntry(nullthrows(nodeRef.current), { + scrollMargin: '25px 0px 0px 0px', + }); + + expect(entry.isIntersecting).toBe(true); + expect(entry.intersectionRatio).toBe(0.5); + expectRectEquals(entry.intersectionRect, { + x: 0, + y: 75, + width: 50, + height: 25, + }); + }); + + it('should compose with rootMargin on the implicit root', () => { + const node = renderTargetBelowTheFoldOfAScrollView(); + + // scrollMargin expands the scrollport's clip to 0..250, revealing the + // whole target (150..200), but rootMargin contracts the root to + // 0..160, so only 150..160 is intersecting. + const entry = observeAndGetEntry(node, { + rootMargin: '0px 0px -840px 0px', + scrollMargin: '0px 0px 150px 0px', + }); + + expect(entry.isIntersecting).toBe(true); + expect(entry.intersectionRatio).toBe(0.2); + expectRectEquals(entry.intersectionRect, { + x: 0, + y: 150, + width: 50, + height: 10, + }); + expectRectEquals(nullthrows(entry.rootBounds), { + x: 0, + y: 0, + width: 1000, + height: 160, + }); + }); + }); }); describe('unobserve(target)', () => { diff --git a/packages/react-native/src/private/webapis/intersectionobserver/internals/IntersectionObserverManager.js b/packages/react-native/src/private/webapis/intersectionobserver/internals/IntersectionObserverManager.js index 97e0fcf49051..c4b77e67534e 100644 --- a/packages/react-native/src/private/webapis/intersectionobserver/internals/IntersectionObserverManager.js +++ b/packages/react-native/src/private/webapis/intersectionobserver/internals/IntersectionObserverManager.js @@ -175,6 +175,7 @@ export function observe({ thresholds: registeredObserver.observer.thresholds, rootThresholds: registeredObserver.observer.rnRootThresholds, rootMargin: registeredObserver.observer.rootMargin, + scrollMargin: registeredObserver.observer.scrollMargin, }); targetToTokenMap.set(target, token); diff --git a/packages/react-native/src/private/webapis/intersectionobserver/specs/NativeIntersectionObserver.js b/packages/react-native/src/private/webapis/intersectionobserver/specs/NativeIntersectionObserver.js index 56931369a35e..d8c44f318eb8 100644 --- a/packages/react-native/src/private/webapis/intersectionobserver/specs/NativeIntersectionObserver.js +++ b/packages/react-native/src/private/webapis/intersectionobserver/specs/NativeIntersectionObserver.js @@ -30,6 +30,7 @@ export type NativeIntersectionObserverObserveOptions = { thresholds: ReadonlyArray, rootThresholds?: ?ReadonlyArray, rootMargin?: ?string, + scrollMargin?: ?string, }; export opaque type NativeIntersectionObserverToken = unknown; diff --git a/packages/rn-tester/js/examples/IntersectionObserver/IntersectionObserverIndex.js b/packages/rn-tester/js/examples/IntersectionObserver/IntersectionObserverIndex.js index 47d2dcf44318..85ee16c08b42 100644 --- a/packages/rn-tester/js/examples/IntersectionObserver/IntersectionObserverIndex.js +++ b/packages/rn-tester/js/examples/IntersectionObserver/IntersectionObserverIndex.js @@ -17,6 +17,7 @@ import * as IntersectionObserverExplicitRoot from './IntersectionObserverExplici import * as IntersectionObserverExplicitRootScroll from './IntersectionObserverExplicitRootScroll'; import * as IntersectionObserverMDNExample from './IntersectionObserverMDNExample'; import * as IntersectionObserverRootThreshold from './IntersectionObserverRootThreshold'; +import * as IntersectionObserverScrollMarginPrefetch from './IntersectionObserverScrollMarginPrefetch'; export const framework = 'React'; export const title = 'IntersectionObserver'; @@ -34,4 +35,5 @@ export const examples: Array = [ IntersectionObserverExplicitRootScroll, IntersectionObserverClippingParent, IntersectionObserverClippingRoot, + IntersectionObserverScrollMarginPrefetch, ]; diff --git a/packages/rn-tester/js/examples/IntersectionObserver/IntersectionObserverScrollMarginPrefetch.js b/packages/rn-tester/js/examples/IntersectionObserver/IntersectionObserverScrollMarginPrefetch.js new file mode 100644 index 000000000000..f5304eb5185c --- /dev/null +++ b/packages/rn-tester/js/examples/IntersectionObserver/IntersectionObserverScrollMarginPrefetch.js @@ -0,0 +1,243 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @flow strict-local + */ + +import type {HostInstance} from 'react-native'; + +import RNTesterText from '../../components/RNTesterText'; +import {RNTesterThemeContext} from '../../components/RNTesterTheme'; +import RNTOption from '../../components/RNTOption'; +import * as React from 'react'; +import {useContext, useLayoutEffect, useRef, useState} from 'react'; +import {ScrollView, StyleSheet, View} from 'react-native'; + +export const name = 'IntersectionObserver scrollMargin Prefetch Example'; +export const title = name; +export const description = + 'Detect list items 500px before they scroll into view (e.g. to prefetch data or images). Compares rootMargin, which cannot see past the ScrollView clipping the items, with scrollMargin, which can.'; + +export function render(): React.Node { + return ; +} + +type MarginMode = 'rootMargin' | 'scrollMargin'; + +const PREFETCH_DISTANCE = '500px'; +const ITEM_COUNT = 50; +const MAX_MESSAGES = 50; + +const MODE_EXPLANATIONS: {[mode: MarginMode]: string} = { + rootMargin: `rootMargin: '${PREFETCH_DISTANCE} 0px' expands the viewport, but the items are still clipped by the ScrollView, so each one is only reported once it is actually visible. Too late to prefetch.`, + scrollMargin: `scrollMargin: '${PREFETCH_DISTANCE} 0px' expands the clipping area of the ScrollView, so each item is reported ${PREFETCH_DISTANCE} before it scrolls into view.`, +}; + +component IntersectionObserverScrollMarginPrefetchExample() { + const theme = useContext(RNTesterThemeContext); + const [mode, setMode] = useState('scrollMargin'); + const [messages, setMessages] = useState>([]); + const [itemsInRange, setItemsInRange] = useState>( + new Set(), + ); + const itemNodesRef = useRef>(new Map()); + + useLayoutEffect(() => { + setMessages([]); + setItemsInRange(new Set()); + + const itemNumberByNode = new Map(); + for (const [itemNumber, node] of itemNodesRef.current) { + itemNumberByNode.set(node, itemNumber); + } + + const observer = new IntersectionObserver( + entries => { + const entered: Array = []; + const left: Array = []; + for (const entry of entries) { + const itemNumber = itemNumberByNode.get(entry.target); + if (itemNumber == null) { + continue; + } + (entry.isIntersecting ? entered : left).push(itemNumber); + } + + if (entered.length > 0) { + entered.sort((a, b) => a - b); + setMessages(prev => + [ + ...entered + .map( + itemNumber => + `#${itemNumber} is within ${PREFETCH_DISTANCE}: prefetch it`, + ) + .reverse(), + ...prev, + ].slice(0, MAX_MESSAGES), + ); + } + + setItemsInRange(prev => { + const next = new Set(prev); + entered.forEach(itemNumber => next.add(itemNumber)); + left.forEach(itemNumber => next.delete(itemNumber)); + return next; + }); + }, + mode === 'rootMargin' + ? {rootMargin: `${PREFETCH_DISTANCE} 0px`} + : {scrollMargin: `${PREFETCH_DISTANCE} 0px`}, + ); + + for (const node of itemNodesRef.current.values()) { + // $FlowFixMe[incompatible-type] React Native host instances implement the global Element interface. + observer.observe(node); + } + + return () => { + observer.disconnect(); + }; + }, [mode]); + + return ( + + + setMode('rootMargin')} + /> + setMode('scrollMargin')} + /> + + + {MODE_EXPLANATIONS[mode]} + + + + {`Within ${PREFETCH_DISTANCE} of the viewport: ${formatItemList(itemsInRange)}`} + + + {messages.length === 0 ? ( + + Nothing reported yet + + ) : ( + messages.map((message, index) => ( + + {message} + + )) + )} + + + + {Array.from({length: ITEM_COUNT}, (_, index) => { + const itemNumber = index + 1; + const isInRange = itemsInRange.has(itemNumber); + return ( + { + if (node == null) { + itemNodesRef.current.delete(itemNumber); + } else { + itemNodesRef.current.set(itemNumber, node); + } + }} + style={[ + styles.item, + {backgroundColor: theme.TertiarySystemFillColor}, + isInRange && styles.itemInRange, + ]}> + + {`#${itemNumber}`} + + + {isInRange ? `Within ${PREFETCH_DISTANCE}` : 'Out of range'} + + + ); + })} + + + ); +} + +function formatItemList(items: ReadonlySet): string { + if (items.size === 0) { + return 'none'; + } + return [...items] + .sort((a, b) => a - b) + .map(itemNumber => `#${itemNumber}`) + .join(', '); +} + +const styles = StyleSheet.create({ + container: { + padding: 10, + gap: 10, + }, + toggle: { + flexDirection: 'row', + gap: 10, + }, + explanation: { + fontSize: 13, + }, + messageArea: { + height: 150, + borderWidth: 1, + borderRadius: 5, + padding: 8, + }, + messageAreaTitle: { + fontSize: 13, + fontWeight: 'bold', + marginBottom: 5, + }, + message: { + fontSize: 12, + fontFamily: 'monospace', + }, + list: { + height: 300, + flexGrow: 0, + borderWidth: 1, + }, + item: { + height: 100, + marginVertical: 4, + marginHorizontal: 8, + borderRadius: 5, + alignItems: 'center', + justifyContent: 'center', + }, + itemInRange: { + backgroundColor: 'rgba(52, 199, 89, 0.35)', + }, + itemNumber: { + fontSize: 20, + fontWeight: 'bold', + }, +}); diff --git a/scripts/cxx-api/api-snapshots/ReactAndroidDebugCxx.api b/scripts/cxx-api/api-snapshots/ReactAndroidDebugCxx.api index b1f8d72fcfb7..e46e85e2eb47 100644 --- a/scripts/cxx-api/api-snapshots/ReactAndroidDebugCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAndroidDebugCxx.api @@ -413,6 +413,7 @@ using facebook::react::DebuggingOverlayComponentDescriptor = facebook::react::Co using facebook::react::DebuggingOverlayShadowNode = facebook::react::ConcreteViewShadowNode; using facebook::react::DebuggingOverlayState = facebook::react::StateData; using facebook::react::EdgeInsets = facebook::react::RectangleEdges; +using facebook::react::EdgeMargins = facebook::react::RectangleEdges; using facebook::react::EventListener = std::function; using facebook::react::EventPipe = std::function; using facebook::react::EventPipeConclusion = std::function; @@ -502,6 +503,7 @@ facebook::react::ColorComponents facebook::react::colorComponentsFromColor(faceb facebook::react::ColorComponents facebook::react::colorComponentsFromHostPlatformColor(facebook::react::Color color); facebook::react::ColorSpace facebook::react::getDefaultColorSpace(); facebook::react::DisplayType facebook::react::displayTypeFromYGDisplay(YGDisplay display); +facebook::react::EdgeInsets facebook::react::resolveEdgeMargins(const facebook::react::EdgeMargins& margins, const facebook::react::Size& size) noexcept; facebook::react::Float facebook::react::floatFromYogaFloat(float value); facebook::react::Float facebook::react::floatFromYogaOptionalFloat(facebook::yoga::FloatOptional value); facebook::react::LayoutMetrics facebook::react::layoutMetricsFromYogaNode(facebook::yoga::Node& yogaNode); @@ -1720,6 +1722,8 @@ class facebook::react::LayoutableShadowNode : public facebook::react::ShadowNode public virtual bool canBeTouchTarget() const; public virtual bool canChildrenBeTouchTarget() const; public virtual bool getIsLayoutClean() const = 0; + public virtual bool hasContentClip() const; + public virtual bool isScrollContainer() const; public virtual const facebook::react::LayoutableShadowNode* asLayoutable() const override; public virtual facebook::react::Float baseline(const facebook::react::LayoutContext& layoutContext, facebook::react::Size size) const; public virtual facebook::react::Point getContentOriginOffset(bool includeTransform) const; @@ -1737,6 +1741,7 @@ struct facebook::react::LayoutableShadowNode::LayoutInspectingPolicy { public bool enableOverflowClipping; public bool includeTransform; public bool includeViewportOffset; + public std::optional clipMargin; } class facebook::react::LongLivedObject { @@ -2569,6 +2574,8 @@ class facebook::react::YogaLayoutableShadowNode : public facebook::react::Layout public using ListOfShared = std::vector; public using Shared = std::shared_ptr; public virtual bool getIsLayoutClean() const override; + public virtual bool hasContentClip() const override; + public virtual bool isScrollContainer() const override; public virtual void appendChild(const std::shared_ptr& child) override; public virtual void completeClone(const facebook::react::ShadowNode&, const facebook::react::ShadowNodeFragment&) override; public virtual void dirtyLayout() override; @@ -3400,6 +3407,12 @@ struct facebook::react::LinearGradient { public std::vector colorStops; } +struct facebook::react::MarginValue { + public bool isPercentage; + public bool operator==(const facebook::react::MarginValue& rhs) const noexcept = default; + public facebook::react::Float value; +} + struct facebook::react::ModalHostViewSupportedOrientationsMaskWrapped { public facebook::react::ModalHostViewSupportedOrientationsMask value; } @@ -3940,7 +3953,7 @@ struct facebook::react::NativeIntersectionObserverNativeIntersectionObserverEntr public bool operator==(const facebook::react::NativeIntersectionObserverNativeIntersectionObserverEntry& other) const; } -template +template struct facebook::react::NativeIntersectionObserverNativeIntersectionObserverObserveOptions { public P0 intersectionObserverId; public P1 rootShadowNode; @@ -3948,6 +3961,7 @@ struct facebook::react::NativeIntersectionObserverNativeIntersectionObserverObse public P3 thresholds; public P4 rootThresholds; public P5 rootMargin; + public P6 scrollMargin; public bool operator==(const facebook::react::NativeIntersectionObserverNativeIntersectionObserverObserveOptions& other) const; } @@ -4847,6 +4861,7 @@ struct facebook::react::NativeIntersectionObserverNativeIntersectionObserverObse public static facebook::jsi::Value targetShadowNodeToJs(facebook::jsi::Runtime& rt, decltype(types.targetShadowNode) value); public static std::optional rootThresholdsToJs(facebook::jsi::Runtime& rt, decltype(types.rootThresholds) value); public static std::optional rootMarginToJs(facebook::jsi::Runtime& rt, decltype(types.rootMargin) value); + public static std::optional scrollMarginToJs(facebook::jsi::Runtime& rt, decltype(types.scrollMargin) value); public static std::optional rootShadowNodeToJs(facebook::jsi::Runtime& rt, decltype(types.rootShadowNode) value); } diff --git a/scripts/cxx-api/api-snapshots/ReactAndroidFrameworksCxx.api b/scripts/cxx-api/api-snapshots/ReactAndroidFrameworksCxx.api index 7b33432309db..605641bf27b7 100644 --- a/scripts/cxx-api/api-snapshots/ReactAndroidFrameworksCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAndroidFrameworksCxx.api @@ -520,6 +520,7 @@ using facebook::react::DebuggingOverlayShadowNode = facebook::react::ConcreteVie using facebook::react::DebuggingOverlayState = facebook::react::StateData; using facebook::react::DispatchEvent = std::function; using facebook::react::EdgeInsets = facebook::react::RectangleEdges; +using facebook::react::EdgeMargins = facebook::react::RectangleEdges; using facebook::react::EndResult = facebook::react::NativeAnimatedTurboModuleEndResult, std::optional>; using facebook::react::EventEmitterListener = facebook::react::EventListenerT; using facebook::react::EventEmitterListenerContainer = facebook::react::EventListenerContainerT; @@ -722,6 +723,7 @@ facebook::react::ColorComponents facebook::react::colorComponentsFromHostPlatfor facebook::react::ColorSpace facebook::react::getDefaultColorSpace(); facebook::react::ComponentRegistryFactory facebook::react::getDefaultComponentRegistryFactory(); facebook::react::DisplayType facebook::react::displayTypeFromYGDisplay(YGDisplay display); +facebook::react::EdgeInsets facebook::react::resolveEdgeMargins(const facebook::react::EdgeMargins& margins, const facebook::react::Size& size) noexcept; facebook::react::Float facebook::react::floatFromYogaFloat(float value); facebook::react::Float facebook::react::floatFromYogaOptionalFloat(facebook::yoga::FloatOptional value); facebook::react::LayoutMetrics facebook::react::layoutMetricsFromYogaNode(facebook::yoga::Node& yogaNode); @@ -2598,6 +2600,8 @@ class facebook::react::LayoutableShadowNode : public facebook::react::ShadowNode public virtual bool canBeTouchTarget() const; public virtual bool canChildrenBeTouchTarget() const; public virtual bool getIsLayoutClean() const = 0; + public virtual bool hasContentClip() const; + public virtual bool isScrollContainer() const; public virtual const facebook::react::LayoutableShadowNode* asLayoutable() const override; public virtual facebook::react::Float baseline(const facebook::react::LayoutContext& layoutContext, facebook::react::Size size) const; public virtual facebook::react::Point getContentOriginOffset(bool includeTransform) const; @@ -2615,6 +2619,7 @@ struct facebook::react::LayoutableShadowNode::LayoutInspectingPolicy { public bool enableOverflowClipping; public bool includeTransform; public bool includeViewportOffset; + public std::optional clipMargin; } class facebook::react::LineMeasureCacheKey { @@ -4420,6 +4425,8 @@ class facebook::react::YogaLayoutableShadowNode : public facebook::react::Layout public using ListOfShared = std::vector; public using Shared = std::shared_ptr; public virtual bool getIsLayoutClean() const override; + public virtual bool hasContentClip() const override; + public virtual bool isScrollContainer() const override; public virtual void appendChild(const std::shared_ptr& child) override; public virtual void completeClone(const facebook::react::ShadowNode&, const facebook::react::ShadowNodeFragment&) override; public virtual void dirtyLayout() override; @@ -6312,6 +6319,12 @@ struct facebook::react::Magic32 { public uint32_t value; } +struct facebook::react::MarginValue { + public bool isPercentage; + public bool operator==(const facebook::react::MarginValue& rhs) const noexcept = default; + public facebook::react::Float value; +} + struct facebook::react::MeasuredPreparedTextLayout { public facebook::react::Float pointScaleFactor; public facebook::react::LayoutConstraints layoutConstraints; @@ -7067,7 +7080,7 @@ struct facebook::react::NativeIntersectionObserverNativeIntersectionObserverEntr public bool operator==(const facebook::react::NativeIntersectionObserverNativeIntersectionObserverEntry& other) const; } -template +template struct facebook::react::NativeIntersectionObserverNativeIntersectionObserverObserveOptions { public P0 intersectionObserverId; public P1 rootShadowNode; @@ -7075,6 +7088,7 @@ struct facebook::react::NativeIntersectionObserverNativeIntersectionObserverObse public P3 thresholds; public P4 rootThresholds; public P5 rootMargin; + public P6 scrollMargin; public bool operator==(const facebook::react::NativeIntersectionObserverNativeIntersectionObserverObserveOptions& other) const; } diff --git a/scripts/cxx-api/api-snapshots/ReactAndroidNewarchCxx.api b/scripts/cxx-api/api-snapshots/ReactAndroidNewarchCxx.api index 2e76b6de8216..33b9d8fc934d 100644 --- a/scripts/cxx-api/api-snapshots/ReactAndroidNewarchCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAndroidNewarchCxx.api @@ -413,6 +413,7 @@ using facebook::react::DebuggingOverlayComponentDescriptor = facebook::react::Co using facebook::react::DebuggingOverlayShadowNode = facebook::react::ConcreteViewShadowNode; using facebook::react::DebuggingOverlayState = facebook::react::StateData; using facebook::react::EdgeInsets = facebook::react::RectangleEdges; +using facebook::react::EdgeMargins = facebook::react::RectangleEdges; using facebook::react::EventListener = std::function; using facebook::react::EventPipe = std::function; using facebook::react::EventPipeConclusion = std::function; @@ -502,6 +503,7 @@ facebook::react::ColorComponents facebook::react::colorComponentsFromColor(faceb facebook::react::ColorComponents facebook::react::colorComponentsFromHostPlatformColor(facebook::react::Color color); facebook::react::ColorSpace facebook::react::getDefaultColorSpace(); facebook::react::DisplayType facebook::react::displayTypeFromYGDisplay(YGDisplay display); +facebook::react::EdgeInsets facebook::react::resolveEdgeMargins(const facebook::react::EdgeMargins& margins, const facebook::react::Size& size) noexcept; facebook::react::Float facebook::react::floatFromYogaFloat(float value); facebook::react::Float facebook::react::floatFromYogaOptionalFloat(facebook::yoga::FloatOptional value); facebook::react::LayoutMetrics facebook::react::layoutMetricsFromYogaNode(facebook::yoga::Node& yogaNode); @@ -1719,6 +1721,8 @@ class facebook::react::LayoutableShadowNode : public facebook::react::ShadowNode public virtual bool canBeTouchTarget() const; public virtual bool canChildrenBeTouchTarget() const; public virtual bool getIsLayoutClean() const = 0; + public virtual bool hasContentClip() const; + public virtual bool isScrollContainer() const; public virtual const facebook::react::LayoutableShadowNode* asLayoutable() const override; public virtual facebook::react::Float baseline(const facebook::react::LayoutContext& layoutContext, facebook::react::Size size) const; public virtual facebook::react::Point getContentOriginOffset(bool includeTransform) const; @@ -1736,6 +1740,7 @@ struct facebook::react::LayoutableShadowNode::LayoutInspectingPolicy { public bool enableOverflowClipping; public bool includeTransform; public bool includeViewportOffset; + public std::optional clipMargin; } class facebook::react::LongLivedObject { @@ -2562,6 +2567,8 @@ class facebook::react::YogaLayoutableShadowNode : public facebook::react::Layout public using ListOfShared = std::vector; public using Shared = std::shared_ptr; public virtual bool getIsLayoutClean() const override; + public virtual bool hasContentClip() const override; + public virtual bool isScrollContainer() const override; public virtual void appendChild(const std::shared_ptr& child) override; public virtual void completeClone(const facebook::react::ShadowNode&, const facebook::react::ShadowNodeFragment&) override; public virtual void dirtyLayout() override; @@ -3393,6 +3400,12 @@ struct facebook::react::LinearGradient { public std::vector colorStops; } +struct facebook::react::MarginValue { + public bool isPercentage; + public bool operator==(const facebook::react::MarginValue& rhs) const noexcept = default; + public facebook::react::Float value; +} + struct facebook::react::ModalHostViewSupportedOrientationsMaskWrapped { public facebook::react::ModalHostViewSupportedOrientationsMask value; } @@ -3933,7 +3946,7 @@ struct facebook::react::NativeIntersectionObserverNativeIntersectionObserverEntr public bool operator==(const facebook::react::NativeIntersectionObserverNativeIntersectionObserverEntry& other) const; } -template +template struct facebook::react::NativeIntersectionObserverNativeIntersectionObserverObserveOptions { public P0 intersectionObserverId; public P1 rootShadowNode; @@ -3941,6 +3954,7 @@ struct facebook::react::NativeIntersectionObserverNativeIntersectionObserverObse public P3 thresholds; public P4 rootThresholds; public P5 rootMargin; + public P6 scrollMargin; public bool operator==(const facebook::react::NativeIntersectionObserverNativeIntersectionObserverObserveOptions& other) const; } diff --git a/scripts/cxx-api/api-snapshots/ReactAndroidReleaseCxx.api b/scripts/cxx-api/api-snapshots/ReactAndroidReleaseCxx.api index 2e76b6de8216..33b9d8fc934d 100644 --- a/scripts/cxx-api/api-snapshots/ReactAndroidReleaseCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAndroidReleaseCxx.api @@ -413,6 +413,7 @@ using facebook::react::DebuggingOverlayComponentDescriptor = facebook::react::Co using facebook::react::DebuggingOverlayShadowNode = facebook::react::ConcreteViewShadowNode; using facebook::react::DebuggingOverlayState = facebook::react::StateData; using facebook::react::EdgeInsets = facebook::react::RectangleEdges; +using facebook::react::EdgeMargins = facebook::react::RectangleEdges; using facebook::react::EventListener = std::function; using facebook::react::EventPipe = std::function; using facebook::react::EventPipeConclusion = std::function; @@ -502,6 +503,7 @@ facebook::react::ColorComponents facebook::react::colorComponentsFromColor(faceb facebook::react::ColorComponents facebook::react::colorComponentsFromHostPlatformColor(facebook::react::Color color); facebook::react::ColorSpace facebook::react::getDefaultColorSpace(); facebook::react::DisplayType facebook::react::displayTypeFromYGDisplay(YGDisplay display); +facebook::react::EdgeInsets facebook::react::resolveEdgeMargins(const facebook::react::EdgeMargins& margins, const facebook::react::Size& size) noexcept; facebook::react::Float facebook::react::floatFromYogaFloat(float value); facebook::react::Float facebook::react::floatFromYogaOptionalFloat(facebook::yoga::FloatOptional value); facebook::react::LayoutMetrics facebook::react::layoutMetricsFromYogaNode(facebook::yoga::Node& yogaNode); @@ -1719,6 +1721,8 @@ class facebook::react::LayoutableShadowNode : public facebook::react::ShadowNode public virtual bool canBeTouchTarget() const; public virtual bool canChildrenBeTouchTarget() const; public virtual bool getIsLayoutClean() const = 0; + public virtual bool hasContentClip() const; + public virtual bool isScrollContainer() const; public virtual const facebook::react::LayoutableShadowNode* asLayoutable() const override; public virtual facebook::react::Float baseline(const facebook::react::LayoutContext& layoutContext, facebook::react::Size size) const; public virtual facebook::react::Point getContentOriginOffset(bool includeTransform) const; @@ -1736,6 +1740,7 @@ struct facebook::react::LayoutableShadowNode::LayoutInspectingPolicy { public bool enableOverflowClipping; public bool includeTransform; public bool includeViewportOffset; + public std::optional clipMargin; } class facebook::react::LongLivedObject { @@ -2562,6 +2567,8 @@ class facebook::react::YogaLayoutableShadowNode : public facebook::react::Layout public using ListOfShared = std::vector; public using Shared = std::shared_ptr; public virtual bool getIsLayoutClean() const override; + public virtual bool hasContentClip() const override; + public virtual bool isScrollContainer() const override; public virtual void appendChild(const std::shared_ptr& child) override; public virtual void completeClone(const facebook::react::ShadowNode&, const facebook::react::ShadowNodeFragment&) override; public virtual void dirtyLayout() override; @@ -3393,6 +3400,12 @@ struct facebook::react::LinearGradient { public std::vector colorStops; } +struct facebook::react::MarginValue { + public bool isPercentage; + public bool operator==(const facebook::react::MarginValue& rhs) const noexcept = default; + public facebook::react::Float value; +} + struct facebook::react::ModalHostViewSupportedOrientationsMaskWrapped { public facebook::react::ModalHostViewSupportedOrientationsMask value; } @@ -3933,7 +3946,7 @@ struct facebook::react::NativeIntersectionObserverNativeIntersectionObserverEntr public bool operator==(const facebook::react::NativeIntersectionObserverNativeIntersectionObserverEntry& other) const; } -template +template struct facebook::react::NativeIntersectionObserverNativeIntersectionObserverObserveOptions { public P0 intersectionObserverId; public P1 rootShadowNode; @@ -3941,6 +3954,7 @@ struct facebook::react::NativeIntersectionObserverNativeIntersectionObserverObse public P3 thresholds; public P4 rootThresholds; public P5 rootMargin; + public P6 scrollMargin; public bool operator==(const facebook::react::NativeIntersectionObserverNativeIntersectionObserverObserveOptions& other) const; } diff --git a/scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api b/scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api index 25ee74c97f74..8d9fc1f641eb 100644 --- a/scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api @@ -3149,6 +3149,7 @@ using facebook::react::DebuggingOverlayComponentDescriptor = facebook::react::Co using facebook::react::DebuggingOverlayShadowNode = facebook::react::ConcreteViewShadowNode; using facebook::react::DebuggingOverlayState = facebook::react::StateData; using facebook::react::EdgeInsets = facebook::react::RectangleEdges; +using facebook::react::EdgeMargins = facebook::react::RectangleEdges; using facebook::react::EventEmitterCallback = std::function; using facebook::react::EventListener = std::function; using facebook::react::EventPipe = std::function; @@ -3229,6 +3230,7 @@ facebook::react::ColorComponents facebook::react::colorComponentsFromColor(faceb facebook::react::ColorComponents facebook::react::colorComponentsFromHostPlatformColor(facebook::react::Color color); facebook::react::ColorSpace facebook::react::getDefaultColorSpace(); facebook::react::DisplayType facebook::react::displayTypeFromYGDisplay(YGDisplay display); +facebook::react::EdgeInsets facebook::react::resolveEdgeMargins(const facebook::react::EdgeMargins& margins, const facebook::react::Size& size) noexcept; facebook::react::Float facebook::react::floatFromYogaFloat(float value); facebook::react::Float facebook::react::floatFromYogaOptionalFloat(facebook::yoga::FloatOptional value); facebook::react::LayoutMetrics facebook::react::layoutMetricsFromYogaNode(facebook::yoga::Node& yogaNode); @@ -3974,6 +3976,8 @@ class facebook::react::LayoutableShadowNode : public facebook::react::ShadowNode public virtual bool canBeTouchTarget() const; public virtual bool canChildrenBeTouchTarget() const; public virtual bool getIsLayoutClean() const = 0; + public virtual bool hasContentClip() const; + public virtual bool isScrollContainer() const; public virtual const facebook::react::LayoutableShadowNode* asLayoutable() const override; public virtual facebook::react::Float baseline(const facebook::react::LayoutContext& layoutContext, facebook::react::Size size) const; public virtual facebook::react::Point getContentOriginOffset(bool includeTransform) const; @@ -3991,6 +3995,7 @@ struct facebook::react::LayoutableShadowNode::LayoutInspectingPolicy { public bool enableOverflowClipping; public bool includeTransform; public bool includeViewportOffset; + public std::optional clipMargin; } class facebook::react::LongLivedObject { @@ -4715,6 +4720,8 @@ class facebook::react::YogaLayoutableShadowNode : public facebook::react::Layout public using ListOfShared = std::vector; public using Shared = std::shared_ptr; public virtual bool getIsLayoutClean() const override; + public virtual bool hasContentClip() const override; + public virtual bool isScrollContainer() const override; public virtual void appendChild(const std::shared_ptr& child) override; public virtual void completeClone(const facebook::react::ShadowNode& sourceShadowNode, const facebook::react::ShadowNodeFragment& fragment) override; public virtual void dirtyLayout() override; @@ -5408,6 +5415,12 @@ struct facebook::react::LinearGradient { public std::vector colorStops; } +struct facebook::react::MarginValue { + public bool isPercentage; + public bool operator==(const facebook::react::MarginValue& rhs) const noexcept = default; + public facebook::react::Float value; +} + struct facebook::react::ModalHostViewSupportedOrientationsMaskWrapped { public facebook::react::ModalHostViewSupportedOrientationsMask value; } @@ -5848,7 +5861,7 @@ struct facebook::react::NativeIntersectionObserverNativeIntersectionObserverEntr public bool operator==(const facebook::react::NativeIntersectionObserverNativeIntersectionObserverEntry& other) const; } -template +template struct facebook::react::NativeIntersectionObserverNativeIntersectionObserverObserveOptions { public P0 intersectionObserverId; public P1 rootShadowNode; @@ -5856,6 +5869,7 @@ struct facebook::react::NativeIntersectionObserverNativeIntersectionObserverObse public P3 thresholds; public P4 rootThresholds; public P5 rootMargin; + public P6 scrollMargin; public bool operator==(const facebook::react::NativeIntersectionObserverNativeIntersectionObserverObserveOptions& other) const; } @@ -6666,6 +6680,7 @@ struct facebook::react::NativeIntersectionObserverNativeIntersectionObserverObse public static facebook::jsi::Value targetShadowNodeToJs(facebook::jsi::Runtime& rt, decltype(types.targetShadowNode) value); public static std::optional rootThresholdsToJs(facebook::jsi::Runtime& rt, decltype(types.rootThresholds) value); public static std::optional rootMarginToJs(facebook::jsi::Runtime& rt, decltype(types.rootMargin) value); + public static std::optional scrollMarginToJs(facebook::jsi::Runtime& rt, decltype(types.scrollMargin) value); public static std::optional rootShadowNodeToJs(facebook::jsi::Runtime& rt, decltype(types.rootShadowNode) value); } diff --git a/scripts/cxx-api/api-snapshots/ReactAppleFrameworksCxx.api b/scripts/cxx-api/api-snapshots/ReactAppleFrameworksCxx.api index aeaed7df09a0..60bb773f25f6 100644 --- a/scripts/cxx-api/api-snapshots/ReactAppleFrameworksCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAppleFrameworksCxx.api @@ -3296,6 +3296,7 @@ using facebook::react::DebuggingOverlayShadowNode = facebook::react::ConcreteVie using facebook::react::DebuggingOverlayState = facebook::react::StateData; using facebook::react::DispatchEvent = std::function; using facebook::react::EdgeInsets = facebook::react::RectangleEdges; +using facebook::react::EdgeMargins = facebook::react::RectangleEdges; using facebook::react::EndResult = facebook::react::NativeAnimatedTurboModuleEndResult, std::optional>; using facebook::react::EventEmitterCallback = std::function; using facebook::react::EventEmitterListener = facebook::react::EventListenerT; @@ -3490,6 +3491,7 @@ facebook::react::ColorComponents facebook::react::colorComponentsFromHostPlatfor facebook::react::ColorSpace facebook::react::getDefaultColorSpace(); facebook::react::ComponentRegistryFactory facebook::react::getDefaultComponentRegistryFactory(); facebook::react::DisplayType facebook::react::displayTypeFromYGDisplay(YGDisplay display); +facebook::react::EdgeInsets facebook::react::resolveEdgeMargins(const facebook::react::EdgeMargins& margins, const facebook::react::Size& size) noexcept; facebook::react::Float facebook::react::floatFromYogaFloat(float value); facebook::react::Float facebook::react::floatFromYogaOptionalFloat(facebook::yoga::FloatOptional value); facebook::react::LayoutMetrics facebook::react::layoutMetricsFromYogaNode(facebook::yoga::Node& yogaNode); @@ -4784,6 +4786,8 @@ class facebook::react::LayoutableShadowNode : public facebook::react::ShadowNode public virtual bool canBeTouchTarget() const; public virtual bool canChildrenBeTouchTarget() const; public virtual bool getIsLayoutClean() const = 0; + public virtual bool hasContentClip() const; + public virtual bool isScrollContainer() const; public virtual const facebook::react::LayoutableShadowNode* asLayoutable() const override; public virtual facebook::react::Float baseline(const facebook::react::LayoutContext& layoutContext, facebook::react::Size size) const; public virtual facebook::react::Point getContentOriginOffset(bool includeTransform) const; @@ -4801,6 +4805,7 @@ struct facebook::react::LayoutableShadowNode::LayoutInspectingPolicy { public bool enableOverflowClipping; public bool includeTransform; public bool includeViewportOffset; + public std::optional clipMargin; } class facebook::react::LineMeasureCacheKey { @@ -6540,6 +6545,8 @@ class facebook::react::YogaLayoutableShadowNode : public facebook::react::Layout public using ListOfShared = std::vector; public using Shared = std::shared_ptr; public virtual bool getIsLayoutClean() const override; + public virtual bool hasContentClip() const override; + public virtual bool isScrollContainer() const override; public virtual void appendChild(const std::shared_ptr& child) override; public virtual void completeClone(const facebook::react::ShadowNode& sourceShadowNode, const facebook::react::ShadowNodeFragment& fragment) override; public virtual void dirtyLayout() override; @@ -8335,6 +8342,12 @@ struct facebook::react::Magic32 { public uint32_t value; } +struct facebook::react::MarginValue { + public bool isPercentage; + public bool operator==(const facebook::react::MarginValue& rhs) const noexcept = default; + public facebook::react::Float value; +} + struct facebook::react::MeasuredPreparedTextLayout { public facebook::react::Float pointScaleFactor; public facebook::react::LayoutConstraints layoutConstraints; @@ -8990,7 +9003,7 @@ struct facebook::react::NativeIntersectionObserverNativeIntersectionObserverEntr public bool operator==(const facebook::react::NativeIntersectionObserverNativeIntersectionObserverEntry& other) const; } -template +template struct facebook::react::NativeIntersectionObserverNativeIntersectionObserverObserveOptions { public P0 intersectionObserverId; public P1 rootShadowNode; @@ -8998,6 +9011,7 @@ struct facebook::react::NativeIntersectionObserverNativeIntersectionObserverObse public P3 thresholds; public P4 rootThresholds; public P5 rootMargin; + public P6 scrollMargin; public bool operator==(const facebook::react::NativeIntersectionObserverNativeIntersectionObserverObserveOptions& other) const; } diff --git a/scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api b/scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api index d505b7fcfd0d..b854863987d6 100644 --- a/scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api @@ -3142,6 +3142,7 @@ using facebook::react::DebuggingOverlayComponentDescriptor = facebook::react::Co using facebook::react::DebuggingOverlayShadowNode = facebook::react::ConcreteViewShadowNode; using facebook::react::DebuggingOverlayState = facebook::react::StateData; using facebook::react::EdgeInsets = facebook::react::RectangleEdges; +using facebook::react::EdgeMargins = facebook::react::RectangleEdges; using facebook::react::EventEmitterCallback = std::function; using facebook::react::EventListener = std::function; using facebook::react::EventPipe = std::function; @@ -3222,6 +3223,7 @@ facebook::react::ColorComponents facebook::react::colorComponentsFromColor(faceb facebook::react::ColorComponents facebook::react::colorComponentsFromHostPlatformColor(facebook::react::Color color); facebook::react::ColorSpace facebook::react::getDefaultColorSpace(); facebook::react::DisplayType facebook::react::displayTypeFromYGDisplay(YGDisplay display); +facebook::react::EdgeInsets facebook::react::resolveEdgeMargins(const facebook::react::EdgeMargins& margins, const facebook::react::Size& size) noexcept; facebook::react::Float facebook::react::floatFromYogaFloat(float value); facebook::react::Float facebook::react::floatFromYogaOptionalFloat(facebook::yoga::FloatOptional value); facebook::react::LayoutMetrics facebook::react::layoutMetricsFromYogaNode(facebook::yoga::Node& yogaNode); @@ -3966,6 +3968,8 @@ class facebook::react::LayoutableShadowNode : public facebook::react::ShadowNode public virtual bool canBeTouchTarget() const; public virtual bool canChildrenBeTouchTarget() const; public virtual bool getIsLayoutClean() const = 0; + public virtual bool hasContentClip() const; + public virtual bool isScrollContainer() const; public virtual const facebook::react::LayoutableShadowNode* asLayoutable() const override; public virtual facebook::react::Float baseline(const facebook::react::LayoutContext& layoutContext, facebook::react::Size size) const; public virtual facebook::react::Point getContentOriginOffset(bool includeTransform) const; @@ -3983,6 +3987,7 @@ struct facebook::react::LayoutableShadowNode::LayoutInspectingPolicy { public bool enableOverflowClipping; public bool includeTransform; public bool includeViewportOffset; + public std::optional clipMargin; } class facebook::react::LongLivedObject { @@ -4701,6 +4706,8 @@ class facebook::react::YogaLayoutableShadowNode : public facebook::react::Layout public using ListOfShared = std::vector; public using Shared = std::shared_ptr; public virtual bool getIsLayoutClean() const override; + public virtual bool hasContentClip() const override; + public virtual bool isScrollContainer() const override; public virtual void appendChild(const std::shared_ptr& child) override; public virtual void completeClone(const facebook::react::ShadowNode& sourceShadowNode, const facebook::react::ShadowNodeFragment& fragment) override; public virtual void dirtyLayout() override; @@ -5394,6 +5401,12 @@ struct facebook::react::LinearGradient { public std::vector colorStops; } +struct facebook::react::MarginValue { + public bool isPercentage; + public bool operator==(const facebook::react::MarginValue& rhs) const noexcept = default; + public facebook::react::Float value; +} + struct facebook::react::ModalHostViewSupportedOrientationsMaskWrapped { public facebook::react::ModalHostViewSupportedOrientationsMask value; } @@ -5834,7 +5847,7 @@ struct facebook::react::NativeIntersectionObserverNativeIntersectionObserverEntr public bool operator==(const facebook::react::NativeIntersectionObserverNativeIntersectionObserverEntry& other) const; } -template +template struct facebook::react::NativeIntersectionObserverNativeIntersectionObserverObserveOptions { public P0 intersectionObserverId; public P1 rootShadowNode; @@ -5842,6 +5855,7 @@ struct facebook::react::NativeIntersectionObserverNativeIntersectionObserverObse public P3 thresholds; public P4 rootThresholds; public P5 rootMargin; + public P6 scrollMargin; public bool operator==(const facebook::react::NativeIntersectionObserverNativeIntersectionObserverObserveOptions& other) const; } diff --git a/scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api b/scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api index 3feedc079438..3830eb00b87a 100644 --- a/scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api @@ -3149,6 +3149,7 @@ using facebook::react::DebuggingOverlayComponentDescriptor = facebook::react::Co using facebook::react::DebuggingOverlayShadowNode = facebook::react::ConcreteViewShadowNode; using facebook::react::DebuggingOverlayState = facebook::react::StateData; using facebook::react::EdgeInsets = facebook::react::RectangleEdges; +using facebook::react::EdgeMargins = facebook::react::RectangleEdges; using facebook::react::EventEmitterCallback = std::function; using facebook::react::EventListener = std::function; using facebook::react::EventPipe = std::function; @@ -3229,6 +3230,7 @@ facebook::react::ColorComponents facebook::react::colorComponentsFromColor(faceb facebook::react::ColorComponents facebook::react::colorComponentsFromHostPlatformColor(facebook::react::Color color); facebook::react::ColorSpace facebook::react::getDefaultColorSpace(); facebook::react::DisplayType facebook::react::displayTypeFromYGDisplay(YGDisplay display); +facebook::react::EdgeInsets facebook::react::resolveEdgeMargins(const facebook::react::EdgeMargins& margins, const facebook::react::Size& size) noexcept; facebook::react::Float facebook::react::floatFromYogaFloat(float value); facebook::react::Float facebook::react::floatFromYogaOptionalFloat(facebook::yoga::FloatOptional value); facebook::react::LayoutMetrics facebook::react::layoutMetricsFromYogaNode(facebook::yoga::Node& yogaNode); @@ -3973,6 +3975,8 @@ class facebook::react::LayoutableShadowNode : public facebook::react::ShadowNode public virtual bool canBeTouchTarget() const; public virtual bool canChildrenBeTouchTarget() const; public virtual bool getIsLayoutClean() const = 0; + public virtual bool hasContentClip() const; + public virtual bool isScrollContainer() const; public virtual const facebook::react::LayoutableShadowNode* asLayoutable() const override; public virtual facebook::react::Float baseline(const facebook::react::LayoutContext& layoutContext, facebook::react::Size size) const; public virtual facebook::react::Point getContentOriginOffset(bool includeTransform) const; @@ -3990,6 +3994,7 @@ struct facebook::react::LayoutableShadowNode::LayoutInspectingPolicy { public bool enableOverflowClipping; public bool includeTransform; public bool includeViewportOffset; + public std::optional clipMargin; } class facebook::react::LongLivedObject { @@ -4708,6 +4713,8 @@ class facebook::react::YogaLayoutableShadowNode : public facebook::react::Layout public using ListOfShared = std::vector; public using Shared = std::shared_ptr; public virtual bool getIsLayoutClean() const override; + public virtual bool hasContentClip() const override; + public virtual bool isScrollContainer() const override; public virtual void appendChild(const std::shared_ptr& child) override; public virtual void completeClone(const facebook::react::ShadowNode& sourceShadowNode, const facebook::react::ShadowNodeFragment& fragment) override; public virtual void dirtyLayout() override; @@ -5401,6 +5408,12 @@ struct facebook::react::LinearGradient { public std::vector colorStops; } +struct facebook::react::MarginValue { + public bool isPercentage; + public bool operator==(const facebook::react::MarginValue& rhs) const noexcept = default; + public facebook::react::Float value; +} + struct facebook::react::ModalHostViewSupportedOrientationsMaskWrapped { public facebook::react::ModalHostViewSupportedOrientationsMask value; } @@ -5841,7 +5854,7 @@ struct facebook::react::NativeIntersectionObserverNativeIntersectionObserverEntr public bool operator==(const facebook::react::NativeIntersectionObserverNativeIntersectionObserverEntry& other) const; } -template +template struct facebook::react::NativeIntersectionObserverNativeIntersectionObserverObserveOptions { public P0 intersectionObserverId; public P1 rootShadowNode; @@ -5849,6 +5862,7 @@ struct facebook::react::NativeIntersectionObserverNativeIntersectionObserverObse public P3 thresholds; public P4 rootThresholds; public P5 rootMargin; + public P6 scrollMargin; public bool operator==(const facebook::react::NativeIntersectionObserverNativeIntersectionObserverObserveOptions& other) const; } diff --git a/scripts/cxx-api/api-snapshots/ReactCommonDebugCxx.api b/scripts/cxx-api/api-snapshots/ReactCommonDebugCxx.api index 55ec0d0a6ff4..681456c5fde4 100644 --- a/scripts/cxx-api/api-snapshots/ReactCommonDebugCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactCommonDebugCxx.api @@ -99,6 +99,7 @@ using facebook::react::ComponentHandle = int64_t; using facebook::react::ComponentName = const char*; using facebook::react::CornerInsets = facebook::react::RectangleCorners; using facebook::react::EdgeInsets = facebook::react::RectangleEdges; +using facebook::react::EdgeMargins = facebook::react::RectangleEdges; using facebook::react::EventListener = std::function; using facebook::react::EventPipe = std::function; using facebook::react::EventPipeConclusion = std::function; @@ -166,6 +167,7 @@ facebook::jsi::Value facebook::react::createPromiseAsJSIValue(facebook::jsi::Run facebook::react::ColorComponents facebook::react::colorComponentsFromColor(facebook::react::SharedColor color); facebook::react::ColorSpace facebook::react::getDefaultColorSpace(); facebook::react::DisplayType facebook::react::displayTypeFromYGDisplay(YGDisplay display); +facebook::react::EdgeInsets facebook::react::resolveEdgeMargins(const facebook::react::EdgeMargins& margins, const facebook::react::Size& size) noexcept; facebook::react::LayoutMetrics facebook::react::layoutMetricsFromYogaNode(facebook::yoga::Node& yogaNode); facebook::react::Rect facebook::react::insetBy(const facebook::react::Rect& rect, const facebook::react::EdgeInsets& insets) noexcept; facebook::react::Rect facebook::react::outsetBy(const facebook::react::Rect& rect, const facebook::react::EdgeInsets& outsets) noexcept; @@ -843,6 +845,8 @@ class facebook::react::LayoutableShadowNode : public facebook::react::ShadowNode public virtual bool canBeTouchTarget() const; public virtual bool canChildrenBeTouchTarget() const; public virtual bool getIsLayoutClean() const = 0; + public virtual bool hasContentClip() const; + public virtual bool isScrollContainer() const; public virtual const facebook::react::LayoutableShadowNode* asLayoutable() const override; public virtual facebook::react::Point getContentOriginOffset(bool includeTransform) const; public virtual facebook::react::Size measure(const facebook::react::LayoutContext& layoutContext, const facebook::react::LayoutConstraints& layoutConstraints) const; @@ -859,6 +863,7 @@ struct facebook::react::LayoutableShadowNode::LayoutInspectingPolicy { public bool enableOverflowClipping; public bool includeTransform; public bool includeViewportOffset; + public std::optional clipMargin; } class facebook::react::LongLivedObject { @@ -1226,6 +1231,8 @@ class facebook::react::YogaLayoutableShadowNode : public facebook::react::Layout public using ListOfShared = std::vector; public using Shared = std::shared_ptr; public virtual bool getIsLayoutClean() const override; + public virtual bool hasContentClip() const override; + public virtual bool isScrollContainer() const override; public virtual void appendChild(const std::shared_ptr& child) override; public virtual void completeClone(const facebook::react::ShadowNode&, const facebook::react::ShadowNodeFragment&) override; public virtual void dirtyLayout() override; @@ -1852,6 +1859,12 @@ struct facebook::react::LinearGradient { public std::vector colorStops; } +struct facebook::react::MarginValue { + public Float value; + public bool isPercentage; + public bool operator==(const facebook::react::MarginValue& rhs) const noexcept = default; +} + struct facebook::react::Point { public Float x; public Float y; diff --git a/scripts/cxx-api/api-snapshots/ReactCommonFrameworksCxx.api b/scripts/cxx-api/api-snapshots/ReactCommonFrameworksCxx.api index 4c05ab7f6cec..3719c767cd99 100644 --- a/scripts/cxx-api/api-snapshots/ReactCommonFrameworksCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactCommonFrameworksCxx.api @@ -145,6 +145,7 @@ using facebook::react::ComponentRegistryFactory = std::function; using facebook::react::DispatchEvent = std::function; using facebook::react::EdgeInsets = facebook::react::RectangleEdges; +using facebook::react::EdgeMargins = facebook::react::RectangleEdges; using facebook::react::EndResult = NativeAnimatedTurboModuleEndResult, std::optional>; using facebook::react::EventEmitterListener = facebook::react::EventListenerT; using facebook::react::EventEmitterListenerContainer = facebook::react::EventListenerContainerT; @@ -325,6 +326,7 @@ facebook::react::ColorComponents facebook::react::colorComponentsFromColor(faceb facebook::react::ColorSpace facebook::react::getDefaultColorSpace(); facebook::react::ComponentRegistryFactory facebook::react::getDefaultComponentRegistryFactory(); facebook::react::DisplayType facebook::react::displayTypeFromYGDisplay(YGDisplay display); +facebook::react::EdgeInsets facebook::react::resolveEdgeMargins(const facebook::react::EdgeMargins& margins, const facebook::react::Size& size) noexcept; facebook::react::LayoutMetrics facebook::react::layoutMetricsFromYogaNode(facebook::yoga::Node& yogaNode); facebook::react::ParagraphAttributes facebook::react::convertRawProp(const facebook::react::PropsParserContext& context, const facebook::react::RawProps& rawProps, const facebook::react::ParagraphAttributes& sourceParagraphAttributes, const facebook::react::ParagraphAttributes& defaultParagraphAttributes); facebook::react::Rect facebook::react::insetBy(const facebook::react::Rect& rect, const facebook::react::EdgeInsets& insets) noexcept; @@ -1528,6 +1530,8 @@ class facebook::react::LayoutableShadowNode : public facebook::react::ShadowNode public virtual bool canBeTouchTarget() const; public virtual bool canChildrenBeTouchTarget() const; public virtual bool getIsLayoutClean() const = 0; + public virtual bool hasContentClip() const; + public virtual bool isScrollContainer() const; public virtual const facebook::react::LayoutableShadowNode* asLayoutable() const override; public virtual facebook::react::Point getContentOriginOffset(bool includeTransform) const; public virtual facebook::react::Size measure(const facebook::react::LayoutContext& layoutContext, const facebook::react::LayoutConstraints& layoutConstraints) const; @@ -1544,6 +1548,7 @@ struct facebook::react::LayoutableShadowNode::LayoutInspectingPolicy { public bool enableOverflowClipping; public bool includeTransform; public bool includeViewportOffset; + public std::optional clipMargin; } class facebook::react::LineMeasureCacheKey { @@ -2839,6 +2844,8 @@ class facebook::react::YogaLayoutableShadowNode : public facebook::react::Layout public using ListOfShared = std::vector; public using Shared = std::shared_ptr; public virtual bool getIsLayoutClean() const override; + public virtual bool hasContentClip() const override; + public virtual bool isScrollContainer() const override; public virtual void appendChild(const std::shared_ptr& child) override; public virtual void completeClone(const facebook::react::ShadowNode&, const facebook::react::ShadowNodeFragment&) override; public virtual void dirtyLayout() override; @@ -4513,6 +4520,12 @@ struct facebook::react::Magic32 { public uint32_t value; } +struct facebook::react::MarginValue { + public Float value; + public bool isPercentage; + public bool operator==(const facebook::react::MarginValue& rhs) const noexcept = default; +} + struct facebook::react::MeasuredPreparedTextLayout { public Float pointScaleFactor; public facebook::react::LayoutConstraints layoutConstraints; diff --git a/scripts/cxx-api/api-snapshots/ReactCommonNewarchCxx.api b/scripts/cxx-api/api-snapshots/ReactCommonNewarchCxx.api index e988c59a3228..23f96dfb7519 100644 --- a/scripts/cxx-api/api-snapshots/ReactCommonNewarchCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactCommonNewarchCxx.api @@ -99,6 +99,7 @@ using facebook::react::ComponentHandle = int64_t; using facebook::react::ComponentName = const char*; using facebook::react::CornerInsets = facebook::react::RectangleCorners; using facebook::react::EdgeInsets = facebook::react::RectangleEdges; +using facebook::react::EdgeMargins = facebook::react::RectangleEdges; using facebook::react::EventListener = std::function; using facebook::react::EventPipe = std::function; using facebook::react::EventPipeConclusion = std::function; @@ -166,6 +167,7 @@ facebook::jsi::Value facebook::react::createPromiseAsJSIValue(facebook::jsi::Run facebook::react::ColorComponents facebook::react::colorComponentsFromColor(facebook::react::SharedColor color); facebook::react::ColorSpace facebook::react::getDefaultColorSpace(); facebook::react::DisplayType facebook::react::displayTypeFromYGDisplay(YGDisplay display); +facebook::react::EdgeInsets facebook::react::resolveEdgeMargins(const facebook::react::EdgeMargins& margins, const facebook::react::Size& size) noexcept; facebook::react::LayoutMetrics facebook::react::layoutMetricsFromYogaNode(facebook::yoga::Node& yogaNode); facebook::react::Rect facebook::react::insetBy(const facebook::react::Rect& rect, const facebook::react::EdgeInsets& insets) noexcept; facebook::react::Rect facebook::react::outsetBy(const facebook::react::Rect& rect, const facebook::react::EdgeInsets& outsets) noexcept; @@ -842,6 +844,8 @@ class facebook::react::LayoutableShadowNode : public facebook::react::ShadowNode public virtual bool canBeTouchTarget() const; public virtual bool canChildrenBeTouchTarget() const; public virtual bool getIsLayoutClean() const = 0; + public virtual bool hasContentClip() const; + public virtual bool isScrollContainer() const; public virtual const facebook::react::LayoutableShadowNode* asLayoutable() const override; public virtual facebook::react::Point getContentOriginOffset(bool includeTransform) const; public virtual facebook::react::Size measure(const facebook::react::LayoutContext& layoutContext, const facebook::react::LayoutConstraints& layoutConstraints) const; @@ -858,6 +862,7 @@ struct facebook::react::LayoutableShadowNode::LayoutInspectingPolicy { public bool enableOverflowClipping; public bool includeTransform; public bool includeViewportOffset; + public std::optional clipMargin; } class facebook::react::LongLivedObject { @@ -1219,6 +1224,8 @@ class facebook::react::YogaLayoutableShadowNode : public facebook::react::Layout public using ListOfShared = std::vector; public using Shared = std::shared_ptr; public virtual bool getIsLayoutClean() const override; + public virtual bool hasContentClip() const override; + public virtual bool isScrollContainer() const override; public virtual void appendChild(const std::shared_ptr& child) override; public virtual void completeClone(const facebook::react::ShadowNode&, const facebook::react::ShadowNodeFragment&) override; public virtual void dirtyLayout() override; @@ -1845,6 +1852,12 @@ struct facebook::react::LinearGradient { public std::vector colorStops; } +struct facebook::react::MarginValue { + public Float value; + public bool isPercentage; + public bool operator==(const facebook::react::MarginValue& rhs) const noexcept = default; +} + struct facebook::react::Point { public Float x; public Float y; diff --git a/scripts/cxx-api/api-snapshots/ReactCommonReleaseCxx.api b/scripts/cxx-api/api-snapshots/ReactCommonReleaseCxx.api index e988c59a3228..23f96dfb7519 100644 --- a/scripts/cxx-api/api-snapshots/ReactCommonReleaseCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactCommonReleaseCxx.api @@ -99,6 +99,7 @@ using facebook::react::ComponentHandle = int64_t; using facebook::react::ComponentName = const char*; using facebook::react::CornerInsets = facebook::react::RectangleCorners; using facebook::react::EdgeInsets = facebook::react::RectangleEdges; +using facebook::react::EdgeMargins = facebook::react::RectangleEdges; using facebook::react::EventListener = std::function; using facebook::react::EventPipe = std::function; using facebook::react::EventPipeConclusion = std::function; @@ -166,6 +167,7 @@ facebook::jsi::Value facebook::react::createPromiseAsJSIValue(facebook::jsi::Run facebook::react::ColorComponents facebook::react::colorComponentsFromColor(facebook::react::SharedColor color); facebook::react::ColorSpace facebook::react::getDefaultColorSpace(); facebook::react::DisplayType facebook::react::displayTypeFromYGDisplay(YGDisplay display); +facebook::react::EdgeInsets facebook::react::resolveEdgeMargins(const facebook::react::EdgeMargins& margins, const facebook::react::Size& size) noexcept; facebook::react::LayoutMetrics facebook::react::layoutMetricsFromYogaNode(facebook::yoga::Node& yogaNode); facebook::react::Rect facebook::react::insetBy(const facebook::react::Rect& rect, const facebook::react::EdgeInsets& insets) noexcept; facebook::react::Rect facebook::react::outsetBy(const facebook::react::Rect& rect, const facebook::react::EdgeInsets& outsets) noexcept; @@ -842,6 +844,8 @@ class facebook::react::LayoutableShadowNode : public facebook::react::ShadowNode public virtual bool canBeTouchTarget() const; public virtual bool canChildrenBeTouchTarget() const; public virtual bool getIsLayoutClean() const = 0; + public virtual bool hasContentClip() const; + public virtual bool isScrollContainer() const; public virtual const facebook::react::LayoutableShadowNode* asLayoutable() const override; public virtual facebook::react::Point getContentOriginOffset(bool includeTransform) const; public virtual facebook::react::Size measure(const facebook::react::LayoutContext& layoutContext, const facebook::react::LayoutConstraints& layoutConstraints) const; @@ -858,6 +862,7 @@ struct facebook::react::LayoutableShadowNode::LayoutInspectingPolicy { public bool enableOverflowClipping; public bool includeTransform; public bool includeViewportOffset; + public std::optional clipMargin; } class facebook::react::LongLivedObject { @@ -1219,6 +1224,8 @@ class facebook::react::YogaLayoutableShadowNode : public facebook::react::Layout public using ListOfShared = std::vector; public using Shared = std::shared_ptr; public virtual bool getIsLayoutClean() const override; + public virtual bool hasContentClip() const override; + public virtual bool isScrollContainer() const override; public virtual void appendChild(const std::shared_ptr& child) override; public virtual void completeClone(const facebook::react::ShadowNode&, const facebook::react::ShadowNodeFragment&) override; public virtual void dirtyLayout() override; @@ -1845,6 +1852,12 @@ struct facebook::react::LinearGradient { public std::vector colorStops; } +struct facebook::react::MarginValue { + public Float value; + public bool isPercentage; + public bool operator==(const facebook::react::MarginValue& rhs) const noexcept = default; +} + struct facebook::react::Point { public Float x; public Float y;