提问人:goldwalk 提问时间:9/4/2023 更新时间:9/4/2023 访问量:137
(SwiftUI接口)当 Text 可选时,将忽略 OpenURLAction
(SwiftUI) OpenURLAction is ignored when Text is selectable
问:
我在尝试处理来自 SwiftUI 视图的超链接时遇到了一个问题。如果我选择,系统总是忽略超链接。Text
Text
.environment(\.openURL, OpenURLAction)
let attributedString = try! AttributedString(markdown: "Here's the link: [link](https://expample.com)")
...
Text(attributedString)
.environment(\.openURL, OpenURLAction(handler: { url in
.handled // works ✅
}
Text(attributedString)
.textSelection(.enabled)
.environment(\.openURL, OpenURLAction(handler: { url in
.handled // ignored ❌
}
有没有办法在手动处理超链接时保持可选?我的平台是macOS。Text
答: 暂无答案
评论
.textSelection(.enabled)
.textSelection(.disabled)
.systemAction
.handled
.textSelection(.enabled)
.systemAction
Text(attributedString)