mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
* Initial plan * Add Background Activity onboarding step, firmware version screens, and security nag Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/449fe2d6-dec9-4509-920e-e6196ca11d65 Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> * Address code review feedback: use @ObservedObject for LocationsHandler, fix firmware label Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/449fe2d6-dec9-4509-920e-e6196ca11d65 Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> * Improve readability of firmware version checks in Connect.swift Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/449fe2d6-dec9-4509-920e-e6196ca11d65 Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> * Add Siri onboarding step; fix @State→let in version sheets; fix .denied location flow Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/654a5abf-8005-4995-974a-5f1f95dfa68a Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> * Update protobufs package * Additional onboarding cleanup * Catalyst fixes --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> Co-authored-by: Garth Vander Houwen <garthvh@yahoo.com>
97 lines
2.2 KiB
Swift
97 lines
2.2 KiB
Swift
//
|
|
// View.swift
|
|
// Meshtastic
|
|
//
|
|
// Copyright(c) Garth Vander Houwen 8/14/24.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
extension View {
|
|
func onFirstAppear(_ action: @escaping () -> Void) -> some View {
|
|
modifier(FirstAppear(action: action))
|
|
}
|
|
|
|
@ViewBuilder func olderThanOS26( _ contentBuilder: (@escaping (Self) -> some View) ) -> some View {
|
|
if #available(iOS 26.0, macOS 26.0, *) {
|
|
self
|
|
} else {
|
|
contentBuilder(self)
|
|
}
|
|
}
|
|
/// Conditionally applies `defaultScrollAnchor` only on iOS 18+.
|
|
@ViewBuilder
|
|
func defaultScrollAnchorTopAlignment() -> some View {
|
|
if #available(iOS 18, macOS 15, *) {
|
|
AnyView(self.defaultScrollAnchor(.top, for: .alignment))
|
|
} else {
|
|
AnyView(self)
|
|
}
|
|
}
|
|
|
|
/// Conditionally applies `defaultScrollAnchor` only on iOS 18+.
|
|
@ViewBuilder
|
|
func defaultScrollAnchorBottomSizeChanges() -> some View {
|
|
if #available(iOS 18, macOS 15, *) {
|
|
AnyView(self.defaultScrollAnchor(.bottom, for: .sizeChanges))
|
|
} else {
|
|
AnyView(self)
|
|
}
|
|
}
|
|
|
|
@ViewBuilder func `if`<Content: View>(_ condition: @autoclosure () -> Bool, transform: (Self) -> Content) -> some View {
|
|
if condition() {
|
|
transform(self)
|
|
} else {
|
|
self
|
|
}
|
|
}
|
|
|
|
/// Standard capsule-shaped prominent button styling.
|
|
/// On iOS 26+ the button also receives a glass background effect.
|
|
@ViewBuilder
|
|
func capsuleButtonStyle() -> some View {
|
|
if #available(iOS 26.0, macOS 26.0, *) {
|
|
self
|
|
.buttonBorderShape(.capsule)
|
|
.controlSize(.large)
|
|
.padding()
|
|
.buttonStyle(.borderedProminent)
|
|
.glassEffect(in: .capsule)
|
|
} else {
|
|
self
|
|
.buttonBorderShape(.capsule)
|
|
.controlSize(.large)
|
|
.padding()
|
|
.buttonStyle(.borderedProminent)
|
|
}
|
|
}
|
|
|
|
@ViewBuilder
|
|
func glassButtonStyle() -> some View {
|
|
if #available(iOS 26.0, macOS 26.0, *) {
|
|
self.buttonStyle(.glass)
|
|
} else {
|
|
self
|
|
.tint(Color(UIColor.secondarySystemBackground))
|
|
.foregroundColor(.accentColor)
|
|
.buttonStyle(.borderedProminent)
|
|
}
|
|
}
|
|
}
|
|
|
|
private struct FirstAppear: ViewModifier {
|
|
let action: () -> Void
|
|
|
|
// 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()
|
|
}
|
|
}
|
|
}
|