You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.1 KiB
45 lines
1.1 KiB
//
|
|
// NetworkStatusView.swift
|
|
// PadelClub
|
|
//
|
|
// Created by Laurent Morvillier on 25/10/2024.
|
|
//
|
|
|
|
import SwiftUI
|
|
import LeStorage
|
|
|
|
struct NetworkStatusView: View {
|
|
|
|
@State private var isConnected = false
|
|
@State private var timer: Timer?
|
|
|
|
var body: some View {
|
|
Image(systemName: self.isConnected ? "network" : "network.slash")
|
|
.resizable()
|
|
.scaledToFit()
|
|
|
|
.onAppear {
|
|
self._defineStatus()
|
|
// Start the timer when the view appears
|
|
timer = Timer.scheduledTimer(withTimeInterval: 2.0, repeats: true) { _ in
|
|
withAnimation {
|
|
self._defineStatus()
|
|
}
|
|
}
|
|
}
|
|
.onDisappear {
|
|
// Clean up timer when view disappears
|
|
timer?.invalidate()
|
|
timer = nil
|
|
}
|
|
}
|
|
|
|
fileprivate func _defineStatus() {
|
|
self.isConnected = LeStorage.NetworkMonitor.shared.isConnected
|
|
}
|
|
|
|
}
|
|
|
|
#Preview {
|
|
NetworkStatusView()
|
|
}
|
|
|