Skip to content

Commit

Permalink
Merge pull request #278 from depromeet/fix/#277-fix-회원가입-프로필-사진-이슈사항-해결
Browse files Browse the repository at this point in the history
  • Loading branch information
YuGeonHui authored Jan 15, 2024
2 parents 3511be1 + 60ac4c0 commit d16ab25
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extension String {
enum Nickname {
static let title: String = "닉네임을 입력해주세요"
static let placeholder: String = "김아빠"
static let errorMsg: String = "10자 이내로 입력해주세요"
static let errorMsg: String = "9자 이내로 입력해주세요"
static var desc: String = "가족에게 주로 불리는 호칭을 입력해주세요"
}
enum Date {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public final class AccountSignUpReactor: Reactor {
case setDay(Int?)
case didTapDateNextButton

case profileImageTapped // Action Sheet출력 하는 이벤트
case didTapCompletehButton
case profilePresignedURL(String, Data)
case didTapPHAssetsImage(Data)
Expand All @@ -46,7 +45,6 @@ public final class AccountSignUpReactor: Reactor {
case didTapDateNextButton
case setEditNickName(AccountNickNameEditResponse?)

case profileImageTapped
case setprofilePresignedURL(String)
case setprofileImage(Data)
case didTapCompletehButton(AccessTokenResponse?)
Expand All @@ -72,7 +70,6 @@ public final class AccountSignUpReactor: Reactor {
var profileType: AccountLoaction = .account

var profilePresignedURL: String = ""
var profileImageButtontapped: Bool = false
var profileImage: Data? = nil
var didTapCompletehButtonFinish: AccessTokenResponse? = nil
}
Expand Down Expand Up @@ -110,9 +107,6 @@ extension AccountSignUpReactor {
return Observable.just(Mutation.didTapDateNextButton)

// MARK: Profile
case .profileImageTapped:
return Observable.just(Mutation.profileImageTapped)

case let .profilePresignedURL(presignedURL, originImage):
return .concat(
.just(.setprofilePresignedURL(presignedURL)),
Expand Down Expand Up @@ -202,8 +196,6 @@ extension AccountSignUpReactor {
newState.dateButtonTappedFinish = true
case .setprofilePresignedURL(let url):
newState.profilePresignedURL = url
case .profileImageTapped:
newState.profileImageButtontapped = true
case let .setprofileImage(profileImage):
newState.profileImage = profileImage
case .didTapCompletehButton(let token):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,23 @@ final class AccountProfileViewController: BaseViewController<AccountSignUpReacto
private let titleLabel = BibbiLabel(.head2Bold, alignment: .center, textColor: .gray300)
private let profileButton = UIButton()

private var pickerConfiguration: PHPickerConfiguration = {
var configuration: PHPickerConfiguration = PHPickerConfiguration()
configuration.filter = .images
configuration.selectionLimit = 1
configuration.selection = .default
return configuration
}()
private lazy var profilePickerController: PHPickerViewController = PHPickerViewController(configuration: pickerConfiguration)

private let nextButton = UIButton()
private let profileView = UIImageView()
private let cameraView = UIImageView()

override func viewDidLoad() {
super.viewDidLoad()

profilePickerController.delegate = self
}

override func bind(reactor: AccountSignUpReactor) {
Expand All @@ -44,9 +55,9 @@ final class AccountProfileViewController: BaseViewController<AccountSignUpReacto
.disposed(by: disposeBag)

profileButton.rx.tap
.throttle(RxConst.throttleInterval, scheduler: Schedulers.main)
.map { Reactor.Action.profileImageTapped }
.bind(to: reactor.action)
.throttle(RxConst.throttleInterval, scheduler: MainScheduler.instance)
.withUnretained(self)
.bind(onNext: { $0.0.createAlertController(owner: $0.0) })
.disposed(by: disposeBag)

NotificationCenter.default.rx
Expand Down Expand Up @@ -82,14 +93,21 @@ final class AccountProfileViewController: BaseViewController<AccountSignUpReacto
.observe(on: Schedulers.main)
.bind(onNext: { $0.0.showNextPage(accessToken: $0.1) })
.disposed(by: disposeBag)


NotificationCenter.default.rx
.notification(.PHPickerAssetsDidFinishPickingProcessingPhotoNotification)
.compactMap { notification -> Data? in
guard let userInfo = notification.userInfo else { return nil }
return userInfo["selectImage"] as? Data
}
.map{ Reactor.Action.didTapPHAssetsImage($0)}
.bind(to: reactor.action)
.disposed(by: disposeBag)
}

override func setupUI() {
super.setupUI()

profileView.addSubview(cameraView)
view.addSubviews(titleLabel, profileButton, nextButton, profileView)
view.addSubviews(titleLabel, profileButton, profileView, cameraView, nextButton)
}

override func setupAutoLayout() {
Expand All @@ -113,7 +131,8 @@ final class AccountProfileViewController: BaseViewController<AccountSignUpReacto
}

cameraView.snp.makeConstraints {
$0.bottom.trailing.equalToSuperview()
$0.centerX.equalToSuperview().offset(35)
$0.top.equalTo(titleLabel.snp.bottom).offset(90)
$0.width.height.equalTo(28)
}

Expand All @@ -135,6 +154,12 @@ final class AccountProfileViewController: BaseViewController<AccountSignUpReacto
$0.layer.cornerRadius = 45
}

profileView.do {
$0.contentMode = .scaleAspectFill
$0.layer.cornerRadius = 45
$0.clipsToBounds = true
}

cameraView.do {
$0.image = DesignSystemAsset.cameraCircle.image
$0.contentMode = .scaleAspectFit
Expand All @@ -159,6 +184,7 @@ extension AccountProfileViewController {

if let firstName = nickname.first {
profileButton.setTitle(String(firstName), for: .normal)
profileButton.titleLabel?.font = UIFont(font: DesignSystemFontFamily.Pretendard.semiBold, size: 28)
}
}

Expand All @@ -178,3 +204,38 @@ extension AccountProfileViewController {
present(container, animated: false)
}
}

extension AccountProfileViewController {
private func createAlertController(owner: AccountProfileViewController) {
let alertController: UIAlertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
let presentCameraAction: UIAlertAction = UIAlertAction(title: "카메라", style: .default) { _ in
let cameraViewController = CameraDIContainer(cameraType: .profile).makeViewController()
owner.navigationController?.pushViewController(cameraViewController, animated: true)
}
let presentAlbumAction: UIAlertAction = UIAlertAction(title: "앨범", style: .default) { _ in
self.profilePickerController.modalPresentationStyle = .fullScreen
self.profilePickerController.overrideUserInterfaceStyle = .dark
self.present(self.profilePickerController, animated: true)
}
let presentCancelAction: UIAlertAction = UIAlertAction(title: "취소", style: .cancel, handler: nil)
presentCancelAction.setValue(UIColor.red, forKey: "titleTextColor")

[presentCameraAction, presentAlbumAction, presentCancelAction].forEach { alertController.addAction($0) }
alertController.overrideUserInterfaceStyle = .dark
owner.present(alertController, animated: true)
}
}

extension AccountProfileViewController: PHPickerViewControllerDelegate {
public func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
let itemProvider = results.first?.itemProvider
picker.dismiss(animated: true)
if let imageProvider = itemProvider, imageProvider.canLoadObject(ofClass: UIImage.self) {
imageProvider.loadObject(ofClass: UIImage.self) { image, error in
guard let photoImage: UIImage = image as? UIImage,
let originalData: Data = photoImage.jpegData(compressionQuality: 1.0) else { return }
imageProvider.didSelectProfileImageWithProcessing(photo: originalData, error: error)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,19 @@
import UIKit
import Core
import DesignSystem
import PhotosUI

fileprivate typealias _Str = AccountSignUpStrings
public final class AccountSignUpViewController: BasePageViewController<AccountSignUpReactor> {
private let nextButton = UIButton()
private let descLabel = UILabel()

private var pickerConfiguration: PHPickerConfiguration = {
var configuration: PHPickerConfiguration = PHPickerConfiguration()
configuration.filter = .images
configuration.selectionLimit = 1
configuration.selection = .default
return configuration
}()
private lazy var profilePickerController: PHPickerViewController = PHPickerViewController(configuration: pickerConfiguration)

private var pages = [UIViewController]()
private var initalPage = 0

public override func viewDidLoad() {
super.viewDidLoad()

dataSource = self
profilePickerController.delegate = self
setViewControllers([pages[initalPage]], direction: .forward, animated: true)
isPagingEnabled = false
}
Expand All @@ -50,24 +39,6 @@ public final class AccountSignUpViewController: BasePageViewController<AccountSi
.withUnretained(self)
.bind(onNext: { $0.0.goToNextPage() })
.disposed(by: disposeBag)

reactor.state.map { $0.profileImageButtontapped }
.filter { $0 }
.observe(on: Schedulers.main)
.withUnretained(self)
.bind(onNext: { $0.0.createAlertController(owner: $0.0) })
.disposed(by: disposeBag)

NotificationCenter.default.rx
.notification(.PHPickerAssetsDidFinishPickingProcessingPhotoNotification)
.compactMap { notification -> Data? in
guard let userInfo = notification.userInfo else { return nil }
return userInfo["selectImage"] as? Data
}
.map{ Reactor.Action.didTapPHAssetsImage($0)}
.bind(to: reactor.action)
.disposed(by: disposeBag)

}

public override func setupUI() {
Expand Down Expand Up @@ -111,43 +82,3 @@ extension AccountSignUpViewController: UIPageViewControllerDataSource {
return pages[currentIndex + 1]
}
}


extension AccountSignUpViewController {
private func createAlertController(owner: AccountSignUpViewController) {
let alertController: UIAlertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
let presentCameraAction: UIAlertAction = UIAlertAction(title: "카메라", style: .default) { _ in
let cameraViewController = CameraDIContainer(cameraType: .profile).makeViewController()
owner.navigationController?.pushViewController(cameraViewController, animated: true)
}
let presentAlbumAction: UIAlertAction = UIAlertAction(title: "앨범", style: .default) { _ in
self.profilePickerController.modalPresentationStyle = .fullScreen
self.profilePickerController.overrideUserInterfaceStyle = .dark
self.present(self.profilePickerController, animated: true)
}
let presentDefaultAction: UIAlertAction = UIAlertAction(title: "초기화", style: .destructive) { _ in
print("초기화 구문")
}
let presentCancelAction: UIAlertAction = UIAlertAction(title: "취소", style: .cancel, handler: nil)

[presentCameraAction, presentAlbumAction, presentDefaultAction, presentCancelAction].forEach {
alertController.addAction($0)
}
alertController.overrideUserInterfaceStyle = .dark
owner.present(alertController, animated: true)
}
}

extension AccountSignUpViewController: PHPickerViewControllerDelegate {
public func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
let itemProvider = results.first?.itemProvider
picker.dismiss(animated: true)
if let imageProvider = itemProvider, imageProvider.canLoadObject(ofClass: UIImage.self) {
imageProvider.loadObject(ofClass: UIImage.self) { image, error in
guard let photoImage: UIImage = image as? UIImage,
let originalData: Data = photoImage.jpegData(compressionQuality: 1.0) else { return }
imageProvider.didSelectProfileImageWithProcessing(photo: originalData, error: error)
}
}
}
}

0 comments on commit d16ab25

Please sign in to comment.