Skip to content

Commit

Permalink
add onTap (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
muukii authored Jun 19, 2024
1 parent a9813c1 commit 1d0717b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ struct FloatingDisplayKitContentView: View {
context: .init(
position: .top,
transition: .slideIn,
onTap: {
print("tap")
},
content: {
ZStack {
HStack {
Expand Down
7 changes: 5 additions & 2 deletions Sources/FluidSnackbar/FloatingDisplayContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ extension FloatingDisplayContext {
public convenience init<Content: View>(
position: FloatingDisplayController.DisplayPosition,
transition: FloatingDisplayTransitionType,
onTap: @escaping @MainActor () -> Void,
@ViewBuilder content: @escaping () -> Content
) {

self.init(
viewBuilder: {
_HostingWrapperView(hostingView: SwiftUIHostingView(content: content))
_HostingWrapperView(hostingView: SwiftUIHostingView(content: content), onTap: onTap)
},
position: position,
transition: transition
Expand All @@ -58,7 +59,7 @@ private final class _HostingWrapperView: SnackbarDraggableBase {

private let hostingView: SwiftUIHostingView

init(hostingView: SwiftUIHostingView) {
init(hostingView: SwiftUIHostingView, onTap: @escaping @MainActor () -> Void) {
self.hostingView = hostingView
super.init(topMargin: .zero)
contentView.addSubview(hostingView)
Expand All @@ -69,6 +70,8 @@ private final class _HostingWrapperView: SnackbarDraggableBase {
hostingView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
hostingView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor)
])

self.onTap = onTap
}

}

0 comments on commit 1d0717b

Please sign in to comment.