WIP posting photos

This commit is contained in:
Thomas Ricouard 2022-12-25 19:15:35 +01:00
parent 827e06b26c
commit 6bbe352f7e
3 changed files with 58 additions and 9 deletions

View file

@ -393,7 +393,7 @@
CODE_SIGN_IDENTITY = "-"; CODE_SIGN_IDENTITY = "-";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "Apple Development"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 350; CURRENT_PROJECT_VERSION = 400;
DEAD_CODE_STRIPPING = YES; DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"IceCubesApp/Resources\""; DEVELOPMENT_ASSET_PATHS = "\"IceCubesApp/Resources\"";
DEVELOPMENT_TEAM = Z6P74P6T99; DEVELOPMENT_TEAM = Z6P74P6T99;
@ -401,6 +401,8 @@
ENABLE_PREVIEWS = YES; ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = IceCubesApp/Info.plist; INFOPLIST_FILE = IceCubesApp/Info.plist;
INFOPLIST_KEY_NSCameraUsageDescription = "Upload photos & videos to Mastodon";
INFOPLIST_KEY_NSPhotoLibraryUsageDescription = "Upload photos & videos to Mastodon";
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES;
@ -415,7 +417,7 @@
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 13.0; MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 0.3.5; MARKETING_VERSION = 0.4;
PRODUCT_BUNDLE_IDENTIFIER = com.thomasricouard.IceCubesApp; PRODUCT_BUNDLE_IDENTIFIER = com.thomasricouard.IceCubesApp;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = auto; SDKROOT = auto;
@ -437,7 +439,7 @@
CODE_SIGN_IDENTITY = "-"; CODE_SIGN_IDENTITY = "-";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "Apple Development"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 350; CURRENT_PROJECT_VERSION = 400;
DEAD_CODE_STRIPPING = YES; DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"IceCubesApp/Resources\""; DEVELOPMENT_ASSET_PATHS = "\"IceCubesApp/Resources\"";
DEVELOPMENT_TEAM = Z6P74P6T99; DEVELOPMENT_TEAM = Z6P74P6T99;
@ -445,6 +447,8 @@
ENABLE_PREVIEWS = YES; ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = IceCubesApp/Info.plist; INFOPLIST_FILE = IceCubesApp/Info.plist;
INFOPLIST_KEY_NSCameraUsageDescription = "Upload photos & videos to Mastodon";
INFOPLIST_KEY_NSPhotoLibraryUsageDescription = "Upload photos & videos to Mastodon";
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES;
@ -459,7 +463,7 @@
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 13.0; MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 0.3.5; MARKETING_VERSION = 0.4;
PRODUCT_BUNDLE_IDENTIFIER = com.thomasricouard.IceCubesApp; PRODUCT_BUNDLE_IDENTIFIER = com.thomasricouard.IceCubesApp;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = auto; SDKROOT = auto;

View file

@ -5,6 +5,7 @@ import DesignSystem
import TextView import TextView
import Models import Models
import Network import Network
import PhotosUI
public struct StatusEditorView: View { public struct StatusEditorView: View {
@EnvironmentObject private var client: Client @EnvironmentObject private var client: Client
@ -20,10 +21,11 @@ public struct StatusEditorView: View {
public var body: some View { public var body: some View {
NavigationStack { NavigationStack {
ZStack(alignment: .bottom) { ZStack(alignment: .bottom) {
VStack { VStack(spacing: 12) {
accountHeaderView accountHeaderView
TextView($viewModel.statusText) TextView($viewModel.statusText)
.placeholder("What's on your mind") .placeholder("What's on your mind")
mediasView
Spacer() Spacer()
} }
accessoryView accessoryView
@ -64,7 +66,8 @@ public struct StatusEditorView: View {
} }
} }
@ViewBuilder private var accountHeaderView: some View { @ViewBuilder
private var accountHeaderView: some View {
if let account = currentAccount.account { if let account = currentAccount.account {
HStack { HStack {
AvatarView(url: account.avatar, size: .status) AvatarView(url: account.avatar, size: .status)
@ -81,11 +84,24 @@ public struct StatusEditorView: View {
} }
} }
private var mediasView: some View {
ScrollView(.horizontal) {
HStack {
ForEach(viewModel.mediasImages) { container in
Image(uiImage: container.image)
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 150, height: 150)
.clipped()
}
}
}
}
private var accessoryView: some View { private var accessoryView: some View {
HStack { HStack {
Button { PhotosPicker(selection: $viewModel.selectedMedias,
matching: .images) {
} label: {
Image(systemName: "photo.fill.on.rectangle.fill") Image(systemName: "photo.fill.on.rectangle.fill")
} }
Spacer() Spacer()

View file

@ -2,6 +2,7 @@ import SwiftUI
import DesignSystem import DesignSystem
import Models import Models
import Network import Network
import PhotosUI
@MainActor @MainActor
class StatusEditorViewModel: ObservableObject { class StatusEditorViewModel: ObservableObject {
@ -13,6 +14,17 @@ class StatusEditorViewModel: ObservableObject {
} }
@Published var isPosting: Bool = false @Published var isPosting: Bool = false
@Published var selectedMedias: [PhotosPickerItem] = [] {
didSet {
inflateSelectedMedias()
}
}
@Published var mediasImages: [ImageContainer] = []
struct ImageContainer: Identifiable {
let id = UUID().uuidString
let image: UIImage
}
var client: Client? var client: Client?
private var internalUpdate: Bool = false private var internalUpdate: Bool = false
@ -78,5 +90,22 @@ class StatusEditorViewModel: ObservableObject {
} }
} }
func inflateSelectedMedias() {
for media in selectedMedias {
media.loadTransferable(type: Data.self) { [weak self] result in
switch result {
case .success(let data?):
if let image = UIImage(data: data) {
DispatchQueue.main.async {
self?.mediasImages.append(.init(image: image))
}
}
default:
break
}
}
}
}
} }