mirror of
https://github.com/NinjaCheetah/RIT-Dining.git
synced 2026-03-05 05:25:29 -05:00
- Widgets will now open the appropriate DetailView in the app when you tap on them. - ...except when they don't. This is still a little buggy. It works correctly when the app is already alive in the background but only works about 75% of the time when the app isn't running yet. - Unified the loading view into a shared view used in all places requiring loading
65 lines
1.7 KiB
Swift
65 lines
1.7 KiB
Swift
//
|
|
// LoadingView.swift
|
|
// TigerDine
|
|
//
|
|
// Created by Campbell on 1/24/26.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
enum LoadingType {
|
|
case normal
|
|
case truck
|
|
}
|
|
|
|
struct LoadingView: View {
|
|
@Binding var loadFailed: Bool
|
|
@State var loadingType: LoadingType = .normal
|
|
|
|
@State private var rotationDegrees: Double = 0
|
|
|
|
private var animation: Animation {
|
|
.linear
|
|
.speed(0.1)
|
|
.repeatForever(autoreverses: false)
|
|
}
|
|
|
|
private var loadingSymbol: String {
|
|
switch loadingType {
|
|
case .normal:
|
|
return "fork.knife.circle"
|
|
case .truck:
|
|
return "truck.box"
|
|
}
|
|
}
|
|
|
|
var body: some View {
|
|
VStack {
|
|
if loadFailed {
|
|
Image(systemName: "wifi.exclamationmark.circle")
|
|
.resizable()
|
|
.frame(width: 75, height: 75)
|
|
.foregroundStyle(.accent)
|
|
Text("An error occurred while loading data. Please check your network connection and try again.")
|
|
.foregroundStyle(.secondary)
|
|
.multilineTextAlignment(.center)
|
|
} else {
|
|
Image(systemName: loadingSymbol)
|
|
.resizable()
|
|
.scaledToFit()
|
|
.frame(width: 75, height: 75)
|
|
.foregroundStyle(.accent)
|
|
.rotationEffect(.degrees(rotationDegrees))
|
|
.onAppear {
|
|
withAnimation(animation) {
|
|
rotationDegrees = 360.0
|
|
}
|
|
}
|
|
Text("Loading...")
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
}
|
|
.padding()
|
|
}
|
|
}
|