Skip to content
Closed
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
14 changes: 8 additions & 6 deletions packages/react-native/React/Fabric/RCTSurfacePointerHandler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -620,22 +620,22 @@ - (void)_dispatchActivePointers:(std::vector<ActivePointer>)activePointers event
if (eventEmitter != nil) {
switch (eventType) {
case RCTPointerEventTypeStart: {
eventEmitter->onPointerDown(pointerEvent);
eventEmitter->onPointerDown(std::move(pointerEvent));
break;
}
case RCTPointerEventTypeMove: {
eventEmitter->onPointerMove(pointerEvent);
eventEmitter->onPointerMove(std::move(pointerEvent));
break;
}
case RCTPointerEventTypeEnd: {
eventEmitter->onPointerUp(pointerEvent);
if (pointerEvent.isPrimary && pointerEvent.button == 0 && IsPointerWithinInitialTree(activePointer)) {
eventEmitter->onClick(pointerEvent);
eventEmitter->onClick(std::move(pointerEvent));
}
break;
}
case RCTPointerEventTypeCancel: {
eventEmitter->onPointerCancel(pointerEvent);
eventEmitter->onPointerCancel(std::move(pointerEvent));
break;
}
}
Expand Down Expand Up @@ -761,9 +761,11 @@ - (void)hovering:(UIHoverGestureRecognizer *)recognizer
if (eventEmitter != nil) {
switch (recognizer.state) {
case UIGestureRecognizerStateEnded:
eventEmitter->onPointerLeave(event);
eventEmitter->onPointerLeave(std::move(event));
break;
default:
eventEmitter->onPointerMove(event);
eventEmitter->onPointerMove(std::move(event));
break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,92 +44,104 @@ static jsi::Value touchEventPayload(

void TouchEventEmitter::dispatchTouchEvent(
std::string type,
const TouchEvent& event,
TouchEvent event,
RawEvent::Category category) const {
dispatchEvent(
std::move(type),
[event](jsi::Runtime& runtime) {
[event = std::move(event)](jsi::Runtime& runtime) {
return touchEventPayload(runtime, event);
},
category);
}

void TouchEventEmitter::dispatchPointerEvent(
std::string type,
const PointerEvent& event,
PointerEvent event,
RawEvent::Category category) const {
dispatchEvent(
std::move(type), std::make_shared<PointerEvent>(event), category);
std::move(type),
std::make_shared<PointerEvent>(std::move(event)),
category);
}

void TouchEventEmitter::onTouchStart(const TouchEvent& event) const {
dispatchTouchEvent("touchStart", event, RawEvent::Category::ContinuousStart);
void TouchEventEmitter::onTouchStart(TouchEvent event) const {
dispatchTouchEvent(
"touchStart", std::move(event), RawEvent::Category::ContinuousStart);
}

void TouchEventEmitter::onTouchMove(const TouchEvent& event) const {
dispatchUniqueEvent("touchMove", [event](jsi::Runtime& runtime) {
return touchEventPayload(runtime, event);
});
void TouchEventEmitter::onTouchMove(TouchEvent event) const {
dispatchUniqueEvent(
"touchMove", [event = std::move(event)](jsi::Runtime& runtime) {
return touchEventPayload(runtime, event);
});
}

void TouchEventEmitter::onTouchEnd(const TouchEvent& event) const {
dispatchTouchEvent("touchEnd", event, RawEvent::Category::ContinuousEnd);
void TouchEventEmitter::onTouchEnd(TouchEvent event) const {
dispatchTouchEvent(
"touchEnd", std::move(event), RawEvent::Category::ContinuousEnd);
}

void TouchEventEmitter::onTouchCancel(const TouchEvent& event) const {
dispatchTouchEvent("touchCancel", event, RawEvent::Category::ContinuousEnd);
void TouchEventEmitter::onTouchCancel(TouchEvent event) const {
dispatchTouchEvent(
"touchCancel", std::move(event), RawEvent::Category::ContinuousEnd);
}

void TouchEventEmitter::onClick(const PointerEvent& event) const {
dispatchPointerEvent("click", event, RawEvent::Category::Discrete);
void TouchEventEmitter::onClick(PointerEvent event) const {
dispatchPointerEvent("click", std::move(event), RawEvent::Category::Discrete);
}

void TouchEventEmitter::onPointerCancel(const PointerEvent& event) const {
void TouchEventEmitter::onPointerCancel(PointerEvent event) const {
dispatchPointerEvent(
"pointerCancel", event, RawEvent::Category::ContinuousEnd);
"pointerCancel", std::move(event), RawEvent::Category::ContinuousEnd);
}

void TouchEventEmitter::onPointerDown(const PointerEvent& event) const {
void TouchEventEmitter::onPointerDown(PointerEvent event) const {
dispatchPointerEvent(
"pointerDown", event, RawEvent::Category::ContinuousStart);
"pointerDown", std::move(event), RawEvent::Category::ContinuousStart);
}

void TouchEventEmitter::onPointerMove(const PointerEvent& event) const {
dispatchUniqueEvent("pointerMove", std::make_shared<PointerEvent>(event));
void TouchEventEmitter::onPointerMove(PointerEvent event) const {
dispatchUniqueEvent(
"pointerMove", std::make_shared<PointerEvent>(std::move(event)));
}

void TouchEventEmitter::onPointerUp(const PointerEvent& event) const {
dispatchPointerEvent("pointerUp", event, RawEvent::Category::ContinuousEnd);
void TouchEventEmitter::onPointerUp(PointerEvent event) const {
dispatchPointerEvent(
"pointerUp", std::move(event), RawEvent::Category::ContinuousEnd);
}

void TouchEventEmitter::onPointerEnter(const PointerEvent& event) const {
void TouchEventEmitter::onPointerEnter(PointerEvent event) const {
dispatchPointerEvent(
"pointerEnter", event, RawEvent::Category::ContinuousStart);
"pointerEnter", std::move(event), RawEvent::Category::ContinuousStart);
}

void TouchEventEmitter::onPointerLeave(const PointerEvent& event) const {
void TouchEventEmitter::onPointerLeave(PointerEvent event) const {
dispatchPointerEvent(
"pointerLeave", event, RawEvent::Category::ContinuousEnd);
"pointerLeave", std::move(event), RawEvent::Category::ContinuousEnd);
}

void TouchEventEmitter::onPointerOver(const PointerEvent& event) const {
void TouchEventEmitter::onPointerOver(PointerEvent event) const {
dispatchPointerEvent(
"pointerOver", event, RawEvent::Category::ContinuousStart);
"pointerOver", std::move(event), RawEvent::Category::ContinuousStart);
}

void TouchEventEmitter::onPointerOut(const PointerEvent& event) const {
void TouchEventEmitter::onPointerOut(PointerEvent event) const {
dispatchPointerEvent(
"pointerOut", event, RawEvent::Category::ContinuousStart);
"pointerOut", std::move(event), RawEvent::Category::ContinuousStart);
}

void TouchEventEmitter::onGotPointerCapture(const PointerEvent& event) const {
void TouchEventEmitter::onGotPointerCapture(PointerEvent event) const {
dispatchPointerEvent(
"gotPointerCapture", event, RawEvent::Category::ContinuousStart);
"gotPointerCapture",
std::move(event),
RawEvent::Category::ContinuousStart);
}

void TouchEventEmitter::onLostPointerCapture(const PointerEvent& event) const {
void TouchEventEmitter::onLostPointerCapture(PointerEvent event) const {
dispatchPointerEvent(
"lostPointerCapture", event, RawEvent::Category::ContinuousEnd);
"lostPointerCapture",
std::move(event),
RawEvent::Category::ContinuousEnd);
}

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,31 @@ class TouchEventEmitter : public EventEmitter {
public:
using EventEmitter::EventEmitter;

void onTouchStart(const TouchEvent& event) const;
void onTouchMove(const TouchEvent& event) const;
void onTouchEnd(const TouchEvent& event) const;
void onTouchCancel(const TouchEvent& event) const;

void onClick(const PointerEvent& event) const;
void onPointerCancel(const PointerEvent& event) const;
void onPointerDown(const PointerEvent& event) const;
void onPointerMove(const PointerEvent& event) const;
void onPointerUp(const PointerEvent& event) const;
void onPointerEnter(const PointerEvent& event) const;
void onPointerLeave(const PointerEvent& event) const;
void onPointerOver(const PointerEvent& event) const;
void onPointerOut(const PointerEvent& event) const;
void onGotPointerCapture(const PointerEvent& event) const;
void onLostPointerCapture(const PointerEvent& event) const;
void onTouchStart(TouchEvent event) const;
void onTouchMove(TouchEvent event) const;
void onTouchEnd(TouchEvent event) const;
void onTouchCancel(TouchEvent event) const;

void onClick(PointerEvent event) const;
void onPointerCancel(PointerEvent event) const;
void onPointerDown(PointerEvent event) const;
void onPointerMove(PointerEvent event) const;
void onPointerUp(PointerEvent event) const;
void onPointerEnter(PointerEvent event) const;
void onPointerLeave(PointerEvent event) const;
void onPointerOver(PointerEvent event) const;
void onPointerOut(PointerEvent event) const;
void onGotPointerCapture(PointerEvent event) const;
void onLostPointerCapture(PointerEvent event) const;

private:
void dispatchTouchEvent(
std::string type,
const TouchEvent& event,
TouchEvent event,
RawEvent::Category category) const;
void dispatchPointerEvent(
std::string type,
const PointerEvent& event,
PointerEvent event,
RawEvent::Category category) const;
};

Expand Down