pref(rn): 优化全尺寸 linear-gradient 背景渲染时机#2521
Open
dos1in wants to merge 5 commits into
Open
Conversation
hiyuki
reviewed
Jul 1, 2026
Member
Author
valid-show-hide.mp4验证看起没问题,验证逻辑如下: |
hiyuki
reviewed
Jul 7, 2026
| // 数值类型设置为 stretch | ||
| imageProps.resizeMode = 'stretch' | ||
| if (type === 'linear' && (!layoutWidth || !layoutHeight) && (isPercent(width) || isPercent(height))) { | ||
| if (type === 'linear' && width === '100%' && height === '100%' && (!layoutWidth || !layoutHeight)) { |
Collaborator
There was a problem hiding this comment.
&& (!layoutWidth || !layoutHeight) 最后这个条件不需要了吧
Member
Author
There was a problem hiding this comment.
需要的,没拿到容器宽高时可以直接让 100% 100% 的渐变铺满父容器;但拿到宽高后要用它重新计算位置或角度,不能一律走铺满逻辑。
Collaborator
There was a problem hiding this comment.
如果依赖layout计算角度或者位置的话本身isNeedLayout会返回为true,背景图只有在layout后才会展示,你当前这个改动生效的核心条件就是扩宽了isNeedLayout的判定条件,让没有角度且高宽为100%的情况isNeedLayout返回false,让首次渲染不等待layout,如果命中其他条件让isNeedLayout返回false的话你当前这个改动逻辑是不会被命中的
Collaborator
There was a problem hiding this comment.
而且对于size来说用absolute铺满还是设置高宽100%结果是一样的吧
Member
Author
There was a problem hiding this comment.
我理解是会闪,但保留它主要是为了把这个“铺满父容器”的特殊处理只用在首次还没拿到 layout 的时候;如果已经拿到 layout,就继续按原来的 width: 100% / height: 100% 走,避免额外带上 top/right/bottom/left: 0 改变其它位置相关逻辑。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
默认全尺寸的渐变色 linear-gradient 无差别等待 onLayout 导致首帧显示变慢,做了以下优化:
before.mp4
after.mp4