2024-08-14 03:10:12 -07:00
|
|
|
//
|
|
|
|
|
// View.swift
|
|
|
|
|
// Meshtastic
|
|
|
|
|
//
|
|
|
|
|
// Copyright(c) Garth Vander Houwen 8/14/24.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
|
|
public extension View {
|
2024-09-04 10:06:34 -07:00
|
|
|
func onFirstAppear(_ action: @escaping () -> Void) -> some View {
|
2024-08-14 03:10:12 -07:00
|
|
|
modifier(FirstAppear(action: action))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private struct FirstAppear: ViewModifier {
|
2024-09-04 10:06:34 -07:00
|
|
|
let action: () -> Void
|
2024-08-14 03:10:12 -07:00
|
|
|
|
|
|
|
|
// Use this to only fire your block one time
|
|
|
|
|
@State private var hasAppeared = false
|
|
|
|
|
|
|
|
|
|
func body(content: Content) -> some View {
|
|
|
|
|
// And then, track it here
|
|
|
|
|
content.onAppear {
|
|
|
|
|
guard !hasAppeared else { return }
|
|
|
|
|
hasAppeared = true
|
|
|
|
|
action()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|