Skip to content

Commit 58e3b37

Browse files
committed
[trello.com/c/sI4VXuJa] update snackbar
autoDismiss 4sec -> 3 sec
1 parent 7c6e504 commit 58e3b37

File tree

3 files changed

+66
-60
lines changed

3 files changed

+66
-60
lines changed

PopupKit/Sources/PopupKit/Implementation/Services/AutoDismissManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ private extension AutoDismissManager {
4949
}
5050
}
5151

52-
private let autoDismissTimeInterval: TimeInterval = 4
52+
private let autoDismissTimeInterval: TimeInterval = 3

PopupKit/Sources/PopupKit/Implementation/Views/NotificationPresenterView.swift

Lines changed: 64 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -13,95 +13,103 @@ struct NotificationPresenterView: View {
1313
case vertical
1414
case horizontal
1515
}
16-
17-
@State private var verticalDragTranslation: CGFloat = .zero
18-
@State private var horizontalDragTranslation: CGFloat = .zero
19-
@State private var minTranslationYForDismiss: CGFloat = .infinity
20-
@State private var minTranslationXForDismiss: CGFloat = .infinity
2116
@State private var isTextLimited: Bool = true
2217
@State private var dismissEdge: Edge = .top
23-
@State private var dragDirection: DragDirection?
18+
@State private var dragDirection: DragDirection?
19+
@State private var dynamicHeight: CGFloat = 0
20+
@State private var notificationHeight: CGFloat = 0
21+
@State private var offset: CGSize = .zero
2422

2523
let model: NotificationModel
2624
let safeAreaInsets: EdgeInsets
2725
let dismissAction: () -> Void
2826

