Skip to content

Commit 282a946

Browse files
acoates-msiamAbhi-916
authored andcommitted
Implement onClick (#15889)
* Implement onClick * Change files
1 parent 3820fcc commit 282a946

4 files changed

Lines changed: 36 additions & 8 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Implement onClick",
4+
"packageName": "react-native-windows",
5+
"email": "30809111+acoates-ms@users.noreply.github.com",
6+
"dependentChangeType": "patch"
7+
}

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

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -986,8 +986,6 @@ void CompositionEventHandler::UpdateActiveTouch(
986986
// activeTouch.touch.shiftKey = false;
987987
// activeTouch.touch.ctrlKey = false;
988988
// activeTouch.touch.altKey = false;
989-
990-
// activeTouch.touch.isPrimary = true;
991989
}
992990

993991
facebook::react::PointerEvent CreatePointerEventFromIncompleteHoverData(
@@ -1246,15 +1244,15 @@ void CompositionEventHandler::onPointerPressed(
12461244
->eventEmitterAtPoint(ptLocal)) {
12471245
activeTouch.eventEmitter = eventEmitter;
12481246
activeTouch.touch.target = targetComponentView.Tag();
1249-
// activeTouch.componentView = componentView;
1247+
activeTouch.initialComponentView = targetComponentView;
12501248
break;
12511249
}
12521250
targetComponentView = targetComponentView.Parent();
12531251
}
12541252

12551253
UpdateActiveTouch(activeTouch, ptScaled, ptLocal);
12561254

1257-
// activeTouch.touch.isPrimary = true;
1255+
activeTouch.isPrimary = pointerId == 1;
12581256
activeTouch.touch.identifier = pointerId;
12591257

12601258
// If the pointer has not been marked as hovering over views before the touch started, we register
@@ -1459,11 +1457,26 @@ facebook::react::PointerEvent CompositionEventHandler::CreatePointerEventFromAct
14591457

14601458
// event.tangentialPressure = 0.0;
14611459
// event.twist = 0;
1462-
// event.isPrimary = activeTouch.isPrimary;
1460+
event.isPrimary = activeTouch.isPrimary;
14631461

14641462
return event;
14651463
}
14661464

1465+
bool CompositionEventHandler::IsPointerWithinInitialTree(const ActiveTouch &activeTouch) noexcept {
1466+
auto initialComponentView = activeTouch.initialComponentView.view();
1467+
if (!initialComponentView)
1468+
return false;
1469+
1470+
auto initialViewSet = GetTouchableViewsInPathToRoot(initialComponentView);
1471+
1472+
for (const auto &view : initialViewSet) {
1473+
if (view.Tag() == activeTouch.touch.target)
1474+
return true;
1475+
}
1476+
1477+
return false;
1478+
}
1479+
14671480
// If we have events that include multiple pointer updates, we should change arg from pointerId to vector<pointerId>
14681481
void CompositionEventHandler::DispatchTouchEvent(
14691482
TouchEventType eventType,
@@ -1520,6 +1533,13 @@ void CompositionEventHandler::DispatchTouchEvent(
15201533
}
15211534
case TouchEventType::End:
15221535
activeTouch.eventEmitter->onPointerUp(pointerEvent);
1536+
if (pointerEvent.isPrimary && pointerEvent.button == 0) {
1537+
if (IsPointerWithinInitialTree(activeTouch)) {
1538+
activeTouch.eventEmitter->onClick(pointerEvent);
1539+
}
1540+
} /* else if (IsPointerWithinInitialTree(activeTouch)) {
1541+
activeTouch.eventEmitter->onAuxClick(pointerEvent);
1542+
} */
15231543
break;
15241544
case TouchEventType::Cancel:
15251545
case TouchEventType::CaptureLost:

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,10 @@ class CompositionEventHandler : public std::enable_shared_from_this<CompositionE
138138
/*
139139
* A component view on which the touch was begun.
140140
*/
141-
//__strong UIView<RCTComponentViewProtocol> *componentView = nil;
141+
ReactTaggedView initialComponentView{nullptr};
142142
};
143143

144+
static bool IsPointerWithinInitialTree(const ActiveTouch &activeTouch) noexcept;
144145
static bool IsEndishEventType(TouchEventType eventType) noexcept;
145146
static const char *PointerTypeCStringFromUITouchType(UITouchType type) noexcept;
146147
static facebook::react::PointerEvent CreatePointerEventFromActiveTouch(

vnext/Microsoft.ReactNative/Fabric/ReactTaggedView.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct ReactTaggedView {
1818
ReactTaggedView(const winrt::Microsoft::ReactNative::ComponentView &componentView)
1919
: m_view(componentView), m_tag(componentView ? componentView.Tag() : -1) {}
2020

21-
winrt::Microsoft::ReactNative::ComponentView view() noexcept {
21+
winrt::Microsoft::ReactNative::ComponentView view() const noexcept {
2222
if (!m_view) {
2323
return nullptr;
2424
}
@@ -37,7 +37,7 @@ struct ReactTaggedView {
3737

3838
private:
3939
facebook::react::Tag m_tag;
40-
winrt::weak_ref<winrt::Microsoft::ReactNative::ComponentView> m_view;
40+
mutable winrt::weak_ref<winrt::Microsoft::ReactNative::ComponentView> m_view;
4141
};
4242

4343
} // namespace Microsoft::ReactNative

0 commit comments

Comments
 (0)