From eb2057d14e840266401f4c3d17f1f8e3c2dc63f4 Mon Sep 17 00:00:00 2001 From: sunxiaojian Date: Tue, 2 Mar 2021 16:39:43 +0800 Subject: [PATCH] chore: make sure to crop the image into a square --- .../Register/MastodonRegisterViewController+Avatar.swift | 5 +++-- .../Onboarding/Register/MastodonRegisterViewController.swift | 3 --- .../Onboarding/Register/MastodonRegisterViewModel.swift | 1 + 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewController+Avatar.swift b/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewController+Avatar.swift index 67bd2629e..9b3937122 100644 --- a/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewController+Avatar.swift +++ b/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewController+Avatar.swift @@ -21,7 +21,8 @@ extension MastodonRegisterViewController: CropViewControllerDelegate, PHPickerVi DispatchQueue.main.async { let cropController = CropViewController(croppingStyle: .default, image: image) cropController.delegate = self - self.image = image + cropController.setAspectRatioPreset(.presetSquare, animated: true) + cropController.aspectRatioLockEnabled = true picker.dismiss(animated: true, completion: { self.present(cropController, animated: true, completion: nil) }) @@ -30,7 +31,7 @@ extension MastodonRegisterViewController: CropViewControllerDelegate, PHPickerVi } public func cropViewController(_ cropViewController: CropViewController, didCropToImage image: UIImage, withRect cropRect: CGRect, angle: Int) { - self.image = image + self.viewModel.avatarImage.value = image self.photoButton.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 cc64be1f0..81dc16f75 100644 --- a/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewController.swift +++ b/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewController.swift @@ -17,9 +17,6 @@ final class MastodonRegisterViewController: UIViewController, NeedsDependency, O weak var context: AppContext! { willSet { precondition(!isViewLoaded) } } weak var coordinator: SceneCoordinator! { willSet { precondition(!isViewLoaded) } } - // avater image - var image: UIImage? - var viewModel: MastodonRegisterViewModel! let tapGestureRecognizer = UITapGestureRecognizer.singleTapGestureRecognizer diff --git a/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewModel.swift b/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewModel.swift index a32e5d040..9e244c2de 100644 --- a/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewModel.swift +++ b/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewModel.swift @@ -24,6 +24,7 @@ final class MastodonRegisterViewModel { let email = CurrentValueSubject("") let password = CurrentValueSubject("") let reason = CurrentValueSubject("") + let avatarImage = CurrentValueSubject(nil) // output let approvalRequired: Bool