Skip to content

Commit

Permalink
fix touch event on SubContextView when fitWidth and fitHeight (cocos#…
Browse files Browse the repository at this point in the history
…9043)

update
  • Loading branch information
PPpro committed Jul 22, 2021
1 parent 56377ba commit eb06667
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions cocos/ui/sub-context-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export class SubContextView extends Component {
}

private _updateSubContextView () {
if (!(this._openDataContext && minigame.getSystemInfoSync)) {
if (!this._openDataContext) {
return;
}

Expand All @@ -191,14 +191,16 @@ export class SubContextView extends Component {
contentTrans.height *= scale;

// update viewport in subContextView
const systemInfo = minigame.getSystemInfoSync();
const viewportRect = view.getViewportRect();
const box = contentTrans.getBoundingBoxToWorld();
const visibleSize = view.getVisibleSize();
const dpr = view.getDevicePixelRatio();

const x = systemInfo.screenWidth * (box.x / visibleSize.width);
const y = systemInfo.screenHeight * (box.y / visibleSize.height);
const width = systemInfo.screenWidth * (box.width / visibleSize.width);
const height = systemInfo.screenHeight * (box.height / visibleSize.height);
// TODO: the visibleSize need to be the size of Canvas node where the content node is.
const x = (viewportRect.width * (box.x / visibleSize.width) + viewportRect.x) / dpr;
const y = (viewportRect.height * (box.y / visibleSize.height) + viewportRect.y) / dpr;
const width = viewportRect.width * (box.width / visibleSize.width) / dpr;
const height = viewportRect.height * (box.height / visibleSize.height) / dpr;

this._openDataContext.postMessage({
fromEngine: true, // compatible deprecated property
Expand Down

0 comments on commit eb06667

Please sign in to comment.