refactor(android): centralize clipboard handling
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -181,31 +181,20 @@ struct OtpView: View {
|
||||
}
|
||||
|
||||
private func pasteOtpFromClipboard() {
|
||||
#if canImport(UIKit)
|
||||
let raw = UIPasteboard.general.string ?? ""
|
||||
let raw = appReadClipboardText() ?? ""
|
||||
let digits = raw.filter(\.isNumber)
|
||||
let trimmed = String(digits.prefix(8))
|
||||
if trimmed.isEmpty == false {
|
||||
otp = trimmed
|
||||
}
|
||||
#elseif canImport(AppKit)
|
||||
let raw = NSPasteboard.general.string(forType: .string) ?? ""
|
||||
let digits = raw.filter(\.isNumber)
|
||||
let trimmed = String(digits.prefix(8))
|
||||
if trimmed.isEmpty == false {
|
||||
otp = trimmed
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private func autoFillOtpFromClipboardIfAvailable() {
|
||||
#if canImport(UIKit)
|
||||
guard otp.isEmpty else { return }
|
||||
let raw = UIPasteboard.general.string ?? ""
|
||||
let raw = appReadClipboardText() ?? ""
|
||||
let digits = raw.filter(\.isNumber)
|
||||
guard digits.count >= 8 else { return }
|
||||
otp = String(digits.prefix(8))
|
||||
#endif
|
||||
}
|
||||
|
||||
private var otpDeliveryMessage: String {
|
||||
|
||||
@@ -692,12 +692,7 @@ struct PaymentPixView: View {
|
||||
}
|
||||
|
||||
private func copyToClipboard(_ value: String) {
|
||||
#if canImport(UIKit)
|
||||
UIPasteboard.general.string = value
|
||||
#elseif canImport(AppKit)
|
||||
NSPasteboard.general.clearContents()
|
||||
NSPasteboard.general.setString(value, forType: .string)
|
||||
#endif
|
||||
appWriteClipboardText(value)
|
||||
}
|
||||
|
||||
private var parsedExpirationDate: Date? {
|
||||
|
||||
@@ -327,3 +327,7 @@ Legenda:
|
||||
- `UserProfileView+Android` agora mostra preview de avatar quando `profilePicture` está preenchido.
|
||||
- Campo de edição de foto por URL/Base64 adicionado apenas no Android.
|
||||
- `swift build` validado com sucesso após o ajuste.
|
||||
8. Padronização de clipboard cross-platform concluída para fluxos OTP/PIX.
|
||||
- Helper de clipboard centralizado em `PlatformCompat`.
|
||||
- `OtpView` e `CheckoutView` passaram a usar o helper compartilhado.
|
||||
- `swift build` validado com sucesso após o ajuste.
|
||||
|
||||
Reference in New Issue
Block a user