mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00
fix(devtools-ios): Ensure UI modifications run on main thread
Modifications to the UI can only be made from the main thread. Since {N} 5.3.0 all debugger protocol messages are processed by the worker thread that receives them in iOS. refs #7219, https://github.com/NativeScript/ios-runtime/pull/1101
This commit is contained in:
@ -2,6 +2,7 @@ import { getNodeById } from "./dom-node";
|
||||
|
||||
// Needed for typings only
|
||||
import { ViewBase } from "../ui/core/view-base";
|
||||
import { mainThreadify } from "../utils/utils";
|
||||
|
||||
// Use lazy requires for core modules
|
||||
const frameTopmost = () => require("../ui/frame").topmost();
|
||||
@ -11,7 +12,7 @@ function unsetViewValue(view, name) {
|
||||
if (!unsetValue) {
|
||||
unsetValue = require("../ui/core/properties").unsetValue;
|
||||
}
|
||||
|
||||
|
||||
view[name] = unsetValue;
|
||||
}
|
||||
|
||||
@ -30,10 +31,10 @@ export function getDocument() {
|
||||
if (!topMostFrame) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
topMostFrame.ensureDomNode();
|
||||
|
||||
|
||||
} catch (e) {
|
||||
console.log("ERROR in getDocument(): " + e);
|
||||
}
|
||||
@ -49,7 +50,7 @@ export function getComputedStylesForNode(nodeId): Array<{ name: string, value: s
|
||||
return [];
|
||||
}
|
||||
|
||||
export function removeNode(nodeId) {
|
||||
export const removeNode = mainThreadify(function removeNode(nodeId) {
|
||||
const view = getViewById(nodeId);
|
||||
if (view) {
|
||||
// Avoid importing layout and content view
|
||||
@ -63,9 +64,9 @@ export function removeNode(nodeId) {
|
||||
console.log("Can't remove child from " + parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export function setAttributeAsText(nodeId, text, name) {
|
||||
export const setAttributeAsText = mainThreadify(function setAttributeAsText(nodeId, text, name) {
|
||||
const view = getViewById(nodeId);
|
||||
if (view) {
|
||||
// attribute is registered for the view instance
|
||||
@ -93,4 +94,4 @@ export function setAttributeAsText(nodeId, text, name) {
|
||||
|
||||
view.domNode.loadAttributes();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user