Fix Overview flicker on legacy iOS
This commit is contained in:
@@ -8,19 +8,19 @@ import SwiftUI
|
||||
@EnvironmentObject private var environments: ExtensionEnvironments
|
||||
@EnvironmentObject private var profile: ExtensionProfile
|
||||
@ObservedObject private var coordinator: DashboardViewModel
|
||||
@State private var cardConfigurationVersion = 0
|
||||
@StateObject private var cardConfiguration = DashboardCardConfiguration()
|
||||
#if os(iOS) || os(tvOS)
|
||||
@State private var showCardManagement = false
|
||||
@State private var showGroups = false
|
||||
@State private var showConnections = false
|
||||
@State private var buttonState = ButtonVisibilityState()
|
||||
#endif
|
||||
#if os(macOS)
|
||||
@Environment(\.cardConfigurationVersion) private var cardConfigurationVersion
|
||||
#endif
|
||||
|
||||
private let externalCardConfigurationVersion: Int?
|
||||
|
||||
public init(coordinator: DashboardViewModel, externalCardConfigurationVersion: Int? = nil) {
|
||||
public init(coordinator: DashboardViewModel) {
|
||||
_coordinator = ObservedObject(wrappedValue: coordinator)
|
||||
self.externalCardConfigurationVersion = externalCardConfigurationVersion
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
@@ -100,7 +100,7 @@ import SwiftUI
|
||||
}
|
||||
.navigationDestination(isPresented: $showCardManagement) {
|
||||
CardManagementView(onDisappear: {
|
||||
cardConfigurationVersion += 1
|
||||
Task { await cardConfiguration.reload() }
|
||||
})
|
||||
.navigationTitle("Dashboard Items")
|
||||
.toolbar {
|
||||
@@ -115,7 +115,7 @@ import SwiftUI
|
||||
}.sheet(isPresented: $showConnections) {
|
||||
connectionsSheetContent
|
||||
}.sheet(isPresented: $showCardManagement, onDismiss: {
|
||||
cardConfigurationVersion += 1
|
||||
Task { await cardConfiguration.reload() }
|
||||
}, content: {
|
||||
if #available(iOS 16.0, *) {
|
||||
CardManagementSheet().presentationDetents([.large]).presentationDragIndicator(.visible)
|
||||
@@ -174,6 +174,11 @@ import SwiftUI
|
||||
updateButtonVisibility()
|
||||
}
|
||||
#endif
|
||||
#if os(macOS)
|
||||
.onChangeCompat(of: cardConfigurationVersion) { _ in
|
||||
Task { await cardConfiguration.reload() }
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@ViewBuilder private var overviewPage: some View {
|
||||
@@ -182,7 +187,7 @@ import SwiftUI
|
||||
$coordinator.selectedProfileID,
|
||||
$coordinator.systemProxyAvailable,
|
||||
$coordinator.systemProxyEnabled,
|
||||
cardConfigurationVersion: externalCardConfigurationVersion ?? cardConfigurationVersion
|
||||
cardConfiguration: cardConfiguration
|
||||
)
|
||||
}
|
||||
|
||||
@@ -228,7 +233,7 @@ import SwiftUI
|
||||
$coordinator.selectedProfileID,
|
||||
$coordinator.systemProxyAvailable,
|
||||
$coordinator.systemProxyEnabled,
|
||||
externalCardConfigurationVersion ?? cardConfigurationVersion
|
||||
cardConfiguration
|
||||
)
|
||||
.tag(page)
|
||||
}
|
||||
|
||||
@@ -64,11 +64,11 @@ public extension DashboardPage {
|
||||
}
|
||||
|
||||
@MainActor
|
||||
func contentView(_ profileList: Binding<[ProfilePreview]>, _ selectedProfileID: Binding<Int64>, _ systemProxyAvailable: Binding<Bool>, _ systemProxyEnabled: Binding<Bool>, _ cardConfigurationVersion: Int) -> some View {
|
||||
func contentView(_ profileList: Binding<[ProfilePreview]>, _ selectedProfileID: Binding<Int64>, _ systemProxyAvailable: Binding<Bool>, _ systemProxyEnabled: Binding<Bool>, _ cardConfiguration: DashboardCardConfiguration) -> some View {
|
||||
Group {
|
||||
switch self {
|
||||
case .overview:
|
||||
OverviewView(profileList, selectedProfileID, systemProxyAvailable, systemProxyEnabled, cardConfigurationVersion: cardConfigurationVersion)
|
||||
OverviewView(profileList, selectedProfileID, systemProxyAvailable, systemProxyEnabled, cardConfiguration: cardConfiguration)
|
||||
case .groups:
|
||||
GroupListView()
|
||||
case .connections:
|
||||
|
||||
@@ -5,7 +5,6 @@ import SwiftUI
|
||||
@MainActor
|
||||
public struct DashboardView: View {
|
||||
@Environment(\.openURL) private var openURL
|
||||
@Environment(\.cardConfigurationVersion) private var cardConfigurationVersion
|
||||
@Environment(\.importProfile) private var importProfile
|
||||
@Environment(\.importRemoteProfile) private var importRemoteProfile
|
||||
@EnvironmentObject private var environments: ExtensionEnvironments
|
||||
@@ -148,10 +147,6 @@ public struct DashboardView: View {
|
||||
|
||||
@ViewBuilder
|
||||
private var activeDashboardView: some View {
|
||||
#if os(macOS)
|
||||
ActiveDashboardView(coordinator: coordinator, externalCardConfigurationVersion: cardConfigurationVersion)
|
||||
#else
|
||||
ActiveDashboardView(coordinator: coordinator)
|
||||
#endif
|
||||
ActiveDashboardView(coordinator: coordinator)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,26 +8,25 @@ public struct OverviewView: View {
|
||||
@EnvironmentObject private var environments: ExtensionEnvironments
|
||||
@EnvironmentObject private var profile: ExtensionProfile
|
||||
@StateObject private var coordinator = OverviewViewModel()
|
||||
@StateObject private var configuration = DashboardCardConfiguration()
|
||||
@ObservedObject private var configuration: DashboardCardConfiguration
|
||||
|
||||
@Binding private var profileList: [ProfilePreview]
|
||||
@Binding private var selectedProfileID: Int64
|
||||
@Binding private var systemProxyAvailable: Bool
|
||||
@Binding private var systemProxyEnabled: Bool
|
||||
private let cardConfigurationVersion: Int
|
||||
|
||||
public init(
|
||||
_ profileList: Binding<[ProfilePreview]>,
|
||||
_ selectedProfileID: Binding<Int64>,
|
||||
_ systemProxyAvailable: Binding<Bool>,
|
||||
_ systemProxyEnabled: Binding<Bool>,
|
||||
cardConfigurationVersion: Int
|
||||
cardConfiguration: DashboardCardConfiguration
|
||||
) {
|
||||
_profileList = profileList
|
||||
_selectedProfileID = selectedProfileID
|
||||
_systemProxyAvailable = systemProxyAvailable
|
||||
_systemProxyEnabled = systemProxyEnabled
|
||||
self.cardConfigurationVersion = cardConfigurationVersion
|
||||
_configuration = ObservedObject(wrappedValue: cardConfiguration)
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
@@ -41,9 +40,6 @@ public struct OverviewView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
.onChangeCompat(of: cardConfigurationVersion) { _ in
|
||||
Task { await configuration.reload() }
|
||||
}
|
||||
.alert($coordinator.alert)
|
||||
.disabled(!ApplicationLibrary.inPreview && (!profile.status.isSwitchable || coordinator.reasserting))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user