Fix flashing context menu on data count update (#803)
Observe tunnel in InstalledProfileView subviews to avoid redraw of whole view and context menu.
This commit is contained in:
parent
15959d2422
commit
3f7ad5bf57
|
@ -39,8 +39,7 @@ struct InstalledProfileView: View, Routable {
|
||||||
|
|
||||||
let profile: Profile?
|
let profile: Profile?
|
||||||
|
|
||||||
@ObservedObject
|
let tunnel: ExtendedTunnel
|
||||||
var tunnel: ExtendedTunnel
|
|
||||||
|
|
||||||
let interactiveManager: InteractiveManager
|
let interactiveManager: InteractiveManager
|
||||||
|
|
||||||
|
@ -100,30 +99,25 @@ private extension InstalledProfileView {
|
||||||
var statusView: some View {
|
var statusView: some View {
|
||||||
HStack {
|
HStack {
|
||||||
providerSelectorButton
|
providerSelectorButton
|
||||||
ConnectionStatusText(tunnel: tunnel)
|
StatusText(
|
||||||
.font(.body)
|
theme: theme,
|
||||||
.foregroundStyle(tunnel.statusColor(theme))
|
tunnel: tunnel,
|
||||||
.opacity(installedOpacity)
|
opacity: installedOpacity
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var toggleButton: some View {
|
var toggleButton: some View {
|
||||||
TunnelToggleButton(
|
ToggleButton(
|
||||||
|
theme: theme,
|
||||||
tunnel: tunnel,
|
tunnel: tunnel,
|
||||||
profile: profile,
|
profile: profile,
|
||||||
nextProfileId: $nextProfileId,
|
nextProfileId: $nextProfileId,
|
||||||
interactiveManager: interactiveManager,
|
interactiveManager: interactiveManager,
|
||||||
errorHandler: errorHandler,
|
errorHandler: errorHandler,
|
||||||
onProviderEntityRequired: flow?.onEditProviderEntity,
|
opacity: installedOpacity,
|
||||||
label: { _ in
|
flow: flow
|
||||||
ThemeImage(.tunnelToggle)
|
|
||||||
.scaleEffect(1.5, anchor: .trailing)
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
// TODO: #584, necessary to avoid cell selection
|
|
||||||
.buttonStyle(.plain)
|
|
||||||
.foregroundStyle(tunnel.statusColor(theme))
|
|
||||||
.opacity(installedOpacity)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var menuContent: some View {
|
var menuContent: some View {
|
||||||
|
@ -156,6 +150,69 @@ private extension InstalledProfileView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Subviews (observing)
|
||||||
|
|
||||||
|
private struct StatusText: View {
|
||||||
|
|
||||||
|
@ObservedObject
|
||||||
|
var theme: Theme
|
||||||
|
|
||||||
|
@ObservedObject
|
||||||
|
var tunnel: ExtendedTunnel
|
||||||
|
|
||||||
|
let opacity: Double
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
ConnectionStatusText(tunnel: tunnel)
|
||||||
|
.font(.body)
|
||||||
|
.foregroundStyle(tunnel.statusColor(theme))
|
||||||
|
.opacity(opacity)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private struct ToggleButton: View {
|
||||||
|
|
||||||
|
@ObservedObject
|
||||||
|
var theme: Theme
|
||||||
|
|
||||||
|
@ObservedObject
|
||||||
|
var tunnel: ExtendedTunnel
|
||||||
|
|
||||||
|
let profile: Profile?
|
||||||
|
|
||||||
|
@Binding
|
||||||
|
var nextProfileId: Profile.ID?
|
||||||
|
|
||||||
|
@ObservedObject
|
||||||
|
var interactiveManager: InteractiveManager
|
||||||
|
|
||||||
|
@ObservedObject
|
||||||
|
var errorHandler: ErrorHandler
|
||||||
|
|
||||||
|
let opacity: Double
|
||||||
|
|
||||||
|
let flow: ProfileFlow?
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
TunnelToggleButton(
|
||||||
|
tunnel: tunnel,
|
||||||
|
profile: profile,
|
||||||
|
nextProfileId: $nextProfileId,
|
||||||
|
interactiveManager: interactiveManager,
|
||||||
|
errorHandler: errorHandler,
|
||||||
|
onProviderEntityRequired: flow?.onEditProviderEntity,
|
||||||
|
label: { _ in
|
||||||
|
ThemeImage(.tunnelToggle)
|
||||||
|
.scaleEffect(1.5, anchor: .trailing)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
// TODO: #584, necessary to avoid cell selection
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
.foregroundStyle(tunnel.statusColor(theme))
|
||||||
|
.opacity(opacity)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private struct ProviderCountryFlag: View {
|
private struct ProviderCountryFlag: View {
|
||||||
let provider: ModuleMetadata.Provider
|
let provider: ModuleMetadata.Provider
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue