Skip to content

Commit

Permalink
fix(wx-react): 修正didMount ,didFocus的执行顺序
Browse files Browse the repository at this point in the history
  • Loading branch information
ykforerlang committed Jul 19, 2019
1 parent 5189ba2 commit c13e6e8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/wx-react/miniprogram_dist/AllComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ export class Component extends BaseComponent {

render(subVnode, this, context, this._r, this._or, '_r')

// 一般发生于didFoucs里面的setState,此时还未调用firstUpdate
// firstRender既不是DONE,也不是PENDING,此时调用setState需要刷新_r数据
if (this.firstRender !== FR_DONE) {
return
}
Expand Down
6 changes: 4 additions & 2 deletions packages/wx-react/miniprogram_dist/WxNormalComp.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import {render, createElement, HocComponent, unstable_batchedUpdates} from "./index"
import geneUUID from "./geneUUID"
import instanceManager from "./InstanceManager"
import {recursionUnmount} from './util'
import {FR_DONE, recursionUnmount} from './util'


export default function (CompMySelf, RNApp) {
Expand Down Expand Up @@ -97,7 +97,9 @@ export default function (CompMySelf, RNApp) {

o.methods.onShow = function () {
const compInst = instanceManager.getCompInstByUUID(this.data.diuu)
compInst.componentDidFocus && unstable_batchedUpdates(() => {

//如果组件还未初始化 didFocus方法,由firstUpdateUI负责
compInst.firstRender === FR_DONE && compInst.componentDidFocus && unstable_batchedUpdates(() => {
compInst.componentDidFocus()
})
}
Expand Down
5 changes: 5 additions & 0 deletions packages/wx-react/miniprogram_dist/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ export function recursionMount(comp) {
}
comp.firstRender = FR_DONE
comp.componentDidMount && comp.componentDidMount()

if (comp.isPageComp && !comp.hocWrapped && comp.componentDidFocus) {
comp.componentDidFocus()
}

comp.firstRenderRes && comp.firstRenderRes()
}

Expand Down

0 comments on commit c13e6e8

Please sign in to comment.