Skip to content

Commit 5679861

Browse files
committed
Use uikit dismiss closure to prevent interference
1 parent 78c52e6 commit 5679861

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,17 @@ struct NoticeModifier: ViewModifier {
2828

2929
// NoticeView wrapper
3030
NoticeAlert(notice: notice, width: geometry.size.width)
31-
.fixedSize(horizontal: false, vertical: true)
31+
.onDismiss {
32+
$notice.wrappedValue = nil
33+
}
3234
.onAppear {
3335
// TODO: Move this to a proper state management class
3436
DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
35-
$notice.wrappedValue = nil
37+
//$notice.wrappedValue = nil
3638
}
3739
}
38-
.onTapGesture {
39-
$notice.wrappedValue = nil // TODO: Test the retry button interference
40-
}
40+
41+
.fixedSize(horizontal: false, vertical: true)
4142
}
4243
}
4344
}
@@ -58,8 +59,14 @@ private struct NoticeAlert: UIViewRepresentable {
5859
///
5960
let width: CGFloat
6061

62+
/// Action to be invoked when the view is tapped.
63+
///
64+
var onDismiss: (() -> Void)?
65+
6166
func makeUIView(context: Context) -> NoticeWrapper {
6267
let noticeView = NoticeView(notice: notice)
68+
noticeView.dismissHandler = onDismiss
69+
6370
let wrapperView = NoticeWrapper(noticeView: noticeView)
6471
wrapperView.translatesAutoresizingMaskIntoConstraints = false
6572
return wrapperView
@@ -68,6 +75,14 @@ private struct NoticeAlert: UIViewRepresentable {
6875
func updateUIView(_ uiView: NoticeWrapper, context: Context) {
6976
uiView.width = width
7077
}
78+
79+
/// Updates the notice dismiss closure.
80+
///
81+
func onDismiss(_ onDismiss: @escaping (() -> Void)) -> Self {
82+
var copy = self
83+
copy.onDismiss = onDismiss
84+
return copy
85+
}
7186
}
7287

7388

0 commit comments

Comments
 (0)