fix: avatar image delete and restore

This commit is contained in:
sunxiaojian 2021-03-31 10:37:38 +08:00
parent ca25d43f4f
commit 85e77150b2
4 changed files with 18 additions and 5 deletions

View File

@ -105,7 +105,7 @@
"repositoryURL": "https://github.com/MainasuK/TwitterTextEditor",
"state": {
"branch": "feature/input-view",
"revision": "03e7b7497d424d96268f5bcca1f8e9955bb80fea",
"revision": "1e565d13e3c26fc2bedeb418890df42f80d6e3d5",
"version": null
}
},

View File

@ -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
}()

View File

@ -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)
}
}

View File

@ -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)