Fix:修复切换主题时,被收起的节点样式没有变化的问题

This commit is contained in:
街角小林
2024-01-25 13:52:23 +08:00
parent 59b2506884
commit 7bd467a330
3 changed files with 32 additions and 4 deletions

View File

@@ -397,6 +397,10 @@ class Render {
// 渲染
render(callback = () => {}, source) {
// 切换主题时,被收起的节点需要添加样式复位的标注
if (source === CONSTANTS.CHANGE_THEME) {
this.resetUnExpandNodeStyle()
}
// 如果当前还没有渲染完毕,不再触发渲染
if (this.isRendering) {
// 等待当前渲染完毕后再进行一次渲染
@@ -455,6 +459,18 @@ class Render {
this.emitNodeActiveEvent()
}
// 给当前被收起来的节点数据添加文本复位标志
resetUnExpandNodeStyle() {
walk(this.renderTree, null, node => {
if (!node.data.expand) {
walk(node, null, node2 => {
node2.data.resetRichText = true
})
return true
}
})
}
// 清除当前所有激活节点,并会触发事件
clearActiveNode() {
if (this.activeNodeList.length <= 0) {

View File

@@ -186,6 +186,9 @@ function createTextNode() {
if (this.getData('richText')) {
return this.createRichTextNode()
}
if (this.getData('resetRichText')) {
delete this.nodeData.data.resetRichText
}
let g = new G()
let fontSize = this.getStyle('fontSize', false)
let lineHeight = this.getStyle('lineHeight', false)

View File

@@ -85,8 +85,12 @@ class Base {
newNode.layerIndex = layerIndex
this.cacheNode(data._node.uid, newNode)
this.checkIsLayoutChangeRerenderExpandBtnPlaceholderRect(newNode)
// 主题或主题配置改变了需要重新计算节点大小和布局
if (this.checkIsNeedResizeSources() || isLayerTypeChange) {
// 主题或主题配置改变了、节点层级改变了,需要重新渲染节点文本等情况需要重新计算节点大小和布局
if (
this.checkIsNeedResizeSources() ||
isLayerTypeChange ||
newNode.getData('resetRichText')
) {
newNode.getSize()
newNode.needLayout = true
}
@@ -113,9 +117,14 @@ class Base {
data._node = newNode
// 主题或主题配置改变了需要重新计算节点大小和布局
const isResizeSource = this.checkIsNeedResizeSources()
// 节点数据改变了需要重新计算节点大小和布局
// 主题或主题配置改变了、节点层级改变了,需要重新渲染节点文本,节点数据改变了等情况需要重新计算节点大小和布局
const isNodeDataChange = lastData !== JSON.stringify(data.data)
if (isResizeSource || isNodeDataChange || isLayerTypeChange) {
if (
isResizeSource ||
isNodeDataChange ||
isLayerTypeChange ||
newNode.getData('resetRichText')
) {
newNode.getSize()
newNode.needLayout = true
}