fmodf
b3b3b3aef7
Reviewed-on: narayana/conversations-classic-ios#1 Co-authored-by: fmodf <fmodf.ios@gmail.com> Co-committed-by: fmodf <fmodf.ios@gmail.com>
28 lines
566 B
Swift
28 lines
566 B
Swift
import SwiftUI
|
|
|
|
// MARK: - On load
|
|
extension View {
|
|
func onLoad(_ action: @escaping () -> Void) -> some View {
|
|
modifier(ViewDidLoadModifier(action))
|
|
}
|
|
}
|
|
|
|
private struct ViewDidLoadModifier: ViewModifier {
|
|
private let action: () -> Void
|
|
|
|
@State private var didLoad = false
|
|
|
|
init(_ action: @escaping () -> Void) {
|
|
self.action = action
|
|
}
|
|
|
|
func body(content: Content) -> some View {
|
|
content.onAppear {
|
|
if !didLoad {
|
|
didLoad.toggle()
|
|
action()
|
|
}
|
|
}
|
|
}
|
|
}
|