Share animation type in theme

This commit is contained in:
Davide De Rosa 2022-04-23 12:08:24 +02:00
parent 7eb2b3bd0e
commit 0b1e465143
10 changed files with 26 additions and 12 deletions

View File

@ -310,6 +310,20 @@ extension View {
} }
} }
// MARK: Animations
extension View {
func themeAnimation<V: Equatable>(on value: V) -> some View {
animation(.default, value: value)
}
}
extension Binding {
func themeAnimation() -> Binding<Value> {
animation(.default)
}
}
// MARK: Shortcuts // MARK: Shortcuts
extension View { extension View {

View File

@ -61,7 +61,7 @@ struct AddHostView: View {
} else { } else {
completeView completeView
} }
}.animation(.default, value: viewModel) }.themeAnimation(on: viewModel)
}.toolbar { }.toolbar {
themeCloseItem(isPresented: bindings.$isPresented) themeCloseItem(isPresented: bindings.$isPresented)
ToolbarItem(placement: .primaryAction) { ToolbarItem(placement: .primaryAction) {

View File

@ -84,7 +84,7 @@ struct AddProviderView: View {
}.onChange(of: viewModel.errorMessage) { }.onChange(of: viewModel.errorMessage) {
onErrorMessage($0, scrollProxy) onErrorMessage($0, scrollProxy)
}.disabled(viewModel.pendingOperation != nil) }.disabled(viewModel.pendingOperation != nil)
.animation(.default, value: providers) .themeAnimation(on: providers)
} }
}.toolbar { }.toolbar {
themeCloseItem(isPresented: bindings.$isPresented) themeCloseItem(isPresented: bindings.$isPresented)

View File

@ -73,7 +73,7 @@ struct DonateView: View {
if newValue == .active { if newValue == .active {
productManager.refreshProducts() productManager.refreshProducts()
} }
}.animation(.default, value: productManager.isRefreshingProducts) }.themeAnimation(on: productManager.isRefreshingProducts)
} }
private func presentedAlert(_ alertType: AlertType) -> Alert { private func presentedAlert(_ alertType: AlertType) -> Alert {

View File

@ -132,7 +132,7 @@ extension EndpointView {
extension EndpointView.OpenVPNView { extension EndpointView.OpenVPNView {
private var mainSection: some View { private var mainSection: some View {
Section { Section {
Toggle(L10n.Global.Strings.automatic, isOn: $isAutomatic.animation()) Toggle(L10n.Global.Strings.automatic, isOn: $isAutomatic.themeAnimation())
} }
} }

View File

@ -100,7 +100,7 @@ extension NetworkSettingsView {
Section( Section(
header: Text(L10n.NetworkSettings.Gateway.title) header: Text(L10n.NetworkSettings.Gateway.title)
) { ) {
Toggle(L10n.Global.Strings.automatic, isOn: $settings.isAutomaticGateway.animation()) Toggle(L10n.Global.Strings.automatic, isOn: $settings.isAutomaticGateway.themeAnimation())
if !settings.isAutomaticGateway { if !settings.isAutomaticGateway {
Toggle(Unlocalized.Network.ipv4, isOn: $settings.gateway.isDefaultIPv4) Toggle(Unlocalized.Network.ipv4, isOn: $settings.gateway.isDefaultIPv4)
@ -119,7 +119,7 @@ extension NetworkSettingsView {
Section( Section(
header: Text(Unlocalized.Network.dns) header: Text(Unlocalized.Network.dns)
) { ) {
Toggle(L10n.Global.Strings.automatic, isOn: $settings.isAutomaticDNS.animation()) Toggle(L10n.Global.Strings.automatic, isOn: $settings.isAutomaticDNS.themeAnimation())
if !settings.isAutomaticDNS { if !settings.isAutomaticDNS {
themeTextPicker( themeTextPicker(
@ -212,7 +212,7 @@ extension NetworkSettingsView {
Section( Section(
header: Text(L10n.Global.Strings.proxy) header: Text(L10n.Global.Strings.proxy)
) { ) {
Toggle(L10n.Global.Strings.automatic, isOn: $settings.isAutomaticProxy.animation()) Toggle(L10n.Global.Strings.automatic, isOn: $settings.isAutomaticProxy.themeAnimation())
if !settings.isAutomaticProxy { if !settings.isAutomaticProxy {
themeTextPicker( themeTextPicker(
@ -275,7 +275,7 @@ extension NetworkSettingsView {
Section( Section(
header: Text(Unlocalized.Network.mtu) header: Text(Unlocalized.Network.mtu)
) { ) {
Toggle(L10n.Global.Strings.automatic, isOn: $settings.isAutomaticMTU.animation()) Toggle(L10n.Global.Strings.automatic, isOn: $settings.isAutomaticMTU.themeAnimation())
if !settings.isAutomaticMTU { if !settings.isAutomaticMTU {
themeTextPicker( themeTextPicker(

View File

@ -72,7 +72,7 @@ struct OnDemandView: View {
extension OnDemandView { extension OnDemandView {
private var enabledView: some View { private var enabledView: some View {
Section { Section {
Toggle(L10n.Global.Strings.enabled, isOn: $onDemand.isEnabled.animation()) Toggle(L10n.Global.Strings.enabled, isOn: $onDemand.isEnabled.themeAnimation())
} }
} }

View File

@ -83,7 +83,7 @@ extension OrganizerView {
ForEach(otherHeaders, content: profileButton(forHeader:)) ForEach(otherHeaders, content: profileButton(forHeader:))
.onDelete(perform: removeOtherProfiles) .onDelete(perform: removeOtherProfiles)
} }
}.animation(.default, value: profileManager.headers) }.themeAnimation(on: profileManager.headers)
} }
private var emptyView: some View { private var emptyView: some View {

View File

@ -83,7 +83,7 @@ extension PaywallView {
if newValue == .active { if newValue == .active {
productManager.refreshProducts() productManager.refreshProducts()
} }
}.animation(.default, value: productManager.isRefreshingProducts) }.themeAnimation(on: productManager.isRefreshingProducts)
} }
private func presentedAlert(_ alertType: AlertType) -> Alert { private func presentedAlert(_ alertType: AlertType) -> Alert {

View File

@ -73,7 +73,7 @@ struct ShortcutsView: View {
// reloading // reloading
.onAppear { .onAppear {
intentsManager.reloadShortcuts() intentsManager.reloadShortcuts()
}.animation(.default, value: intentsManager.isReloadingShortcuts) }.themeAnimation(on: intentsManager.isReloadingShortcuts)
// IntentsUI // IntentsUI
.onReceive(intentsManager.shouldDismissIntentView) { _ in .onReceive(intentsManager.shouldDismissIntentView) { _ in