Skip to content

Commit

Permalink
feat(vue): add vue style diff
Browse files Browse the repository at this point in the history
  • Loading branch information
zealotchen0 committed Oct 18, 2023
1 parent aa93c41 commit fa579d1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion driver/js/packages/hippy-vue/src/renderer/element-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ class ElementNode extends ViewNode {
if (typeof this.filterAttribute === 'function') {
this.filterAttribute(this.attributes);
}
!options.notToNative && updateChild(this);
!options.notToNative && updateChild(this, options.notUpdateStyle);
} catch (err) {
// Throw error in development mode
if (isDev()) {
Expand Down
35 changes: 30 additions & 5 deletions driver/js/packages/hippy-vue/src/renderer/native/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,24 @@ function getEventNode(targetNode) {
return eventNode;
}

/**
* getEventNode - translate to native node.
* @param targetNode
*/
function getNativeNode(rootViewId, targetNode, refInfo = {}, style) {
const nativeNode = {
id: targetNode.nodeId,
pId: (targetNode.parentNode && targetNode.parentNode.nodeId) || rootViewId,
name: targetNode.meta.component.name,
props: {
...getNativeProps(targetNode),
style,
},
tagName: targetNode.tagName,
};
return [nativeNode, refInfo, { skipStyleDiff: true }];
}

/**
* Render Element to native
*/
Expand Down Expand Up @@ -638,19 +656,26 @@ function updateEvent(parentNode) {
endBatch(app);
}

function updateChild(parentNode) {
function updateChild(parentNode, notUpdateStyle = false) {
if (!parentNode.isMounted) {
return;
}
const app = getApp();
const { $options: { rootViewId } } = app;
const [nativeNode, eventNode, printedNode] = renderToNative(rootViewId, parentNode);
let nativeNode;
let eventNode;
let printedNode;
if (notUpdateStyle) {
nativeNode = getNativeNode(rootViewId, parentNode, refInfo);
} else {
[nativeNode, eventNode, printedNode] = renderToNative(rootViewId, parentNode);
}
if (nativeNode) {
batchNodes.push({
type: NODE_OPERATION_TYPES.updateNode,
nodes: [nativeNode],
eventNodes: [eventNode],
printedNodes: isDev() ? [printedNode] : [],
nodes: nativeNode ? [nativeNode] : [],
eventNodes: eventNode ? [eventNode] : [],
printedNodes: isDev() && printedNode ? [printedNode] : [],
});
endBatch(app);
}
Expand Down

0 comments on commit fa579d1

Please sign in to comment.