Skip to content

Commit

Permalink
Merge pull request #26 from payan-app/snackbar
Browse files Browse the repository at this point in the history
feat: add on disappear handler
  • Loading branch information
juandahurt authored Jul 9, 2022
2 parents c0a2df9 + 56ad755 commit e8b40e6
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Sources/Purace/Views/Basic/Snackbar/PuraceSnackbarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,16 @@ struct PuraceSnackbarViewModifier: ViewModifier {
var buttonTitle: String?
var type: PuraceSnackbarType
var buttonOnTap: (() -> Void)?
var onDissappear: (() -> Void)?

func body(content: Content) -> some View {
ZStack {
content
if isVisibleAux {
PuraceSnackbarView(title: title, type: type, isVisible: $isVisible, buttonTitle: buttonTitle, buttonOnTap: buttonOnTap)
.onDisappear {
onDissappear?()
}
}
}.onChange(of: isVisible) { newValue in
if !newValue {
Expand All @@ -103,7 +107,7 @@ struct PuraceSnackbarViewModifier: ViewModifier {


public extension View {
func snackBar(title: String, isVisible: Binding<Bool>, type: PuraceSnackbarType = .info, buttonTitle: String? = nil, buttonOnTap: (() -> Void)? = nil) -> some View {
modifier(PuraceSnackbarViewModifier(isVisible: isVisible, title: title, buttonTitle: buttonTitle, type: type, buttonOnTap: buttonOnTap))
func snackBar(title: String, isVisible: Binding<Bool>, type: PuraceSnackbarType = .info, buttonTitle: String? = nil, buttonOnTap: (() -> Void)? = nil, onDissappear: (() -> Void)? = nil) -> some View {
modifier(PuraceSnackbarViewModifier(isVisible: isVisible, title: title, buttonTitle: buttonTitle, type: type, buttonOnTap: buttonOnTap, onDissappear: onDissappear))
}
}

0 comments on commit e8b40e6

Please sign in to comment.