Skip to content

Commit 509f49d

Browse files
committed
feat: 屏幕尺寸变化时仅重新渲染使用rpx/vw/vh单位的组件
1 parent ba370b1 commit 509f49d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

packages/core/src/platform/builtInMixins/styleHelperMixin.ios.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,23 @@ const unit = {
7979

8080
const empty = {}
8181

82+
let needPageSize = false
83+
8284
function formatValue (value, unitType) {
8385
if (!dimensionsInfoInitialized) useDimensionsInfo(global.__mpxAppDimensionsInfo)
8486
if (unitType === 'hairlineWidth') {
8587
return StyleSheet.hairlineWidth
8688
}
8789
if (unitType && typeof unit[unitType] === 'function') {
90+
needPageSize = true
8891
return unit[unitType](+value)
8992
}
9093
const matched = unitRegExp.exec(value)
9194
if (matched) {
9295
if (!matched[2] || matched[2] === 'px') {
9396
return +matched[1]
9497
} else {
98+
needPageSize = true
9599
return unit[matched[2]](+matched[1])
96100
}
97101
}
@@ -254,11 +258,10 @@ export default function styleHelperMixin () {
254258
return concat(staticClass, stringifyDynamicClass(dynamicClass))
255259
},
256260
__getStyle (staticClass, dynamicClass, staticStyle, dynamicStyle, hide) {
261+
needPageSize = false
257262
const isNativeStaticStyle = staticStyle && isNativeStyle(staticStyle)
258263
let result = isNativeStaticStyle ? [] : {}
259264
const mergeResult = isNativeStaticStyle ? (...args) => result.push(...args) : (...args) => Object.assign(result, ...args)
260-
// 使用一下 __getSizeCount 触发其 get
261-
this.__getSizeCount()
262265

263266
if (staticClass || dynamicClass) {
264267
// todo 当前为了复用小程序unocss产物,暂时进行mpEscape,等后续正式支持unocss后可不进行mpEscape
@@ -319,6 +322,10 @@ export default function styleHelperMixin () {
319322
})
320323
}
321324
const isEmpty = isNativeStaticStyle ? !result.length : isEmptyObject(result)
325+
if (needPageSize) {
326+
// 使用一下 __getSizeCount 触发其 get
327+
this.__getSizeCount()
328+
}
322329
return isEmpty ? empty : result
323330
}
324331
}

0 commit comments

Comments
 (0)