Skip to content

Commit 206c4ee

Browse files
authored
Fix selectable text not receiving pointer events inside ScrollView (#15577)
* Fix selectable text not working inside ScrollView * Change files
1 parent 7bfa8bf commit 206c4ee

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Fix selectable text not working inside ScrollView",
4+
"packageName": "react-native-windows",
5+
"email": "74712637+iamAbhi-916@users.noreply.github.com",
6+
"dependentChangeType": "patch"
7+
}

vnext/Microsoft.ReactNative/Fabric/Composition/ParagraphComponentView.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,26 @@ void ParagraphComponentView::updateTextAlignment(
171171
m_textLayout = nullptr;
172172
}
173173

174+
facebook::react::Tag ParagraphComponentView::hitTest(
175+
facebook::react::Point pt,
176+
facebook::react::Point &localPt,
177+
bool ignorePointerEvents) const noexcept {
178+
facebook::react::Point ptLocal{pt.x - m_layoutMetrics.frame.origin.x, pt.y - m_layoutMetrics.frame.origin.y};
179+
const auto &props = paragraphProps();
180+
const auto &vProps = *viewProps();
181+
182+
if (props.isSelectable && ptLocal.x >= 0 && ptLocal.x <= m_layoutMetrics.frame.size.width && ptLocal.y >= 0 &&
183+
ptLocal.y <= m_layoutMetrics.frame.size.height) {
184+
// claims if pointer events are enabled for this component
185+
if (ignorePointerEvents || vProps.pointerEvents == facebook::react::PointerEventsMode::Auto ||
186+
vProps.pointerEvents == facebook::react::PointerEventsMode::BoxOnly) {
187+
localPt = ptLocal;
188+
return Tag();
189+
}
190+
}
191+
return Super::hitTest(pt, localPt, ignorePointerEvents);
192+
}
193+
174194
bool ParagraphComponentView::IsTextSelectableAtPoint(facebook::react::Point pt) noexcept {
175195
// paragraph-level selectable prop is enabled
176196
const auto &props = paragraphProps();
@@ -543,7 +563,8 @@ void ParagraphComponentView::OnPointerPressed(
543563
return;
544564
}
545565

546-
auto pp = args.GetCurrentPoint(-1);
566+
// Use Tag() to get coordinates in component's local space
567+
auto pp = args.GetCurrentPoint(static_cast<int32_t>(Tag()));
547568

548569
// Ignores right-click
549570
if (pp.Properties().PointerUpdateKind() ==
@@ -554,8 +575,8 @@ void ParagraphComponentView::OnPointerPressed(
554575

555576
auto position = pp.Position();
556577

557-
facebook::react::Point localPt{
558-
position.X - m_layoutMetrics.frame.origin.x, position.Y - m_layoutMetrics.frame.origin.y};
578+
// GetCurrentPoint(Tag()) returns position relative to component origin
579+
facebook::react::Point localPt{position.X, position.Y};
559580

560581
std::optional<int32_t> charPosition = GetTextPositionAtPoint(localPt);
561582

@@ -629,7 +650,7 @@ void ParagraphComponentView::OnPointerMoved(
629650
void ParagraphComponentView::OnPointerReleased(
630651
const winrt::Microsoft::ReactNative::Composition::Input::PointerRoutedEventArgs &args) noexcept {
631652
// Check for right-click to show context menu
632-
auto pp = args.GetCurrentPoint(-1);
653+
auto pp = args.GetCurrentPoint(static_cast<int32_t>(Tag()));
633654
if (pp.Properties().PointerUpdateKind() ==
634655
winrt::Microsoft::ReactNative::Composition::Input::PointerUpdateKind::RightButtonReleased) {
635656
const auto &props = paragraphProps();

vnext/Microsoft.ReactNative/Fabric/Composition/ParagraphComponentView.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ struct ParagraphComponentView : ParagraphComponentViewT<ParagraphComponentView,
4949
static facebook::react::SharedViewProps defaultProps() noexcept;
5050
const facebook::react::ParagraphProps &paragraphProps() const noexcept;
5151

52+
facebook::react::Tag hitTest(
53+
facebook::react::Point pt,
54+
facebook::react::Point &localPt,
55+
bool ignorePointerEvents = false) const noexcept override;
56+
5257
// Returns true when text is selectable
5358
bool focusable() const noexcept override;
5459

0 commit comments

Comments
 (0)