Skip to content

Commit

Permalink
feat: add snackbar duration
Browse files Browse the repository at this point in the history
  • Loading branch information
juandahurt committed Dec 15, 2022
1 parent d7efbf4 commit 06e03a9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Foundation
public struct PuraceSnackbarContent {
var title: String = ""
var type: PuraceSnackbarType = .info
var duration: PuraceSnakbarDuration = .low
var action: (() -> Void)?
var actionTitle: String?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// PuraceSnakbarDuration.swift
//
//
// Created by Juan Hurtado on 15/12/22.
//

import Foundation

public enum PuraceSnakbarDuration: Int {
case low = 2
case medium = 4
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public class PuraceSnackbarBuilder {
return self
}

public func whithDuraction(_ duration: PuraceSnakbarDuration) -> PuraceSnackbarBuilder {
content.duration = duration
return self
}

public func withAction(title: String?, handler: @escaping () -> Void) -> PuraceSnackbarBuilder {
content.actionTitle = title
content.action = handler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class PuraceSnackbarManager {
guard let self else { return }
self.snackbar?.transform = .init(translationX: 0, y: -PuraceSnackbar.height - PuraceSnackbar.padding)
}) { _ in
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in
DispatchQueue.main.asyncAfter(deadline: .now().advanced(by: .seconds(content.duration.rawValue))) { [weak self] in
guard let self else { return }
if self.isPresented {
self.hide()
Expand Down

0 comments on commit 06e03a9

Please sign in to comment.