@dolphinweex/weex-harmony 0.1.66 → 0.1.67
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -122,6 +122,9 @@ export default {
|
|
|
122
122
|
return null;
|
|
123
123
|
};
|
|
124
124
|
this._wrapperEl = findWrapperFromParent(); // 保存容器引用
|
|
125
|
+
// 优化手势处理性能
|
|
126
|
+
this._rafId = null;
|
|
127
|
+
this._pendingGesture = null;
|
|
125
128
|
this._onMessage = (event) => {
|
|
126
129
|
if(event.data.type==='IFRAME_CONTENT_HEIGHT'){
|
|
127
130
|
const h = Number(event.data.height) || 0;
|
|
@@ -136,6 +139,26 @@ export default {
|
|
|
136
139
|
}else{
|
|
137
140
|
document.getElementsByTagName('iframe')[0].height = event.data.height
|
|
138
141
|
}
|
|
142
|
+
// 处理iframe手势跨窗口传递冒泡
|
|
143
|
+
if (event.data.type === 'IFRAME_GESTURE') {
|
|
144
|
+
const gestureData = event.data;
|
|
145
|
+
|
|
146
|
+
// touchmove 使用RAF节流,其他事件立即处理
|
|
147
|
+
if (gestureData.eventType === 'touchmove') {
|
|
148
|
+
this._pendingGesture = gestureData;
|
|
149
|
+
if (!this._rafId) {
|
|
150
|
+
this._rafId = requestAnimationFrame(() => {
|
|
151
|
+
if (this._pendingGesture) {
|
|
152
|
+
this.handleGestureBubble(this._pendingGesture);
|
|
153
|
+
this._pendingGesture = null;
|
|
154
|
+
}
|
|
155
|
+
this._rafId = null;
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
} else {
|
|
159
|
+
this.handleGestureBubble(gestureData);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
139
162
|
};
|
|
140
163
|
window.addEventListener("message", this._onMessage, false);
|
|
141
164
|
},
|
|
@@ -151,6 +174,60 @@ export default {
|
|
|
151
174
|
);
|
|
152
175
|
}
|
|
153
176
|
},
|
|
177
|
+
handleGestureBubble(gestureData) {
|
|
178
|
+
const iframeEl = this.$refs.iframe;
|
|
179
|
+
if (!iframeEl) return;
|
|
180
|
+
|
|
181
|
+
const rect = iframeEl.getBoundingClientRect();
|
|
182
|
+
const offsetX = rect.left;
|
|
183
|
+
const offsetY = rect.top;
|
|
184
|
+
const pageOffsetX = offsetX + window.pageXOffset;
|
|
185
|
+
const pageOffsetY = offsetY + window.pageYOffset;
|
|
186
|
+
|
|
187
|
+
// 创建Touch对象并转换坐标
|
|
188
|
+
const createTouches = (touchesData) => touchesData.map(t => new Touch({
|
|
189
|
+
identifier: t.identifier,
|
|
190
|
+
target: iframeEl,
|
|
191
|
+
clientX: t.clientX + offsetX,
|
|
192
|
+
clientY: t.clientY + offsetY,
|
|
193
|
+
screenX: t.screenX,
|
|
194
|
+
screenY: t.screenY,
|
|
195
|
+
pageX: t.pageX + pageOffsetX,
|
|
196
|
+
pageY: t.pageY + pageOffsetY,
|
|
197
|
+
radiusX: t.radiusX || 0,
|
|
198
|
+
radiusY: t.radiusY || 0,
|
|
199
|
+
rotationAngle: t.rotationAngle || 0,
|
|
200
|
+
force: t.force || 0
|
|
201
|
+
}));
|
|
202
|
+
|
|
203
|
+
try {
|
|
204
|
+
iframeEl.dispatchEvent(new TouchEvent(gestureData.eventType, {
|
|
205
|
+
bubbles: true,
|
|
206
|
+
cancelable: true,
|
|
207
|
+
composed: true,
|
|
208
|
+
touches: createTouches(gestureData.touches),
|
|
209
|
+
targetTouches: createTouches(gestureData.targetTouches),
|
|
210
|
+
changedTouches: createTouches(gestureData.changedTouches),
|
|
211
|
+
ctrlKey: gestureData.ctrlKey,
|
|
212
|
+
shiftKey: gestureData.shiftKey,
|
|
213
|
+
altKey: gestureData.altKey,
|
|
214
|
+
metaKey: gestureData.metaKey
|
|
215
|
+
}));
|
|
216
|
+
} catch (e) {
|
|
217
|
+
console.warn('手势事件冒泡失败:', e);
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
beforeDestroy() {
|
|
222
|
+
// 清理RAF避免内存泄漏
|
|
223
|
+
if (this._rafId) {
|
|
224
|
+
cancelAnimationFrame(this._rafId);
|
|
225
|
+
this._rafId = null;
|
|
226
|
+
}
|
|
227
|
+
// 清理消息监听
|
|
228
|
+
if (this._onMessage) {
|
|
229
|
+
window.removeEventListener("message", this._onMessage, false);
|
|
230
|
+
}
|
|
154
231
|
},
|
|
155
232
|
};
|
|
156
233
|
</script>
|