代码之家  ›  专栏  ›  技术社区  ›  goldwalk

(SwiftUI)当“文本”可选时,OpenURLAction将被忽略

  •  0
  • goldwalk  · 技术社区  · 1 年前

    我在尝试处理SwiftUI的超链接时遇到了一个问题 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。

    0 回复  |  直到 1 年前