Skip to content

Commit

Permalink
fix(wx-react): 修复 TouchableWithoutFeedback 包裹自定义组件样式bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ykforerlang committed Jul 23, 2019
1 parent d81b406 commit 3f5d8f1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 5 additions & 2 deletions packages/wx-react/miniprogram_dist/AllComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@ export class Component extends BaseComponent {
}

const subVnode = this.render()
if (subVnode && subVnode.isReactElement) {
subVnode.isFirstEle = true
}

/// 重置实例字段:_or 旧的渲染数据, _r 渲染数据, _c 所以孩子实例 , __eventHanderMap 方法回调map

Expand Down Expand Up @@ -373,8 +376,8 @@ export class Component extends BaseComponent {
/* eslint-disable-next-line */
while (true) {
const pp = p._p
if (pp.isPageComp || !p._isFirstEle) {
const stylePath = `${p._keyPath}style`
if (pp.isPageComp || !p._isFirstEle || p._TWFBStylePath) {
const stylePath = p._TWFBStylePath || `${p._keyPath}style`
setDeepData(pp, newOutStyle, stylePath)

const diuu = pp.__diuu__
Expand Down
9 changes: 6 additions & 3 deletions packages/wx-react/miniprogram_dist/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default function render(vnode, parentInst, parentContext, data, oldData,
} else if (k === 'mode') {
data[`${vnodeDiuu}${k}`] = resizeMode(v)
} else if (k === 'style' && finalNodeType !== 'TouchableWithoutFeedback') {
data[`${vnodeDiuu}${k}`] = tackleWithStyleObj(v, isFirstEle ? finalNodeType : null)
data[`${vnodeDiuu}${k}`] = tackleWithStyleObj(v, (isFirstEle || vnode.TWFBStylePath) ? finalNodeType : null)
} else if (k === 'activeOpacity') {
data[`${vnodeDiuu}hoverClass`] = activeOpacityHandler(v)
} else {
Expand Down Expand Up @@ -120,8 +120,7 @@ export default function render(vnode, parentInst, parentContext, data, oldData,
}

if (props.original === 'TouchableWithoutFeedback') {
// isFirstEle 需要往外上报样式
children[0].isFirstEle = true
children[0].TWFBStylePath = `${dataPath}.${vnodeDiuu}style`
}

for (let i = 0; i < children.length; i++) {
Expand Down Expand Up @@ -582,7 +581,11 @@ export default function render(vnode, parentInst, parentContext, data, oldData,

inst.__eventHanderMap = {}

// _TWFBStylePath, _isFirstEle两个字段 FuncComp 不需要设置,因为他们只有在setState的起作用
inst._isFirstEle = isFirstEle
if (vnode.TWFBStylePath) {
inst._TWFBStylePath = vnode.TWFBStylePath
}

const subVnode = inst.render()
if (subVnode && subVnode.isReactElement) {
Expand Down

0 comments on commit 3f5d8f1

Please sign in to comment.