Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,34 @@ describe('<ScrollView>', () => {
});
});

describe('hitSlop', () => {
it('widens parent overflowInset when hitSlop extends past parent', () => {
const root = Fantom.createRoot();

Fantom.runTask(() => {
root.render(
<View collapsable={false} style={{width: 100, height: 100}}>
<ScrollView
hitSlop={{top: 10, left: 20, bottom: 70, right: 80}}
style={{width: 40, height: 40}}
/>
</View>,
);
});

const parent = root
.getRenderedOutput({
includeLayoutMetrics: true,
props: ['^layoutMetrics-overflowInset$'],
})
.toJSONObject();

expect(parent.props['layoutMetrics-overflowInset']).toBe(
'{top:-10,right:-20,bottom:-10,left:-20}',
);
});
});

describe('ref', () => {
it('receives an instance or null', () => {
const root = Fantom.createRoot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <react/featureflags/ReactNativeFeatureFlags.h>
#include <react/renderer/components/view/LayoutConformanceShadowNode.h>
#include <react/renderer/components/view/ViewProps.h>
#include <react/renderer/components/view/ViewShadowNode.h>
#include <react/renderer/components/view/conversions.h>
#include <react/renderer/core/ComponentDescriptor.h>
#include <react/renderer/core/LayoutConstraints.h>
Expand Down Expand Up @@ -892,14 +891,8 @@ Rect YogaLayoutableShadowNode::getContentBounds() const {

auto layoutMetricsWithOverflowInset = childNode.getLayoutMetrics();
if (layoutMetricsWithOverflowInset.displayType != DisplayType::None) {
// ViewShadowNode is final, so comparing component handles is equivalent
// to a `dynamic_cast`, without its cost for every non-View child.
auto viewChildNode =
childNode.getComponentHandle() == ViewShadowNode::Handle()
? static_cast<const ViewShadowNode*>(&childNode)
: nullptr;
auto hitSlop = viewChildNode != nullptr
? viewChildNode->getConcreteProps().hitSlop
auto hitSlop = childNode.getTraits().check(ShadowNodeTraits::ViewKind)
? static_cast<const ViewProps&>(*childNode.getProps()).hitSlop
: EdgeInsets{};

// The contentBounds should always union with existing child node layout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
#include <react/renderer/components/root/RootComponentDescriptor.h>
#include <react/renderer/components/scrollview/ScrollViewShadowNode.h>
#include <react/renderer/components/view/ViewComponentDescriptor.h>
#include <react/renderer/element/ComponentBuilder.h>
#include <react/renderer/element/Element.h>
Expand Down Expand Up @@ -444,4 +445,60 @@ TEST_F(LayoutTest, overflowInsetHitSlopTransformTranslateTest) {
EXPECT_EQ(layoutMetricsABC.overflowInset.bottom, 0);
}

TEST_F(LayoutTest, overflowInsetScrollViewHitSlopTest) {
std::shared_ptr<RootShadowNode> rootShadowNode;
std::shared_ptr<ViewShadowNode> viewShadowNode;

// clang-format off
auto element =
Element<RootShadowNode>()
.reference(rootShadowNode)
.tag(1)
.props([] {
auto sharedProps = std::make_shared<RootProps>();
auto &props = *sharedProps;
props.layoutConstraints = LayoutConstraints{
.minimumSize = {.width = 0, .height = 0},
.maximumSize = {.width = 500, .height = 500}};
props.yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleSizeLength::points(200));
props.yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleSizeLength::points(200));
return sharedProps;
})
.children({
Element<ViewShadowNode>()
.reference(viewShadowNode)
.tag(2)
.props([] {
auto sharedProps = std::make_shared<ViewProps>();
auto &props = *sharedProps;
props.yogaStyle.setPositionType(yoga::PositionType::Absolute);
props.yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleSizeLength::points(100));
props.yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleSizeLength::points(100));
return sharedProps;
})
.children({
Element<ScrollViewShadowNode>()
.tag(3)
.props([] {
auto sharedProps = std::make_shared<ScrollViewProps>();
auto &props = *sharedProps;
props.yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleSizeLength::points(40));
props.yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleSizeLength::points(40));
props.hitSlop = EdgeInsets{.left = 20, .top = 10, .right = 80, .bottom = 70};
return sharedProps;
})
})
});
// clang-format on

builder_.build(element);
rootShadowNode->layoutIfNeeded();

auto layoutMetrics = viewShadowNode->getLayoutMetrics();
EXPECT_EQ(layoutMetrics.overflowInset.left, -20);
EXPECT_EQ(layoutMetrics.overflowInset.top, -10);
EXPECT_EQ(layoutMetrics.overflowInset.right, -20);
EXPECT_EQ(layoutMetrics.overflowInset.bottom, -10);
}

} // namespace facebook::react
Loading