@@ -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+
174194bool 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(
629650void 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 ();
0 commit comments