This commit is contained in:
Daniel Arantes Loverde
2026-06-03 14:31:11 -03:00
parent 69dd67b8a5
commit 74848192a0
28 changed files with 134 additions and 617 deletions

View File

@@ -1,9 +1,6 @@
#if !os(Android)
import SwiftUI
#if canImport(PhotosUI) && os(iOS)
#if os(iOS)
import PhotosUI
#endif
#if canImport(UIKit)
import UIKit
#endif
@@ -17,8 +14,8 @@ struct UserProfileView: View {
@State var profilePicture: String = ""
@State var isSaving = false
#if canImport(PhotosUI) && os(iOS)
@State var selectedPhotoItem: PhotosPickerItem?
#if os(iOS)
@State private var selectedPhotoItem: PhotosPickerItem?
#endif
var body: some View {
@@ -38,7 +35,7 @@ struct UserProfileView: View {
.onAppear {
hydrateFromAppState()
}
#if canImport(PhotosUI) && os(iOS)
#if os(iOS)
.onChange(of: selectedPhotoItem) { _, newItem in
Task { await applySelectedPhoto(newItem) }
}
@@ -63,7 +60,7 @@ struct UserProfileView: View {
}
HStack(spacing: 10) {
#if canImport(PhotosUI) && os(iOS)
#if os(iOS)
PhotosPicker(selection: $selectedPhotoItem, matching: .images, photoLibrary: .shared()) {
Text("Trocar Foto")
.font(AppTypography.caption)
@@ -244,19 +241,15 @@ struct UserProfileView: View {
}
}
#if canImport(PhotosUI) && os(iOS)
#if os(iOS)
@MainActor
private func applySelectedPhoto(_ item: PhotosPickerItem?) async {
guard let item else { return }
do {
guard let data = try await item.loadTransferable(type: Data.self) else { return }
#if canImport(UIKit)
guard let image = UIImage(data: data),
let jpegData = image.jpegData(compressionQuality: 0.82) else { return }
profilePicture = "data:image/jpeg;base64,\(jpegData.base64EncodedString())"
#else
profilePicture = "data:image/jpeg;base64,\(data.base64EncodedString())"
#endif
} catch {
SnackbarCenter.shared.show(
title: "Não foi possível carregar a foto selecionada.",
@@ -268,4 +261,3 @@ struct UserProfileView: View {
}
#endif
}
#endif