2927
var body: some View {
30-
NotificationView(
31-
isTextLimited: $isTextLimited,
32-
model: model
33-
)
34-
.padding([.leading, .trailing], 10)
35-
.padding([.top, .bottom], 10)
28+
VStack {
29+
NotificationView(
30+
isTextLimited: $isTextLimited,
31+
model: model
32+
)
33+
.padding(10)
34+
.padding([.top, .bottom], 10)
35+
.background(
36+
GeometryReader { geometry in
37+
Color.clear
38+
.onAppear {
39+
notificationHeight = geometry.size.height
40+
print("onappier")
41+
}
42+
.onChange(of: geometry.size.height) { newValue in
43+
notificationHeight = newValue
44+
}
45+
}
46+
)
47+
}
48+
.frame(minHeight: notificationHeight + dynamicHeight)
3649
.overlay(
3750
RoundedRectangle(cornerRadius: 10)
3851
.stroke(Color.init(uiColor:.adamant.chatInputBarBorderColor), lineWidth: 1)
3952
)
4053
.background(GeometryReader(content: processGeometry))
41-
.expanded(axes: .horizontal)
42-
.offset(y: verticalDragTranslation < .zero ? verticalDragTranslation : .zero)
43-
.offset(x: horizontalDragTranslation < .zero ? horizontalDragTranslation : .zero)
44-
.gesture(dragGesture)
4554
.onTapGesture(perform: onTap)
55+
.gesture(dragGesture)
4656
.cornerRadius(10)
4757
.padding(.horizontal, 15)
4858
.padding(.top, safeAreaInsets.top)
59+
.offset(offset)
60+
.animation(.interactiveSpring(), value: offset)
4961
.transition(.move(edge: dismissEdge))
5062
}
5163
}
52-
64+
private extension NotificationPresenterView {
65+
func processGeometry(_ geometry: GeometryProxy) -> some View {
66+
return Color.init(uiColor: .adamant.swipeBlockColor)
67+
.cornerRadius(10)
68+
}
69+
func onTap() {
70+
model.tapHandler?.value()
71+
dismissAction()
72+
dismissEdge = .top
73+
}
74+
}
5375
private extension NotificationPresenterView {
5476
var dragGesture: some Gesture {
5577
DragGesture()
56-
.onChanged {
57-
if dragDirection == nil {
58-
dragDirection = abs($0.translation.height) > abs($0.translation.width) ? .vertical : .horizontal
78+
.onChanged { value in
79+
if dragDirection == nil || (abs(value.translation.width) <= 5 && abs(value.translation.height) <= 5) {
80+
detectDragDirection(value: value)
5981
}
60-
switch dragDirection {
61-
case .vertical:
62-
verticalDragTranslation = $0.translation.height
63-
case .horizontal:
64-
horizontalDragTranslation = $0.translation.width
65-
case .none:
66-
break
82+
if dragDirection == .vertical && isTextLimited {
83+
dynamicHeight = max(0, min(value.translation.height, 30))
84+
}
85+
if dragDirection == .vertical, value.translation.height < 0 {
86+
offset = CGSize(width: 0, height: value.translation.height)
87+
} else if dragDirection == .horizontal, value.translation.width < 0 {
88+
offset = CGSize(width: value.translation.width, height: 0)
6789
}
6890
}
69-
.onEnded {
70-
if $0.velocity.height < -100 || -$0.translation.height > minTranslationYForDismiss {
71-
dismissEdge = .top
72-
Task { dismissAction() }
73-
} else if $0.velocity.width < -100 || $0.translation.width > minTranslationXForDismiss {
74-
dismissEdge = .leading
75-
Task { dismissAction() }
76-
} else if $0.velocity.height > -100 || -$0.translation.height < minTranslationYForDismiss {
77-
withAnimation {
78-
horizontalDragTranslation = .zero
91+
.onEnded { value in
92+
if dragDirection == .vertical {
93+
if value.translation.height > 25 {
94+
model.cancelAutoDismiss?.value()
7995
isTextLimited = false
96+
} else if value.translation.height < -30 {
97+
Task { dismissAction() }
8098
}
81-
model.cancelAutoDismiss?.value()
82-
} else {
83-
withAnimation {
84-
verticalDragTranslation = .zero
85-
horizontalDragTranslation = .zero
99+
} else if dragDirection == .horizontal {
100+
if value.translation.width < -100 {
101+
dismissEdge = .leading
102+
Task { dismissAction() }
86103
}
87104
}
88105
dragDirection = nil
106+
dynamicHeight = 0
107+
offset = .zero
89108
}
90109
}
91110

92-
func processGeometry(_ geometry: GeometryProxy) -> some View {
93-
DispatchQueue.main.async {
94-
minTranslationYForDismiss = geometry.size.height / 2
95-
minTranslationXForDismiss = geometry.size.width / 2
96-
}
97-
98-
return Color.init(uiColor: .adamant.swipeBlockColor)
99-
.cornerRadius(10)
100-
}
101-
102-
func onTap() {
103-
model.tapHandler?.value()
104-
dismissAction()
105-
dismissEdge = .top
111+
func detectDragDirection(value: DragGesture.Value) {
112+
let horizontalDistance = abs(value.translation.width), verticalDistance = abs(value.translation.height)
113+
dragDirection = verticalDistance > horizontalDistance ? .vertical : .horizontal
106114
}
107115
}

PopupKit/Sources/PopupKit/Implementation/Views/NotificationView.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// NotificationView.swift
3-
//
3+
//
44
//
55
// Created by Andrey Golubenko on 06.12.2022.
66
//
@@ -21,7 +21,6 @@ struct NotificationView: View {
2121
textStack
2222
Spacer(minLength: .zero)
2323
}
24-
2524
Image(systemName: isTextLimited ? pullDownIcon : pullUpIcon)
2625
.font(.title)
2726
.foregroundColor(.gray)
@@ -50,7 +49,6 @@ private extension NotificationView {
5049
Text(description)
5150
.font(.system(size: 13))
5251
.lineLimit(isTextLimited ? 3 : nil)
53-
5452
}
5553
}
5654
}

0 commit comments

Comments
 (0)