Skip to content

Commit

Permalink
feat(vue): add native event parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
zoomchan-cxj committed Mar 16, 2023
1 parent b42f999 commit d08affb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,14 @@ const HippyEventDispatcher = {
if (!nativeEvent) {
return;
}

const { id: targetNodeId, name: eventName } = nativeEvent;
const { id: targetNodeId, name: eventName, ...params } = nativeEvent;
const targetNode = getNodeById(targetNodeId);

if (!targetNode) {
return;
}

const targetEventName = getVueEventName(eventName, targetNode);
const targetEvent = new HippyEvent(targetEventName);
targetEvent.nativeParams = params;
const { processEventData } = targetNode.component;
if (processEventData) {
processEventData(
Expand All @@ -148,23 +146,20 @@ const HippyEventDispatcher = {
if (isInvalidNativeEvent(nativeEvent)) {
return;
}

const [targetNodeId, eventName, params] = nativeEvent;
if (typeof targetNodeId !== 'number' || typeof eventName !== 'string') {
return;
}

const targetNode = getNodeById(targetNodeId);
if (!targetNode) {
return;
}

const targetEventName = getVueEventName(eventName, targetNode);

// process layout event
if (eventName === 'onLayout') {
const { layout } = params;
const targetLayoutEvent = new HippyLayoutEvent(targetEventName);
targetLayoutEvent.nativeParams = params ?? {};
targetLayoutEvent.top = layout.y;
targetLayoutEvent.left = layout.x;
targetLayoutEvent.bottom = layout.y + layout.height;
Expand All @@ -175,7 +170,7 @@ const HippyEventDispatcher = {
targetNode.dispatchEvent(targetLayoutEvent);
} else {
const targetEvent = new HippyEvent(targetEventName);

targetEvent.nativeParams = params ?? {};
// other event processing, if the node itself has additional event processing logic, it also needs to be processed
const { processEventData } = targetNode.component;

Expand Down
3 changes: 3 additions & 0 deletions packages/hippy-vue-next/src/runtime/event/hippy-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ export class HippyEvent {
// whether the event can bubble, the default is true
public bubbles = true;

// native parameters
public nativeParams?: NeedToTyped;

// whether the default behavior of the event can be canceled, the default is true
protected cancelable = true;

Expand Down
4 changes: 3 additions & 1 deletion packages/hippy-vue/src/renderer/native/event/dispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,14 @@ const EventDispatcher = {
if (!nativeEvent) {
return;
}
const { id: targetNodeId, name: eventName } = nativeEvent;
const { id: targetNodeId, name: eventName, ...params } = nativeEvent;
const targetNode = getNodeById(targetNodeId);
if (!targetNode) {
return;
}
const targetEventName = getVueEventName(eventName, targetNode);
const targetEvent = new Event(targetEventName);
targetEvent.nativeParams = params;
const { processEventData } = targetNode._meta.component;
if (processEventData) {
processEventData(targetEvent, eventName, nativeEvent);
Expand Down Expand Up @@ -126,6 +127,7 @@ const EventDispatcher = {
}
const targetEventName = getVueEventName(eventName, targetNode);
const targetEvent = new Event(targetEventName);
targetEvent.nativeParams = params || {};
// Post event parameters process.
if (eventName === 'onLayout') {
const { layout } = params;
Expand Down

0 comments on commit d08affb

Please sign in to comment.