refactor(android): centralize clipboard handling
This commit is contained in:
@@ -11,6 +11,10 @@ import CoreGraphics
|
|||||||
import UIKit
|
import UIKit
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if canImport(AppKit)
|
||||||
|
import AppKit
|
||||||
|
#endif
|
||||||
|
|
||||||
#if !canImport(UIKit)
|
#if !canImport(UIKit)
|
||||||
struct UIDevice {
|
struct UIDevice {
|
||||||
static let topNotch = 0.0
|
static let topNotch = 0.0
|
||||||
@@ -32,6 +36,31 @@ func printError(title: String, msg: String) {
|
|||||||
}
|
}
|
||||||
#endif
|
#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 {
|
extension View {
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
func appInlineNavigationTitle() -> some View {
|
func appInlineNavigationTitle() -> some View {
|
||||||
|
|||||||
@@ -181,31 +181,20 @@ struct OtpView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func pasteOtpFromClipboard() {
|
private func pasteOtpFromClipboard() {
|
||||||
#if canImport(UIKit)
|
let raw = appReadClipboardText() ?? ""
|
||||||
let raw = UIPasteboard.general.string ?? ""
|
|
||||||
let digits = raw.filter(\.isNumber)
|
let digits = raw.filter(\.isNumber)
|
||||||
let trimmed = String(digits.prefix(8))
|
let trimmed = String(digits.prefix(8))
|
||||||
if trimmed.isEmpty == false {
|
if trimmed.isEmpty == false {
|
||||||
otp = trimmed
|
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() {
|
private func autoFillOtpFromClipboardIfAvailable() {
|
||||||
#if canImport(UIKit)
|
|
||||||
guard otp.isEmpty else { return }
|
guard otp.isEmpty else { return }
|
||||||
let raw = UIPasteboard.general.string ?? ""
|
let raw = appReadClipboardText() ?? ""
|
||||||
let digits = raw.filter(\.isNumber)
|
let digits = raw.filter(\.isNumber)
|
||||||
guard digits.count >= 8 else { return }
|
guard digits.count >= 8 else { return }
|
||||||
otp = String(digits.prefix(8))
|
otp = String(digits.prefix(8))
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private var otpDeliveryMessage: String {
|
private var otpDeliveryMessage: String {
|
||||||
|
|||||||
@@ -692,12 +692,7 @@ struct PaymentPixView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func copyToClipboard(_ value: String) {
|
private func copyToClipboard(_ value: String) {
|
||||||
#if canImport(UIKit)
|
appWriteClipboardText(value)
|
||||||
UIPasteboard.general.string = value
|
|
||||||
#elseif canImport(AppKit)
|
|
||||||
NSPasteboard.general.clearContents()
|
|
||||||
NSPasteboard.general.setString(value, forType: .string)
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private var parsedExpirationDate: Date? {
|
private var parsedExpirationDate: Date? {
|
||||||
|
|||||||
@@ -327,3 +327,7 @@ Legenda:
|
|||||||
- `UserProfileView+Android` agora mostra preview de avatar quando `profilePicture` está preenchido.
|
- `UserProfileView+Android` agora mostra preview de avatar quando `profilePicture` está preenchido.
|
||||||
- Campo de edição de foto por URL/Base64 adicionado apenas no Android.
|
- Campo de edição de foto por URL/Base64 adicionado apenas no Android.
|
||||||
- `swift build` validado com sucesso após o ajuste.
|
- `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