Skip to content

Commit 78c52e6

Browse files
committed
Add Animation when presenting and dismissing notice
1 parent 7f49582 commit 78c52e6

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

WooCommerce/Classes/View Modifiers/View+NoticesModifier.swift

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,36 @@ struct NoticeModifier: ViewModifier {
1010
@Binding var notice: Notice?
1111

1212
func body(content: Content) -> some View {
13+
content
14+
.overlay(buildNoticeStack())
15+
.animation(.easeInOut, value: notice)
16+
}
17+
18+
/// Builds a notice view at the bottom of the screen.
19+
///
20+
@ViewBuilder private func buildNoticeStack() -> some View {
1321
if let notice = notice {
14-
content.overlay(
15-
// Geometry reader to provide the correct view width.
16-
GeometryReader { geometry in
17-
// VStack with spacer to push content to the bottom
18-
VStack {
19-
Spacer()
20-
21-
// NoticeView wrapper
22-
NoticeAlert(notice: notice, width: geometry.size.width)
23-
.fixedSize(horizontal: false, vertical: true)
24-
.onAppear {
25-
// TODO: Move this to a proper state management class
26-
DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
27-
$notice.wrappedValue = nil
28-
}
22+
// Geometry reader to provide the correct view width.
23+
GeometryReader { geometry in
24+
25+
// VStack with spacer to push content to the bottom
26+
VStack {
27+
Spacer()
28+
29+
// NoticeView wrapper
30+
NoticeAlert(notice: notice, width: geometry.size.width)
31+
.fixedSize(horizontal: false, vertical: true)
32+
.onAppear {
33+
// TODO: Move this to a proper state management class
34+
DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
35+
$notice.wrappedValue = nil
2936
}
30-
.onTapGesture {
31-
$notice.wrappedValue = nil // TODO: Test the retry button interference
32-
}
33-
}
37+
}
38+
.onTapGesture {
39+
$notice.wrappedValue = nil // TODO: Test the retry button interference
40+
}
3441
}
35-
)
36-
} else {
37-
content
42+
}
3843
}
3944
}
4045
}
@@ -129,7 +134,7 @@ extension View {
129134
/// Shows the provided notice in front of the view.
130135
///
131136
func notice(_ notice: Binding<Notice?>) -> some View {
132-
self.modifier(NoticeModifier(notice: notice))
137+
modifier(NoticeModifier(notice: notice))
133138
}
134139
}
135140

0 commit comments

Comments
 (0)