Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sizeWithTemplateItem:measureSize: return abnormal size #451

Merged

Conversation

JohnTsaii
Copy link
Collaborator

@CLAassistant
Copy link

CLAassistant commented Oct 17, 2023

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ jingcheng1988
❌ JohnTsaii
You have signed the CLA already but the status is still pending? Let us recheck it.

@JohnTsaii
Copy link
Collaborator Author

@jingcheng1988 这个pr有问题吗?你们是否也遇到了size计算不对的问题

@jingcheng1988
Copy link
Collaborator

@jingcheng1988 这个pr有问题吗?你们是否也遇到了size计算不对的问题

我这边review一下开源的代码,在main分支上提供轻量化的处理方案,你可以验证一下是否修复了你的问题

@JohnTsaii
Copy link
Collaborator Author

demo.zip
data:
{
"flowerDTO": {
"title": "送您1个小礼物",
"content": "感谢xxxxxxxxxxxx,很热情,主动帮我111111~",
"time": "08-11 16:40",
"customerNo": "xxxxxx",
"orderNo": "111111111",
"url": "查看全部"
}
}
并未修复这个问题,上面是我们的demo 你可以看一下 @jingcheng1988

@jingcheng1988
Copy link
Collaborator

jingcheng1988 commented Oct 20, 2023

demo.zip data: { "flowerDTO": { "title": "送您1个小礼物", "content": "感谢xxxxxxxxxxxx,很热情,主动帮我111111~", "time": "08-11 16:40", "customerNo": "xxxxxx", "orderNo": "111111111", "url": "查看全部" } } 并未修复这个问题,上面是我们的demo 你可以看一下 @jingcheng1988

根据你提供的模板和数据,我进行本地模拟,得出的结果如下:
视图创建:<GXRootView: 0x11b70a8f0; frame = (10 140; 370 169); clipsToBounds = YES; backgroundColor = UIExtendedSRGBColorSpace 0.247059 0.584314 0.631373 1; layer = <CALayer: 0x2806d50a0>>
size计算:NSSize: {370, 169}

创建的视图和实际计算出来的尺寸是一致的

@jingcheng1988
Copy link
Collaborator

我这边复现了一下,发现是一个临界case,最终的原因是由于 paraStyle.lineBreakMode = NSLineBreakByCharWrapping;
计算和creatview的最终是不一致导致的

// 生成AttributedString
NSMutableAttributedString *attrStr = nil;
if (attributeText) {
attrStr = [[NSMutableAttributedString alloc] initWithAttributedString:attributeText];
} else {
attrStr = [[NSMutableAttributedString alloc] initWithString:text];
}

//增加段落 & font属性
NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
paraStyle.lineBreakMode = NSLineBreakByCharWrapping;
[attrStr addAttribute:NSParagraphStyleAttributeName value:paraStyle range:NSMakeRange(0, text.length)];    

@jingcheng1988 jingcheng1988 merged commit bc0e8e9 into alibaba:main Oct 20, 2023
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants