Skip to content

Commit

Permalink
[Add] sopt-makers#336 - Toast 아이콘 에셋 추가 및 button 이름 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
lsj8706 committed Dec 26, 2023
1 parent 25b34e6 commit 67c1066
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "error.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "error@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "error@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "success.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "success@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "success@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions SOPT-iOS/Projects/Modules/DSKit/Sources/Components/Toast.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@

import UIKit

import SnapKit
import Core

public extension UIViewController {
@available(*, deprecated, message: "Use MDS toast")
func showToast(message: String) {
Toast.show(message: message, view: self.view, safeAreaBottomInset: self.safeAreaBottomInset())
}

func showMDSToast(type: MDSToast.ToastType, text: String, linkButtonAction: (() -> Void)? = nil) {
Toast.showMDSToast(type: type, text: text, linkButtonAction: linkButtonAction)
func showMDSToast(type: MDSToast.ToastType, text: String, actionButtonAction: (() -> Void)? = nil) {
Toast.showMDSToast(type: type, text: text, actionButtonAction: actionButtonAction)
}
}

Expand Down Expand Up @@ -69,8 +69,8 @@ public class Toast {
})
}

public static func showMDSToast(type: MDSToast.ToastType, text: String, linkButtonAction: (() -> Void)? = nil) {
let toast = MDSToast(type: type, text: text, linkButtonAction: linkButtonAction)
public static func showMDSToast(type: MDSToast.ToastType, text: String, actionButtonAction: (() -> Void)? = nil) {
let toast = MDSToast(type: type, text: text, actionButtonAction: actionButtonAction)

guard let scene = UIApplication.shared.connectedScenes.first(where: { $0.activationState == .foregroundActive }) as? UIWindowScene else { return }
guard let window = scene.windows.first(where: { $0.isKeyWindow }) else { return }
Expand Down
30 changes: 17 additions & 13 deletions SOPT-iOS/Projects/Modules/DSKit/Sources/MDS/MDSToast.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class MDSToast: UIView {

private let type: ToastType
private let text: String
private var linkButtonAction: (() -> Void)?
private var actionButtonAction: (() -> Void)?
private let cancelBag = CancelBag()

// MARK: - UI Components
Expand All @@ -33,7 +33,7 @@ public class MDSToast: UIView {
return label
}()

private let linkButton: UIButton = {
private let actionButton: UIButton = {
var config = UIButton.Configuration.plain()
config.baseBackgroundColor = .clear
let attributes = AttributeContainer([.font: UIFont.MDS.label3,
Expand All @@ -56,14 +56,14 @@ public class MDSToast: UIView {

// MARK: - initialization

public init(type: ToastType, text: String, linkButtonAction: (() -> Void)? = nil) {
public init(type: ToastType, text: String, actionButtonAction: (() -> Void)? = nil) {
self.type = type
self.text = text
self.linkButtonAction = linkButtonAction
self.actionButtonAction = actionButtonAction
super.init(frame: .zero)
self.setUI()
self.setLayout()
self.setLinkButtonAction()
self.setActionButtonAction()
}

required init?(coder: NSCoder) {
Expand All @@ -86,7 +86,7 @@ public class MDSToast: UIView {
case .default:
containerStackView.addArrangedSubviews(contentLabel)
case .actionButton:
containerStackView.addArrangedSubviews(toastIconImageView, contentLabel, linkButton)
containerStackView.addArrangedSubviews(toastIconImageView, contentLabel, actionButton)
default:
containerStackView.addArrangedSubviews(toastIconImageView, contentLabel)
}
Expand All @@ -99,7 +99,7 @@ public class MDSToast: UIView {
make.width.height.equalTo(20)
}

linkButton.snp.contentHuggingHorizontalPriority = 999
actionButton.snp.contentHuggingHorizontalPriority = 999

containerStackView.snp.makeConstraints { make in
make.center.equalToSuperview()
Expand All @@ -108,11 +108,11 @@ public class MDSToast: UIView {
}
}

private func setLinkButtonAction() {
self.linkButton
private func setActionButtonAction() {
self.actionButton
.publisher(for: .touchUpInside)
.sink { [weak self] _ in
self?.linkButtonAction?()
self?.actionButtonAction?()
}.store(in: cancelBag)
}
}
Expand All @@ -125,12 +125,16 @@ public extension MDSToast {
case error
case actionButton

var icon: UIImage {
var icon: UIImage? {
switch self {
case .success, .actionButton:
return DSKitAsset.Assets.toastSuccess.image
case .alert:
return DSKitAsset.Assets.toastAlert.image
default: // TODO: MDS 피그마 export 권한 생기면 추가 예정
return DSKitAsset.Assets.toastAlert.image
case .error:
return DSKitAsset.Assets.toastError.image
default:
return nil
}
}
}
Expand Down

0 comments on commit 67c1066

Please sign in to comment.