From 85e77150b275dc67c36487a221b341148d055125 Mon Sep 17 00:00:00 2001 From: sunxiaojian Date: Wed, 31 Mar 2021 10:37:38 +0800 Subject: [PATCH] fix: avatar image delete and restore --- .../xcshareddata/swiftpm/Package.resolved | 2 +- .../Scene/Compose/ComposeViewController.swift | 2 +- .../MastodonRegisterViewController+Avatar.swift | 2 -- .../MastodonRegisterViewController.swift | 17 ++++++++++++++++- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Mastodon.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Mastodon.xcworkspace/xcshareddata/swiftpm/Package.resolved index 4f2051528..89055cd4a 100644 --- a/Mastodon.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Mastodon.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -105,7 +105,7 @@ "repositoryURL": "https://github.com/MainasuK/TwitterTextEditor", "state": { "branch": "feature/input-view", - "revision": "03e7b7497d424d96268f5bcca1f8e9955bb80fea", + "revision": "1e565d13e3c26fc2bedeb418890df42f80d6e3d5", "version": null } }, diff --git a/Mastodon/Scene/Compose/ComposeViewController.swift b/Mastodon/Scene/Compose/ComposeViewController.swift index 5e3a6a8a9..9df1225ed 100644 --- a/Mastodon/Scene/Compose/ComposeViewController.swift +++ b/Mastodon/Scene/Compose/ComposeViewController.swift @@ -98,7 +98,7 @@ final class ComposeViewController: UIViewController, NeedsDependency { }() private(set) lazy var documentPickerController: UIDocumentPickerViewController = { - let documentPickerController = UIDocumentPickerViewController(documentTypes: ["public.image"], in: .open) + let documentPickerController = UIDocumentPickerViewController(forOpeningContentTypes: [.image]) documentPickerController.delegate = self return documentPickerController }() diff --git a/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewController+Avatar.swift b/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewController+Avatar.swift index 3a25fad74..5c5f77600 100644 --- a/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewController+Avatar.swift +++ b/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewController+Avatar.swift @@ -35,7 +35,6 @@ extension MastodonRegisterViewController { let deleteAction = UIAction(title: L10n.Scene.Register.Input.Avatar.delete, image: UIImage(systemName: "delete.left"), identifier: nil, discoverabilityTitle: nil, attributes: [], state: .off) { [weak self] _ in guard let self = self else { return } self.viewModel.avatarImage.value = nil - self.avatarButton.setImage(nil, for: .normal) } children.append(deleteAction) } @@ -126,7 +125,6 @@ extension MastodonRegisterViewController: UIDocumentPickerDelegate { extension MastodonRegisterViewController: CropViewControllerDelegate { public func cropViewController(_ cropViewController: CropViewController, didCropToImage image: UIImage, withRect cropRect: CGRect, angle: Int) { self.viewModel.avatarImage.value = image - self.avatarButton.setImage(image, for: .normal) cropViewController.dismiss(animated: true, completion: nil) } } diff --git a/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewController.swift b/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewController.swift index 8f0162cd3..2bfa138b4 100644 --- a/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewController.swift +++ b/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewController.swift @@ -38,7 +38,7 @@ final class MastodonRegisterViewController: UIViewController, NeedsDependency, O }() private(set) lazy var documentPickerController: UIDocumentPickerViewController = { - let documentPickerController = UIDocumentPickerViewController(documentTypes: ["public.image"], in: .open) + let documentPickerController = UIDocumentPickerViewController(forOpeningContentTypes: [.image]) documentPickerController.delegate = self return documentPickerController }() @@ -500,6 +500,21 @@ extension MastodonRegisterViewController { } .store(in: &disposeBag) + viewModel.avatarImage + .receive(on: DispatchQueue.main) + .sink{ [weak self] image in + guard let self = self else { return } + self.avatarButton.menu = self.createMediaContextMenu() + if let avatar = image { + self.avatarButton.setImage(avatar, for: .normal) + } else { + let boldFont = UIFont.systemFont(ofSize: 42) + let configuration = UIImage.SymbolConfiguration(font: boldFont) + let image = UIImage(systemName: "person.fill.viewfinder", withConfiguration: configuration) + self.avatarButton.setImage(image?.withRenderingMode(UIImage.RenderingMode.alwaysTemplate), for: UIControl.State.normal) + } + } + .store(in: &disposeBag) NotificationCenter.default .publisher(for: UITextField.textDidChangeNotification, object: usernameTextField) .receive(on: DispatchQueue.main)