onevcat / OneV-s-Den-Comments

0 stars 0 forks source link

2021/03/swiftui-text-2/ #17

Open utterances-bot opened 3 years ago

utterances-bot commented 3 years ago

SwiftUI 中的 Text 插值和本地化 (下) | OneV's Den

在上篇中,我们已经看到为什么 Text,或者更准确地说,LocalizedStringKey,可以接受 Image 和 Date,而不能接受 Bool 或者自定义的 Person 类型了。在这下篇中,让我们具体看看有哪些方法能让 Text 支持其他类型。

https://onevcat.com/2021/03/swiftui-text-2/

snake326 commented 3 years ago

瞄大YYDS,有一个关于 iOS widget 的技术问题,想请教一下。最近,我在研究 Widget 官方的动画效果是如何实现的,通过 调用Widget 的私有 API _clockHandRotationEffect,使用 dump 和反射,我拿到了 _clockDatePublisher,我使用 .sink 去接收事件,但事件只发了一次,后续就停止了,无法通过接收这个事件,实现自定义动画的效果,但同样的代码,App 是可以持续接收到事件的,想问问博主,这个问题,该如何往下探索呢?也试过 dump Text dateStyle,但没有找到探索的方向。谢谢

onevcat commented 3 years ago

@snake326 大概猜测还是有什么限制吧..而且这种做法怕是很难过审核?我没有研究过...在这个话题上我落后你太多了,感觉给不出什么建议 😂

snake326 commented 3 years ago

我看到 App Store 上有挺多好像实现了类似动画效果的产品,想着研究他们是如何实现😂,感谢瞄大

ApolloZhu commented 1 year ago

喵神您好,我最近正好在研究这个问题,发现把 Person 的 _specifier 改成 "%lld" 之后还是会在 Export Localizations… 的时候变成 "%@"。可能插值的格式是并不完全是由 _FormatSpecifiable 确定的?

onevcat commented 1 year ago

@ApolloZhu 确实,我可以在 Xcode 14.2 里验证你说的这个结果。这就比较迷惑了。我现在不太清楚这是一个最近的改动(bug)还是是一直就有的问题,现在看起来在生成 LocalizedStringKey 时,似乎完全无视了 _FormatSpecifiable 的类型定义。但是如果 _arg_specifier 类型不匹配的话,是不是会导致在 runtime 挂掉...?

当时写这篇文章的时候应该是验证过,结果自恰才会作为结论写上去的。所以我现在有点怀疑是不是中途哪个 SwiftUI 的版本在内部改了这部分。

ApolloZhu commented 1 year ago

因为需要在编译时知道具体的值,看 swiftinterface 里的定义,可能 _FormatSpecifiable 默认用 formatSpecifier<T>(_ type: T.Type) 里返回的 specifier(所以自定义的是 default "%@"),然后其他的根据 @_semantics 来判断。

https://github.com/xybp888/iOS-SDKs/blob/fa4a2d866231985fa9538fafc800421aa99b83f2/iPhoneOS16.2.sdk/System/Library/Frameworks/SwiftUI.framework/Modules/SwiftUI.swiftmodule/arm64e-apple-ios.swiftinterface#LL11755-L11758

https://github.com/xybp888/iOS-SDKs/blob/fa4a2d866231985fa9538fafc800421aa99b83f2/iPhoneOS16.2.sdk/System/Library/Frameworks/SwiftUI.framework/Modules/SwiftUI.swiftmodule/arm64e-apple-ios.swiftinterface#L11790-L11821

cuixiang081 commented 1 year ago

@snake326 大哥,你找到实现widget动画的方法没,能不能给点思路

simonhulu commented 1 year ago

@snake326 大哥,你找到实现widget动画的方法没,能不能给点思路

simonhulu commented 1 year ago

关于动画,想了解的开发同仁加qq 177133683或者通过邮箱联系177133683@qq.com

cuixiang081 commented 1 year ago

Eilgnaw/WidgetAnimationgithub.com已经有大神开源了在 2023年8月20日,09:30,simonHulu @.> 写道: 关于动画,想了解的开发同仁加qq @.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>