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
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ void EventEmitterWrapper::dispatchEvent(
eventEmitter->dispatchEvent(
eventName,
payload ? payload->consume() : folly::dynamic::object(),
EventPriority::AsynchronousBatched,
static_cast<RawEvent::Category>(category));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,10 @@ void ScrollViewEventEmitter::onMomentumScrollEnd(

void ScrollViewEventEmitter::dispatchScrollViewEvent(
std::string name,
const ScrollViewMetrics& scrollViewMetrics,
EventPriority priority) const {
dispatchEvent(
std::move(name),
[scrollViewMetrics](jsi::Runtime& runtime) {
return scrollViewMetricsPayload(runtime, scrollViewMetrics);
},
priority);
const ScrollViewMetrics& scrollViewMetrics) const {
dispatchEvent(std::move(name), [scrollViewMetrics](jsi::Runtime& runtime) {
return scrollViewMetricsPayload(runtime, scrollViewMetrics);
});
}

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ class ScrollViewEventEmitter : public ViewEventEmitter {
private:
void dispatchScrollViewEvent(
std::string name,
const ScrollViewMetrics& scrollViewMetrics,
EventPriority priority = EventPriority::AsynchronousBatched) const;
const ScrollViewMetrics& scrollViewMetrics) const;
};

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,9 @@ void TextInputEventEmitter::onSubmitEditing(

void TextInputEventEmitter::onKeyPress(
const KeyPressMetrics& keyPressMetrics) const {
dispatchEvent(
"keyPress",
[keyPressMetrics](jsi::Runtime& runtime) {
return keyPressMetricsPayload(runtime, keyPressMetrics);
},
EventPriority::AsynchronousBatched);
dispatchEvent("keyPress", [keyPressMetrics](jsi::Runtime& runtime) {
return keyPressMetricsPayload(runtime, keyPressMetrics);
});
}

void TextInputEventEmitter::onScroll(
Expand All @@ -129,26 +126,18 @@ void TextInputEventEmitter::onScroll(

void TextInputEventEmitter::dispatchTextInputEvent(
const std::string& name,
const TextInputMetrics& textInputMetrics,
EventPriority priority) const {
dispatchEvent(
name,
[textInputMetrics](jsi::Runtime& runtime) {
return textInputMetricsPayload(runtime, textInputMetrics);
},
priority);
const TextInputMetrics& textInputMetrics) const {
dispatchEvent(name, [textInputMetrics](jsi::Runtime& runtime) {
return textInputMetricsPayload(runtime, textInputMetrics);
});
}

void TextInputEventEmitter::dispatchTextInputContentSizeChangeEvent(
const std::string& name,
const TextInputMetrics& textInputMetrics,
EventPriority priority) const {
dispatchEvent(
name,
[textInputMetrics](jsi::Runtime& runtime) {
return textInputMetricsContentSizePayload(runtime, textInputMetrics);
},
priority);
const TextInputMetrics& textInputMetrics) const {
dispatchEvent(name, [textInputMetrics](jsi::Runtime& runtime) {
return textInputMetricsContentSizePayload(runtime, textInputMetrics);
});
}

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,11 @@ class TextInputEventEmitter : public ViewEventEmitter {
private:
void dispatchTextInputEvent(
const std::string& name,
const TextInputMetrics& textInputMetrics,
EventPriority priority = EventPriority::AsynchronousBatched) const;
const TextInputMetrics& textInputMetrics) const;

void dispatchTextInputContentSizeChangeEvent(
const std::string& name,
const TextInputMetrics& textInputMetrics,
EventPriority priority = EventPriority::AsynchronousBatched) const;
const TextInputMetrics& textInputMetrics) const;
};

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -45,35 +45,25 @@ static jsi::Value touchEventPayload(
void TouchEventEmitter::dispatchTouchEvent(
std::string type,
const TouchEvent& event,
EventPriority priority,
RawEvent::Category category) const {
dispatchEvent(
std::move(type),
[event](jsi::Runtime& runtime) {
return touchEventPayload(runtime, event);
},
priority,
category);
}

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

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

void TouchEventEmitter::onTouchMove(const TouchEvent& event) const {
Expand All @@ -83,103 +73,63 @@ void TouchEventEmitter::onTouchMove(const TouchEvent& event) const {
}

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

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

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

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

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

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

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

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

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

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

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

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

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

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,10 @@ class TouchEventEmitter : public EventEmitter {
void dispatchTouchEvent(
std::string type,
const TouchEvent& event,
EventPriority priority,
RawEvent::Category category) const;
void dispatchPointerEvent(
std::string type,
const PointerEvent& event,
EventPriority priority,
RawEvent::Category category) const;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,10 @@ class ConcreteState : public State {
* function for cases where a new value of data does not depend on an old
* value.
*/
void updateState(Data&& newData, EventPriority priority) const {
updateState(
[data{std::move(newData)}](const Data& oldData) -> SharedData {
return std::make_shared<Data const>(data);
},
priority);
}

void updateState(Data&& newData) const {
updateState(std::move(newData), EventPriority::AsynchronousBatched);
updateState([data{std::move(newData)}](const Data& oldData) -> SharedData {
return std::make_shared<Data const>(data);
});
}

/*
Expand All @@ -79,8 +73,7 @@ class ConcreteState : public State {
* return `nullptr`.
*/
void updateState(
std::function<StateData::Shared(const Data& oldData)> callback,
EventPriority priority = EventPriority::AsynchronousBatched) const {
std::function<StateData::Shared(const Data& oldData)> callback) const {
auto family = family_.lock();

if (!family) {
Expand All @@ -95,7 +88,7 @@ class ConcreteState : public State {
return callback(*static_cast<Data const*>(oldData.get()));
}};

family->dispatchRawState(std::move(stateUpdate), priority);
family->dispatchRawState(std::move(stateUpdate));
}

#ifdef ANDROID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,11 @@ EventDispatcher::EventDispatcher(
const EventBeat::Factory& synchonousEventBeatFactory,
const EventBeat::Factory& asynchronousEventBeatFactory,
const EventBeat::SharedOwnerBox& ownerBox)
: synchronousUnbatchedQueue_(std::make_unique<UnbatchedEventQueue>(
eventProcessor,
synchonousEventBeatFactory(ownerBox))),
synchronousBatchedQueue_(std::make_unique<BatchedEventQueue>(
eventProcessor,
synchonousEventBeatFactory(ownerBox))),
asynchronousUnbatchedQueue_(std::make_unique<UnbatchedEventQueue>(
eventProcessor,
asynchronousEventBeatFactory(ownerBox))),
asynchronousBatchedQueue_(std::make_unique<BatchedEventQueue>(
: asynchronousBatchedQueue_(std::make_unique<BatchedEventQueue>(
eventProcessor,
asynchronousEventBeatFactory(ownerBox))) {}

void EventDispatcher::dispatchEvent(RawEvent&& rawEvent, EventPriority priority)
const {
void EventDispatcher::dispatchEvent(RawEvent&& rawEvent) const {
// Allows the event listener to interrupt default event dispatch
if (eventListeners_.willDispatchEvent(rawEvent)) {
return;
Expand All @@ -45,13 +35,11 @@ void EventDispatcher::dispatchEvent(RawEvent&& rawEvent, EventPriority priority)
if (eventLogger != nullptr) {
rawEvent.loggingTag = eventLogger->onEventStart(rawEvent.type);
}
getEventQueue(priority).enqueueEvent(std::move(rawEvent));
asynchronousBatchedQueue_->enqueueEvent(std::move(rawEvent));
}

void EventDispatcher::dispatchStateUpdate(
StateUpdate&& stateUpdate,
EventPriority priority) const {
getEventQueue(priority).enqueueStateUpdate(std::move(stateUpdate));
void EventDispatcher::dispatchStateUpdate(StateUpdate&& stateUpdate) const {
asynchronousBatchedQueue_->enqueueStateUpdate(std::move(stateUpdate));
}

void EventDispatcher::dispatchUniqueEvent(RawEvent&& rawEvent) const {
Expand All @@ -62,19 +50,6 @@ void EventDispatcher::dispatchUniqueEvent(RawEvent&& rawEvent) const {
asynchronousBatchedQueue_->enqueueUniqueEvent(std::move(rawEvent));
}

const EventQueue& EventDispatcher::getEventQueue(EventPriority priority) const {
switch (priority) {
case EventPriority::SynchronousUnbatched:
return *synchronousUnbatchedQueue_;
case EventPriority::SynchronousBatched:
return *synchronousBatchedQueue_;
case EventPriority::AsynchronousUnbatched:
return *asynchronousUnbatchedQueue_;
case EventPriority::AsynchronousBatched:
return *asynchronousBatchedQueue_;
}
}

void EventDispatcher::addListener(
const std::shared_ptr<const EventListener>& listener) const {
eventListeners_.addListener(listener);
Expand Down
Loading