Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[trello.com/c/sI4VXuJa] Added swipe gestures (left & down) to Snackbar #595

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,22 @@ import UIKit
import CommonKit

struct NotificationModel: Equatable, Hashable {
static func == (lhs: NotificationModel, rhs: NotificationModel) -> Bool {
return lhs.icon == rhs.icon
&& lhs.title == rhs.title
&& lhs.description == rhs.description
}

func hash(into hasher: inout Hasher) {
hasher.combine(icon)
hasher.combine(title)
hasher.combine(description)
hasher.combine(tapHandler)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove


let icon: UIImage?
let title: String?
let description: String?
let tapHandler: IDWrapper<() -> Void>?
let cancelAutoDismiss: () -> Void
IanaaDvlp marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ import CommonKit

struct NotificationView: View {
@State private var dragTranslation: CGFloat = .zero
@State private var horizontalDragTranslation: CGFloat = .zero
@State private var minTranslationForDismiss: CGFloat = .infinity
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Y


@State private var minTranslationXForDismiss: CGFloat = .infinity
@State private var isTextLimited: Bool = true

let model: NotificationModel
let safeAreaInsets: EdgeInsets
let dismissAction: () -> Void
Expand All @@ -27,9 +30,11 @@ struct NotificationView: View {
.padding([.leading, .trailing], 15)
.padding([.top, .bottom], 10)
.background(GeometryReader(content: processGeometry))
.expanded(axes: .horizontal)
.offset(y: dragTranslation < .zero ? dragTranslation : .zero)
.offset(x: horizontalDragTranslation < .zero ? horizontalDragTranslation : .zero)
.gesture(dragGesture)
.onTapGesture(perform: onTap)
.background(Color(.adamant.swipeBlockColor))
.cornerRadius(10)
.padding(.horizontal, 15)
.padding(.top, safeAreaInsets.top)
Expand All @@ -48,38 +53,52 @@ private extension NotificationView {
}

var textStack: some View {
VStack(alignment: .leading, spacing: .zero) {
VStack(alignment: .leading, spacing: 3) {
if let title = model.title {
Text(title)
.font(.system(size: 15, weight: .bold))
}
if let description = model.description {
Text(description)
.font(.system(size: 13))
.lineLimit(3)
.lineLimit(isTextLimited ? 3 : nil)

}
}
}

var dragGesture: some Gesture {
DragGesture()
.onChanged { dragTranslation = $0.translation.height }
.onChanged {
dragTranslation = $0.translation.height
horizontalDragTranslation = $0.translation.width
}
.onEnded {
print(-$0.translation.height, minTranslationForDismiss)
if $0.velocity.height < -100 || -$0.translation.height > minTranslationForDismiss {
dismissAction()
} else if $0.velocity.width < -100 || $0.translation.width > minTranslationXForDismiss {
dismissAction()
} else if $0.velocity.height > -100 || -$0.translation.height < minTranslationForDismiss {
horizontalDragTranslation = .zero
Copy link
Member

@just-software-dev just-software-dev Nov 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove? Animation?

isTextLimited = false
model.cancelAutoDismiss()
} else {
withAnimation { dragTranslation = .zero }
withAnimation {
dragTranslation = .zero
horizontalDragTranslation = .zero
}
}
}
}

func processGeometry(_ geometry: GeometryProxy) -> some View {
DispatchQueue.main.async {
minTranslationForDismiss = geometry.size.height / 2
minTranslationXForDismiss = geometry.size.width / 2
}

return Color.clear
return Color.init(uiColor: .adamant.swipeBlockColor)
.cornerRadius(10)
}

func onTap() {
Expand Down
5 changes: 4 additions & 1 deletion PopupKit/Sources/PopupKit/PopupManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ public extension PopupManager {
icon: icon,
title: title,
description: description,
tapHandler: tapHandler.map { .init(id: .empty, value: $0) }
tapHandler: tapHandler.map { .init(id: .empty, value: $0) },
cancelAutoDismiss: { [weak self] in
self?.autoDismissManager.notificationDismissSubscription?.cancel()
}
)

if autoDismiss {
Expand Down