fix: avatar image delete and restore
This commit is contained in:
parent
ca25d43f4f
commit
85e77150b2
|
@ -105,7 +105,7 @@
|
||||||
"repositoryURL": "https://github.com/MainasuK/TwitterTextEditor",
|
"repositoryURL": "https://github.com/MainasuK/TwitterTextEditor",
|
||||||
"state": {
|
"state": {
|
||||||
"branch": "feature/input-view",
|
"branch": "feature/input-view",
|
||||||
"revision": "03e7b7497d424d96268f5bcca1f8e9955bb80fea",
|
"revision": "1e565d13e3c26fc2bedeb418890df42f80d6e3d5",
|
||||||
"version": null
|
"version": null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -98,7 +98,7 @@ final class ComposeViewController: UIViewController, NeedsDependency {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
private(set) lazy var documentPickerController: UIDocumentPickerViewController = {
|
private(set) lazy var documentPickerController: UIDocumentPickerViewController = {
|
||||||
let documentPickerController = UIDocumentPickerViewController(documentTypes: ["public.image"], in: .open)
|
let documentPickerController = UIDocumentPickerViewController(forOpeningContentTypes: [.image])
|
||||||
documentPickerController.delegate = self
|
documentPickerController.delegate = self
|
||||||
return documentPickerController
|
return documentPickerController
|
||||||
}()
|
}()
|
||||||
|
|
|
@ -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
|
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 }
|
guard let self = self else { return }
|
||||||
self.viewModel.avatarImage.value = nil
|
self.viewModel.avatarImage.value = nil
|
||||||
self.avatarButton.setImage(nil, for: .normal)
|
|
||||||
}
|
}
|
||||||
children.append(deleteAction)
|
children.append(deleteAction)
|
||||||
}
|
}
|
||||||
|
@ -126,7 +125,6 @@ extension MastodonRegisterViewController: UIDocumentPickerDelegate {
|
||||||
extension MastodonRegisterViewController: CropViewControllerDelegate {
|
extension MastodonRegisterViewController: CropViewControllerDelegate {
|
||||||
public func cropViewController(_ cropViewController: CropViewController, didCropToImage image: UIImage, withRect cropRect: CGRect, angle: Int) {
|
public func cropViewController(_ cropViewController: CropViewController, didCropToImage image: UIImage, withRect cropRect: CGRect, angle: Int) {
|
||||||
self.viewModel.avatarImage.value = image
|
self.viewModel.avatarImage.value = image
|
||||||
self.avatarButton.setImage(image, for: .normal)
|
|
||||||
cropViewController.dismiss(animated: true, completion: nil)
|
cropViewController.dismiss(animated: true, completion: nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ final class MastodonRegisterViewController: UIViewController, NeedsDependency, O
|
||||||
}()
|
}()
|
||||||
|
|
||||||
private(set) lazy var documentPickerController: UIDocumentPickerViewController = {
|
private(set) lazy var documentPickerController: UIDocumentPickerViewController = {
|
||||||
let documentPickerController = UIDocumentPickerViewController(documentTypes: ["public.image"], in: .open)
|
let documentPickerController = UIDocumentPickerViewController(forOpeningContentTypes: [.image])
|
||||||
documentPickerController.delegate = self
|
documentPickerController.delegate = self
|
||||||
return documentPickerController
|
return documentPickerController
|
||||||
}()
|
}()
|
||||||
|
@ -500,6 +500,21 @@ extension MastodonRegisterViewController {
|
||||||
}
|
}
|
||||||
.store(in: &disposeBag)
|
.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
|
NotificationCenter.default
|
||||||
.publisher(for: UITextField.textDidChangeNotification, object: usernameTextField)
|
.publisher(for: UITextField.textDidChangeNotification, object: usernameTextField)
|
||||||
.receive(on: DispatchQueue.main)
|
.receive(on: DispatchQueue.main)
|
||||||
|
|
Loading…
Reference in New Issue