Skip to content

Commit

Permalink
Feat: 딜레이 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
ITlearning committed Feb 1, 2024
1 parent 98dce0e commit d9c0cd7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ A library that makes Toast Alert globally available.
- Font customization: You can set the font weight.
- Set Bottom Padding: You can set the Bottom Padding.
- Bottom Padding is a padding value calculated based on the bottom of the phone view.
- Add a delay: You can set a delay between when the Toast Alert is shown.

# Requirements
- iOS 13.0 or later
Expand All @@ -33,6 +34,9 @@ toast.show(title: "Toast Information", subTitle: "Subtitle Information")
// custom BackgroundColor and Text Weight , padding
toast.show(title: "Toast Information", subTitle: "Subtitle Information", type: .black(fontWeight: .bold, bottomPadding: 70))

// add Delay
toast.show(title: "Toast Information", subTitle: "Subtitle Information", type: .black(fontWeight: .bold, bottomPadding: 70), delay: 0.2)

```

# Contribution
Expand Down
24 changes: 14 additions & 10 deletions Sources/SCToastAlert/SCToastAlert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import UIKit
public struct SCToastAlert {
private var toastAlert = SCToastAlertUIView()

public mutating func show(title: String, subTitle: String? = nil, type: ConfigType = .black()) {
public mutating func show(title: String, subTitle: String? = nil, type: ConfigType = .black(), delay: CGFloat = 0.0) {
toastAlert.show(title: title, subTitle: subTitle, type: type)
}

Expand All @@ -30,7 +30,9 @@ struct SCToastAlertUIView: UIViewRepresentable {

public mutating func show(title: String,
subTitle: String? = nil,
type: ConfigType = .black()) {
type: ConfigType = .black(),
delay: CGFloat = 0.0
) {

self.view = UIHostingController(rootView: SCToastView(title: title, subTitle: subTitle, type: type))
self.view.view.alpha = 0.0
Expand All @@ -53,15 +55,17 @@ struct SCToastAlertUIView: UIViewRepresentable {

}

private func presentAnimate(dismiss: Bool = true) {
UIView.animate(withDuration: 0.5, animations: {
self.view.view.alpha = 1.0
})

if dismiss {
DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: {
self.hide()
private func presentAnimate(dismiss: Bool = true, delay: CGFloat = 0.0) {
DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
UIView.animate(withDuration: 0.5, animations: {
self.view.view.alpha = 1.0
})

if dismiss {
DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: {
self.hide()
})
}
}
}

Expand Down

0 comments on commit d9c0cd7

Please sign in to comment.