( finishedWork: FiberNode, callback: (hostSubtreeRoot: FiberNode) => void )
| 111 | |
| 112 | // 寻找根host节点,考虑到Fragment,可能存在多个 |
| 113 | function findHostSubtreeRoot( |
| 114 | finishedWork: FiberNode, |
| 115 | callback: (hostSubtreeRoot: FiberNode) => void |
| 116 | ) { |
| 117 | let hostSubtreeRoot = null; |
| 118 | let node = finishedWork; |
| 119 | while (true) { |
| 120 | if (node.tag === HostComponent) { |
| 121 | if (hostSubtreeRoot === null) { |
| 122 | // 还未发现 root,当前就是 |
| 123 | hostSubtreeRoot = node; |
| 124 | callback(node); |
| 125 | } |
| 126 | } else if (node.tag === HostText) { |
| 127 | if (hostSubtreeRoot === null) { |
| 128 | // 还未发现 root,text可以是顶层节点 |
| 129 | callback(node); |
| 130 | } |
| 131 | } else if ( |
| 132 | node.tag === OffscreenComponent && |
| 133 | node.pendingProps.mode === 'hidden' && |
| 134 | node !== finishedWork |
| 135 | ) { |
| 136 | // 隐藏的OffscreenComponent跳过 |
| 137 | } else if (node.child !== null) { |
| 138 | node.child.return = node; |
| 139 | node = node.child; |
| 140 | continue; |
| 141 | } |
| 142 | |
| 143 | if (node === finishedWork) { |
| 144 | return; |
| 145 | } |
| 146 | |
| 147 | while (node.sibling === null) { |
| 148 | if (node.return === null || node.return === finishedWork) { |
| 149 | return; |
| 150 | } |
| 151 | |
| 152 | if (hostSubtreeRoot === node) { |
| 153 | hostSubtreeRoot = null; |
| 154 | } |
| 155 | |
| 156 | node = node.return; |
| 157 | } |
| 158 | |
| 159 | // 去兄弟节点寻找,此时当前子树的host root可以移除了 |
| 160 | if (hostSubtreeRoot === node) { |
| 161 | hostSubtreeRoot = null; |
| 162 | } |
| 163 | |
| 164 | node.sibling.return = node.return; |
| 165 | node = node.sibling; |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | function hideOrUnhideAllChildren(finishedWork: FiberNode, isHidden: boolean) { |
| 170 | findHostSubtreeRoot(finishedWork, (hostRoot) => { |
no outgoing calls
no test coverage detected