Skip to content

Commit

Permalink
feat: 修复fixed异常插入问题
Browse files Browse the repository at this point in the history
  • Loading branch information
heiazu committed Jun 19, 2024
1 parent 32f1f7e commit 3f08bc7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-ignore
import { getPageById } from '@tarojs/plugin-framework-react'
import { eventCenter, eventSource } from '@tarojs/runtime/dist/runtime.esm'
import { EMPTY_OBJ, toCamelCase } from '@tarojs/shared'

Expand Down Expand Up @@ -316,6 +318,13 @@ export class TaroElement<
// 3、removeChild的时候,会判断是否需要移除层级
public setLayer (value: number) {
if (!this.parentNode) return // 没有父节点,不需要设置层级关系


const currentPage = getPageById(this.getAttribute('__fixed'))
if (currentPage) {
this._page = currentPage
}

this._nodeInfo.layer = value

const currentLayerNode = this.currentLayerNode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function initNativeComponentEntry (params: InitNativeComponentEntryParams) {

render () {
return h(
'view',
'taro-page',
{
ref: this.root,
id: this.props.compId,
Expand Down Expand Up @@ -177,6 +177,20 @@ function initNativeComponentEntry (params: InitNativeComponentEntryParams) {
ReactDOM.render(h(Entry, {}), app)
}


const pages = new Map<string, any>()
export function setPageById (inst: any, id: string) {
pages.set(id, inst)
}

export function getPageById (id: string): any {
return pages.get(id)
}

export function removePageById (id: string) {
pages.delete(id)
}

export function createNativePageConfig (
Component,
pageName: string,
Expand Down Expand Up @@ -223,6 +237,8 @@ export function createNativePageConfig (
const uniqueOptions = Object.assign({}, options, { $taroTimestamp: Date.now() })
const $taroPath = (this.$taroPath = getPath(id, uniqueOptions))

setPageById(this, $taroPath)

// this.$taroParams 作为暴露给开发者的页面参数对象,可以被随意修改
if (this.$taroParams == null) {
this.$taroParams = uniqueOptions
Expand Down Expand Up @@ -268,6 +284,10 @@ export function createNativePageConfig (
window.trigger(CONTEXT_ACTIONS.DESTORY, $taroPath)
// 触发onUnload生命周期
safeExecute($taroPath, ONUNLOAD)


removePageById($taroPath)

resetCurrent.call(this)
unmounting = true
Current.app!.unmount!($taroPath, () => {
Expand Down
7 changes: 7 additions & 0 deletions packages/taro-react/src/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,18 @@ export function updateProps (dom: TaroElement, oldProps: Props, newProps: Props)

export function updatePropsByPayload (dom: TaroElement, oldProps: Props, updatePayload: any[]) {
const handlers: (() => void)[] = []
let fixedHandler: (() => void) | null = null
for (let i = 0; i < updatePayload.length; i += 2) {
// key, value 成对出现
const key = updatePayload[i]
const newProp = updatePayload[i + 1]
const oldProp = oldProps[key]
if (isHarmony) {
if (key === '__fixed') {
// hack: __fixed最先识别
fixedHandler = () => setProperty(dom, key, newProp, oldProp)
continue
}
// 鸿蒙样式前置插入,防止覆盖style
if (key === '__hmStyle') {
handlers.splice(0, 0, () => setHarmonyStyle(dom, newProp, oldProp))
Expand All @@ -70,6 +76,7 @@ export function updatePropsByPayload (dom: TaroElement, oldProps: Props, updateP
}
}
if (isHarmony) {
fixedHandler && fixedHandler()
for (let i = 0; i < handlers.length; i++) {
handlers[i]()
}
Expand Down

0 comments on commit 3f08bc7

Please sign in to comment.