@@ -15,17 +15,36 @@ public struct PokitLinkPopup: View {
1515 @State
1616 private var second : Int = 0
1717 private let action : ( ( ) -> Void ) ?
18+ private let until : Int
1819 private let timer = Timer . publish (
1920 every: 1 ,
2021 on: . main,
2122 in: . common
2223 ) . autoconnect ( )
2324
24- public init (
25+ public init ( type: Binding < PokitLinkPopup . PopupType ? > ) {
26+ self . _type = type
27+ switch type. wrappedValue {
28+ case let . link( _, _, until) ,
29+ let . text( _, until) ,
30+ let . success( _, until) ,
31+ let . error( _, until) ,
32+ let . warning( _, until) ,
33+ let . report( _, until) :
34+ self . until = until
35+ default :
36+ self . until = 2
37+ }
38+ self . action = nil
39+ }
40+
41+ private init (
2542 type: Binding < PokitLinkPopup . PopupType ? > ,
26- action: ( ( ) -> Void ) ? = nil
43+ until: Int ,
44+ action: ( ( ) -> Void ) ?
2745 ) {
2846 self . _type = type
47+ self . until = until
2948 self . action = action
3049 }
3150
@@ -40,7 +59,7 @@ public struct PokitLinkPopup: View {
4059 . frame ( width: 335 , height: 60 )
4160 . transition ( . move( edge: . bottom) . combined ( with: . opacity) )
4261 . onReceive ( timer) { _ in
43- guard second < 2 else {
62+ guard second < until else {
4463 closedPopup ( )
4564 return
4665 }
@@ -61,7 +80,7 @@ public struct PokitLinkPopup: View {
6180 . multilineTextAlignment ( . leading)
6281 . foregroundStyle ( textColor)
6382
64- if case let . link( _, url) = type {
83+ if case let . link( _, url, _ ) = type {
6584 Text ( url)
6685 . lineLimit ( 1 )
6786 . pokitFont ( . detail2)
@@ -167,26 +186,34 @@ public struct PokitLinkPopup: View {
167186
168187 private var title : String {
169188 switch type {
170- case let . link( title, _) ,
171- let . text( title) ,
172- let . success( title) ,
173- let . error( title) ,
174- let . warning( title) ,
175- let . report( title) :
189+ case let . link( title, _, _ ) ,
190+ let . text( title, _ ) ,
191+ let . success( title, _ ) ,
192+ let . error( title, _ ) ,
193+ let . warning( title, _ ) ,
194+ let . report( title, _ ) :
176195 return title
177196 default : return " "
178197 }
179198 }
199+
200+ public func onAction( _ action: @escaping ( ) -> Void ) -> Self {
201+ PokitLinkPopup (
202+ type: self . $type,
203+ until: self . until,
204+ action: action
205+ )
206+ }
180207}
181208
182209public extension PokitLinkPopup {
183210 enum PopupType : Equatable {
184- case link( title: String , url: String )
185- case text( title: String )
186- case success( title: String )
187- case error( title: String )
188- case warning( title: String )
189- case report( title: String )
211+ case link( title: String , url: String , until : Int = 2 )
212+ case text( title: String , until : Int = 2 )
213+ case success( title: String , until : Int = 2 )
214+ case error( title: String , until : Int = 2 )
215+ case warning( title: String , until : Int = 2 )
216+ case report( title: String , until : Int = 2 )
190217 }
191218}
192219
0 commit comments