refactor(android): centralize clipboard handling

This commit is contained in:
Daniel Arantes Loverde
2026-04-17 14:44:27 -03:00
parent 3c78f2558e
commit 246e1a272b
4 changed files with 36 additions and 19 deletions

View File

@@ -11,6 +11,10 @@ import CoreGraphics
import UIKit
#endif
#if canImport(AppKit)
import AppKit
#endif
#if !canImport(UIKit)
struct UIDevice {
static let topNotch = 0.0
@@ -32,6 +36,31 @@ func printError(title: String, msg: String) {
}
#endif
func appReadClipboardText() -> String? {
#if canImport(UIKit)
return UIPasteboard.general.string
#elseif canImport(AppKit)
return NSPasteboard.general.string(forType: .string)
#elseif os(Android)
return UIPasteboard.general.string
#else
return nil
#endif
}
func appWriteClipboardText(_ value: String) {
#if canImport(UIKit)
UIPasteboard.general.string = value
#elseif canImport(AppKit)
NSPasteboard.general.clearContents()
NSPasteboard.general.setString(value, forType: .string)
#elseif os(Android)
UIPasteboard.general.string = value
#else
_ = value
#endif
}
extension View {
@ViewBuilder
func appInlineNavigationTitle() -> some View {