Skip to content

Commit

Permalink
feat(wasm): Added ability to measure shapes on Wasm even when the con…
Browse files Browse the repository at this point in the history
…trol is not loaded.
  • Loading branch information
carldebilly authored and davidjohnoliver committed Aug 2, 2021
1 parent 0d4e7cf commit fe2c502
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
24 changes: 23 additions & 1 deletion src/Uno.UI/WasmScripts/Uno.UI.js
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,29 @@ var Uno;
return true;
}
getBBoxInternal(elementId) {
return this.getView(elementId).getBBox();
const element = this.getView(elementId);
let unconnectedRoot = null;
let cleanupUnconnectedRoot = (owner) => {
if (unconnectedRoot !== null) {
owner.removeChild(unconnectedRoot);
}
};
try {
// On FireFox, the element needs to be connected to the DOM
// or the getBBox() will crash.
if (!element.isConnected) {
while (unconnectedRoot.parentElement) {
// Need to find the top most "unconnected" parent
// of this element
unconnectedRoot = unconnectedRoot.parentElement;
}
this.containerElement.appendChild(unconnectedRoot);
}
return element.getBBox();
}
finally {
cleanupUnconnectedRoot(this.containerElement);
}
}
setSvgElementRect(pParams) {
const params = WindowManagerSetSvgElementRectParams.unmarshal(pParams);
Expand Down
32 changes: 31 additions & 1 deletion src/Uno.UI/ts/WindowManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,37 @@ namespace Uno.UI {
}

private getBBoxInternal(elementId: number): any {
return (<any>this.getView(elementId)).getBBox();

const element = this.getView(elementId) as SVGGraphicsElement;
let unconnectedRoot: HTMLElement = null;

let cleanupUnconnectedRoot = (owner: HTMLDivElement) => {
if (unconnectedRoot !== null) {
owner.removeChild(unconnectedRoot);
}
}

try {

// On FireFox, the element needs to be connected to the DOM
// or the getBBox() will crash.
if (!element.isConnected) {

while (unconnectedRoot.parentElement) {
// Need to find the top most "unconnected" parent
// of this element
unconnectedRoot = unconnectedRoot.parentElement as HTMLElement;
}

this.containerElement.appendChild(unconnectedRoot);
}

return element.getBBox();
}
finally {
cleanupUnconnectedRoot(this.containerElement);
}

}

public setSvgElementRect(pParams: number): boolean {
Expand Down

0 comments on commit fe2c502

Please sign in to comment.