@@ -167,6 +167,26 @@ void ParagraphComponentView::updateTextAlignment(
167167 m_textLayout = nullptr ;
168168}
169169
170+ facebook::react::Tag ParagraphComponentView::hitTest (
171+ facebook::react::Point pt,
172+ facebook::react::Point &localPt,
173+ bool ignorePointerEvents) const noexcept {
174+ facebook::react::Point ptLocal{pt.x - m_layoutMetrics.frame .origin .x , pt.y - m_layoutMetrics.frame .origin .y };
175+ const auto &props = paragraphProps ();
176+ const auto &vProps = *viewProps ();
177+
178+ if (props.isSelectable && ptLocal.x >= 0 && ptLocal.x <= m_layoutMetrics.frame .size .width && ptLocal.y >= 0 &&
179+ ptLocal.y <= m_layoutMetrics.frame .size .height ) {
180+ // claims if pointer events are enabled for this component
181+ if (ignorePointerEvents || vProps.pointerEvents == facebook::react::PointerEventsMode::Auto ||
182+ vProps.pointerEvents == facebook::react::PointerEventsMode::BoxOnly) {
183+ localPt = ptLocal;
184+ return Tag ();
185+ }
186+ }
187+ return Super::hitTest (pt, localPt, ignorePointerEvents);
188+ }
189+
170190bool ParagraphComponentView::IsTextSelectableAtPoint (facebook::react::Point pt) noexcept {
171191 // paragraph-level selectable prop is enabled
172192 const auto &props = paragraphProps ();
@@ -534,7 +554,8 @@ void ParagraphComponentView::OnPointerPressed(
534554 return ;
535555 }
536556
537- auto pp = args.GetCurrentPoint (-1 );
557+ // Use Tag() to get coordinates in component's local space
558+ auto pp = args.GetCurrentPoint (static_cast <int32_t >(Tag ()));
538559
539560 // Ignores right-click
540561 if (pp.Properties ().PointerUpdateKind () ==
@@ -545,8 +566,8 @@ void ParagraphComponentView::OnPointerPressed(
545566
546567 auto position = pp.Position ();
547568
548- facebook::react::Point localPt{
549- position.X - m_layoutMetrics. frame . origin . x , position.Y - m_layoutMetrics. frame . origin . y };
569+ // GetCurrentPoint(Tag()) returns position relative to component origin
570+ facebook::react::Point localPt{ position.X , position.Y };
550571
551572 std::optional<int32_t > charPosition = GetTextPositionAtPoint (localPt);
552573
@@ -620,7 +641,7 @@ void ParagraphComponentView::OnPointerMoved(
620641void ParagraphComponentView::OnPointerReleased (
621642 const winrt::Microsoft::ReactNative::Composition::Input::PointerRoutedEventArgs &args) noexcept {
622643 // Check for right-click to show context menu
623- auto pp = args.GetCurrentPoint (- 1 );
644+ auto pp = args.GetCurrentPoint (static_cast < int32_t >( Tag ()) );
624645 if (pp.Properties ().PointerUpdateKind () ==
625646 winrt::Microsoft::ReactNative::Composition::Input::PointerUpdateKind::RightButtonReleased) {
626647 const auto &props = paragraphProps ();
0 commit comments