From e08de37a466ea00c645d9c0d6a5e085c62d5efc1 Mon Sep 17 00:00:00 2001 From: Sejin Lee Date: Thu, 29 Dec 2022 00:47:00 +0900 Subject: [PATCH] =?UTF-8?q?[Chore]=20#57=20-=20=EB=B9=84=EB=B0=80=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EB=B3=80=EA=B2=BD=20=ED=9B=84=20Toast=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EB=A1=9C=EC=A7=81=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DSKit/Sources/Components/Toast.swift | 47 ++++++++++++++++++- .../VC/PasswordChangeVC.swift | 7 ++- .../Sources/SettingScene/VC/SettingVC.swift | 8 ---- 3 files changed, 48 insertions(+), 14 deletions(-) diff --git a/SOPT-Stamp-iOS/Projects/Modules/DSKit/Sources/Components/Toast.swift b/SOPT-Stamp-iOS/Projects/Modules/DSKit/Sources/Components/Toast.swift index edc7410c6..84e1823a1 100644 --- a/SOPT-Stamp-iOS/Projects/Modules/DSKit/Sources/Components/Toast.swift +++ b/SOPT-Stamp-iOS/Projects/Modules/DSKit/Sources/Components/Toast.swift @@ -5,7 +5,6 @@ // Copyright © 2022 SOPT-Stamp-iOS. All rights reserved. // - import UIKit import SnapKit @@ -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() @@ -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() + }) + }) + } } diff --git a/SOPT-Stamp-iOS/Projects/Presentation/Sources/SettingScene/PasswordSettingScene/VC/PasswordChangeVC.swift b/SOPT-Stamp-iOS/Projects/Presentation/Sources/SettingScene/PasswordSettingScene/VC/PasswordChangeVC.swift index 6f2d4e092..d4dd28748 100644 --- a/SOPT-Stamp-iOS/Projects/Presentation/Sources/SettingScene/PasswordSettingScene/VC/PasswordChangeVC.swift +++ b/SOPT-Stamp-iOS/Projects/Presentation/Sources/SettingScene/PasswordSettingScene/VC/PasswordChangeVC.swift @@ -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) @@ -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) } diff --git a/SOPT-Stamp-iOS/Projects/Presentation/Sources/SettingScene/VC/SettingVC.swift b/SOPT-Stamp-iOS/Projects/Presentation/Sources/SettingScene/VC/SettingVC.swift index fd5d06357..8f507cfd8 100644 --- a/SOPT-Stamp-iOS/Projects/Presentation/Sources/SettingScene/VC/SettingVC.swift +++ b/SOPT-Stamp-iOS/Projects/Presentation/Sources/SettingScene/VC/SettingVC.swift @@ -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) } }