Skip to content

Commit 68deb03

Browse files
committed
fix(rn): update linear background size handling for percentage dimensions
1 parent 918e868 commit 68deb03

File tree

1 file changed

+1
-2
lines changed
  • packages/webpack-plugin/lib/runtime/components/react

1 file changed

+1
-2
lines changed

packages/webpack-plugin/lib/runtime/components/react/mpx-view.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,15 +287,14 @@ function backgroundSize (imageProps: ImageProps, preImageInfo: PreImageInfo, ima
287287
} else { // 数值类型 ImageStyle
288288
// 数值类型设置为 stretch
289289
imageProps.resizeMode = 'stretch'
290-
if (type === 'linear' && (!layoutWidth || !layoutHeight) && isNeedLayout(preImageInfo)) {
290+
if (type === 'linear' && (!layoutWidth || !layoutHeight) && (isPercent(width) || isPercent(height))) {
291291
// ios 上 linear 组件只要重新触发渲染,在渲染过程中外层容器 width 或者 height 被设置为 0,通过设置 % 的方式会渲染不出来,即使后面再更新为正常宽高也渲染不出来
292292
// 所以 hack 手动先将 linear 宽高也设置为 0,后面再更新为正确的数值或 %。
293293
dimensions = {
294294
width: 0,
295295
height: 0
296296
} as { width: NumberVal, height: NumberVal }
297297
} else {
298-
// background-size: 100px 100px; 这种手动设置具体值的场景,不会触发 onLayout,需要走这里的逻辑(通过上面 isNeedLayout 判断)
299298
dimensions = {
300299
width: isPercent(width) ? width : +width,
301300
height: isPercent(height) ? height : +height

0 commit comments

Comments
 (0)