forked from sopt-makers/SOPT-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
205 additions
and
0 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
SOPT-iOS/Projects/Modules/DSKit/Resources/Assets.xcassets/MDS/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
SOPT-iOS/Projects/Modules/DSKit/Resources/Assets.xcassets/MDS/ToastIcon/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
.../Modules/DSKit/Resources/Assets.xcassets/MDS/ToastIcon/toast-alert.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "alert.png", | ||
"idiom" : "universal", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"filename" : "alert@2x.png", | ||
"idiom" : "universal", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"filename" : "alert@3x.png", | ||
"idiom" : "universal", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Binary file added
BIN
+502 Bytes
...es/DSKit/Resources/Assets.xcassets/MDS/ToastIcon/toast-alert.imageset/alert.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+908 Bytes
...DSKit/Resources/Assets.xcassets/MDS/ToastIcon/toast-alert.imageset/alert@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.18 KB
...DSKit/Resources/Assets.xcassets/MDS/ToastIcon/toast-alert.imageset/alert@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
SOPT-iOS/Projects/Modules/DSKit/Sources/MDS/MDSToast.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
// | ||
// MDSToast.swift | ||
// DSKit | ||
// | ||
// Created by sejin on 12/25/23. | ||
// Copyright © 2023 SOPT-iOS. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import Combine | ||
|
||
import Core | ||
|
||
public class MDSToast: UIView { | ||
|
||
// MARK: - Properties | ||
|
||
private let type: ToastType | ||
private let text: String | ||
private var linkButtonAction: (() -> Void)? | ||
private let cancelBag = CancelBag() | ||
|
||
// MARK: - UI Components | ||
|
||
private let toastIconImageView = UIImageView() | ||
|
||
private let contentLabel: UILabel = { | ||
let label = UILabel() | ||
label.font = UIFont.MDS.label3 | ||
label.textColor = DSKitAsset.Colors.gray900.color | ||
label.numberOfLines = 2 | ||
label.textAlignment = .left | ||
return label | ||
}() | ||
|
||
private let linkButton: UIButton = { | ||
var config = UIButton.Configuration.plain() | ||
config.baseBackgroundColor = .clear | ||
let attributes = AttributeContainer([.font: UIFont.MDS.label3, | ||
.foregroundColor: DSKitAsset.Colors.success]) | ||
|
||
var title = AttributedString.init("보러가기", attributes: attributes) | ||
|
||
config.attributedTitle = title | ||
config.contentInsets = .zero | ||
return UIButton(configuration: config) | ||
}() | ||
|
||
private let containerStackView: UIStackView = { | ||
let stackView = UIStackView() | ||
stackView.axis = .horizontal | ||
stackView.spacing = 8 | ||
stackView.alignment = .center | ||
return stackView | ||
}() | ||
|
||
// MARK: - initialization | ||
|
||
init(type: ToastType, text: String, linkButtonAction: (() -> Void)? = nil) { | ||
self.type = type | ||
self.text = text | ||
self.linkButtonAction = linkButtonAction | ||
super.init(frame: .zero) | ||
self.setUI() | ||
self.setLayout() | ||
self.setLinkButtonAction() | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
// MARK: - UI & Layout | ||
|
||
private func setUI() { | ||
self.toastIconImageView.image = self.type.icon | ||
self.contentLabel.text = self.text | ||
self.backgroundColor = DSKitAsset.Colors.gray10.color | ||
self.clipsToBounds = true | ||
self.layer.cornerRadius = 18 | ||
self.fillStackView() | ||
} | ||
|
||
private func fillStackView() { | ||
switch type { | ||
case .default: | ||
containerStackView.addArrangedSubviews(contentLabel) | ||
case .actionButton: | ||
containerStackView.addArrangedSubviews(toastIconImageView, contentLabel, linkButton) | ||
default: | ||
containerStackView.addArrangedSubviews(toastIconImageView, contentLabel) | ||
} | ||
} | ||
|
||
private func setLayout() { | ||
addSubview(containerStackView) | ||
|
||
toastIconImageView.snp.makeConstraints { make in | ||
make.width.height.equalTo(20) | ||
} | ||
|
||
linkButton.snp.contentHuggingHorizontalPriority = 999 | ||
|
||
containerStackView.snp.makeConstraints { make in | ||
make.center.equalToSuperview() | ||
make.leading.trailing.equalToSuperview().inset(16) | ||
make.top.bottom.equalToSuperview().inset(14) | ||
} | ||
} | ||
|
||
private func setLinkButtonAction() { | ||
self.linkButton | ||
.publisher(for: .touchUpInside) | ||
.sink { [weak self] _ in | ||
self?.linkButtonAction?() | ||
}.store(in: cancelBag) | ||
} | ||
} | ||
|
||
public extension MDSToast { | ||
enum ToastType { | ||
case `default` | ||
case success | ||
case alert | ||
case error | ||
case actionButton | ||
|
||
var icon: UIImage { | ||
switch self { | ||
case .alert: | ||
return DSKitAsset.Assets.toastAlert.image | ||
default: // TODO: MDS 피그마 export 권한 생기면 추가 예정 | ||
return DSKitAsset.Assets.toastAlert.image | ||
} | ||
} | ||
} | ||
} |