File tree Expand file tree Collapse file tree 1 file changed +13
-5
lines changed
WooCommerce/Classes/View Modifiers Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change 11import SwiftUI
22import UIKit
3+ import Hardware
34
45/// View Modifier that shows a notice in front of a view.
56/// NOTE: This currently does not support enqueuing multiple notices like `DefaultNoticePresenter` does.
@@ -10,6 +11,14 @@ struct NoticeModifier: ViewModifier {
1011 ///
1112 @Binding var notice : Notice ?
1213
14+ /// Cancelable task that clears a notice.
15+ ///
16+ @State var clearNoticeTask = DispatchWorkItem ( block: { } )
17+
18+ /// Time the notice will remain on screen.
19+ ///
20+ private let onScreenNoticeTime = 5.0
21+
1322 func body( content: Content ) -> some View {
1423 content
1524 . overlay ( buildNoticeStack ( ) )
@@ -30,13 +39,12 @@ struct NoticeModifier: ViewModifier {
3039 // NoticeView wrapper
3140 NoticeAlert ( notice: notice, width: geometry. size. width)
3241 . onDismiss {
33- $notice. wrappedValue = nil
42+ clearNoticeTask. perform ( )
43+ clearNoticeTask. cancel ( )
3444 }
3545 . onAppear {
36- // TODO: Move this to a proper state management class
37- DispatchQueue . main. asyncAfter ( deadline: . now( ) + 5 ) {
38- //$notice.wrappedValue = nil
39- }
46+ clearNoticeTask = . init { $notice. wrappedValue = nil }
47+ DispatchQueue . main. asyncAfter ( deadline: . now( ) + onScreenNoticeTime, execute: clearNoticeTask)
4048 }
4149
4250 . fixedSize ( horizontal: false , vertical: true )
You can’t perform that action at this time.
0 commit comments