Skip to content

Commit

Permalink
[Chore] sopt-makers#57 - 비밀번호 변경 후 Toast 생성 로직 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
lsj8706 committed Dec 28, 2022
1 parent 3c9685f commit e08de37
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Copyright © 2022 SOPT-Stamp-iOS. All rights reserved.
//


import UIKit

import SnapKit
Expand All @@ -17,7 +16,7 @@ public extension UIViewController {
}

public class Toast {
static func show(message: String, controller: UIViewController) {
public static func show(message: String, controller: UIViewController) {

let toastContainer = UIView()
let toastLabel = UILabel()
Expand Down Expand Up @@ -60,4 +59,48 @@ public class Toast {
})
})
}

public static func showInView(message: String, view: UIView) {

let toastContainer = UIView()
let toastLabel = UILabel()

toastContainer.backgroundColor = DSKitAsset.Colors.gray600.color
toastContainer.alpha = 1
toastContainer.layer.cornerRadius = 9
toastContainer.clipsToBounds = true
toastContainer.isUserInteractionEnabled = false

toastLabel.textColor = .white
toastLabel.textAlignment = .center
toastLabel.setTypoStyle(.caption1)
toastLabel.text = message
toastLabel.clipsToBounds = true
toastLabel.numberOfLines = 0
toastLabel.sizeToFit()

toastContainer.addSubview(toastLabel)
view.addSubview(toastContainer)

toastContainer.snp.makeConstraints {
$0.centerX.equalToSuperview()
$0.bottom.equalToSuperview().inset(40)
$0.width.equalTo(213)
$0.height.equalTo(44)
}

toastLabel.snp.makeConstraints {
$0.center.equalToSuperview()
}

UIView.animate(withDuration: 0.4, delay: 0.0, options: .curveEaseIn, animations: {
toastContainer.alpha = 1.0
}, completion: { _ in
UIView.animate(withDuration: 0.4, delay: 1.0, options: .curveEaseOut, animations: {
toastContainer.alpha = 0.0
}, completion: {_ in
toastContainer.removeFromSuperview()
})
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ public class PasswordChangeVC: UIViewController {
public var factory: ModuleFactoryInterface!
public var viewModel: PasswordChangeViewModel!
private var cancelBag = CancelBag()

@Published public var passwordChangeSuccessed = false


// MARK: - UI Components

private lazy var naviBar = CustomNavigationBar(self, type: .titleWithLeftButton)
Expand Down Expand Up @@ -91,9 +89,10 @@ extension PasswordChangeVC {

output.passwordChangeSuccessed.sink { [weak self] isSuccess in
guard let self = self else { return }
self.passwordChangeSuccessed = isSuccess
if isSuccess {
self.navigationController?.popViewController(animated: true)
let window = self.view.window!
Toast.showInView(message: I18N.Setting.passwordEditSuccess, view: window)
} else {
self.showToast(message: I18N.Setting.passwordEditFail)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,6 @@ extension SettingVC {

private func showPasswordChangeView() {
let passwordChangeVC = self.factory.makePasswordChangeVC()
passwordChangeVC.$passwordChangeSuccessed
.sink { [weak self] isSuccess in
guard let self = self else { return }
if isSuccess {
self.showToast(message: I18N.Setting.passwordEditSuccess)
}
}.store(in: cancelBag)

navigationController?.pushViewController(passwordChangeVC, animated: true)
}
}
Expand Down

0 comments on commit e08de37

Please sign in to comment.