Skip to content

Commit

Permalink
working changing theme of app
Browse files Browse the repository at this point in the history
  • Loading branch information
DenAlNik committed May 20, 2024
1 parent 001121d commit 096c00e
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 30 deletions.
68 changes: 68 additions & 0 deletions LiveRecipes/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,23 @@
}
}
},
"dark.theme" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Dark"
}
},
"ru" : {
"stringUnit" : {
"state" : "translated",
"value" : "Темная"
}
}
}
},
"Delete" : {
"localizations" : {
"ru" : {
Expand Down Expand Up @@ -1347,6 +1364,23 @@
}
}
},
"light.theme" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Light"
}
},
"ru" : {
"stringUnit" : {
"state" : "translated",
"value" : "Светлая"
}
}
}
},
"min.filters" : {
"extractionState" : "manual",
"localizations" : {
Expand Down Expand Up @@ -2604,6 +2638,23 @@
}
}
},
"system.theme" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "System"
}
},
"ru" : {
"stringUnit" : {
"state" : "translated",
"value" : "Системная"
}
}
}
},
"tab.cooking" : {
"extractionState" : "manual",
"localizations" : {
Expand Down Expand Up @@ -2672,6 +2723,23 @@
}
}
},
"theme.settings" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Theme"
}
},
"ru" : {
"stringUnit" : {
"state" : "translated",
"value" : "Тема"
}
}
}
},
"then" : {
"extractionState" : "manual",
"localizations" : {
Expand Down
77 changes: 47 additions & 30 deletions LiveRecipes/Modules/Settings/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,59 @@ import SwiftUI
struct SettingsView: View {
@StateObject var viewState: SettingsViewModel
@State private var isShowingCreationView = false
@StateObject var creationViewModel = CreationViewModel(creationModel: CreationModel())//это временная дичь
@StateObject var creationViewModel = CreationViewModel(creationModel: CreationModel())

var body: some View {
List {
Section(header: Text("settings.userSettings".localized)) {
Button(action: {
viewState.clearMyRecipes()
})
{
Text("settings.clearMyRecipes".localized)
.tint(.black)
List {
Section {
Picker(selection: $viewState.selectedSegment, label: Text("Select a segment")) {
ForEach(0..<viewState.segments.count) { index in
Text(viewState.segments[index]).tag(index)
}
}

Button(action: {
viewState.clearFavorites()
})
{
Text("settings.clearFavourites".localized)
.tint(.black)
.pickerStyle(.segmented)
.frame(width: 350)
.listRowBackground(Color.clear)
.onChange(of: viewState.selectedSegment) { _, _ in
viewState.changeTheme()
}
Button(action: {
viewState.clearRecents()
})
{
Text("settings.clearRecents".localized)
.tint(.black)
}
NavigationLink(destination: CreationView(viewState: creationViewModel), isActive: $isShowingCreationView, label: {
Text("settings.publishMyRecipe".localized)
.onTapGesture {
print("settings.publishMyRecipe".localized)
isShowingCreationView = true
}
})
.preferredColorScheme(viewState.colorScheme)
} header: {
Text("theme.settings".localized)
}
Section(header: Text("settings.userSettings".localized)) {
Button(action: {
viewState.clearMyRecipes()
})
{
Text("settings.clearMyRecipes".localized)
.tint(.black)
}

Button(action: {
viewState.clearFavorites()
})
{
Text("settings.clearFavourites".localized)
.tint(.black)
}
Button(action: {
viewState.clearRecents()
})
{
Text("settings.clearRecents".localized)
.tint(.black)
}
NavigationLink(destination: CreationView(viewState: creationViewModel), isActive: $isShowingCreationView, label: {
Text("settings.publishMyRecipe".localized)
.onTapGesture {
print("settings.publishMyRecipe".localized)
isShowingCreationView = true
}
})
}
}
.listSectionSpacing(.custom(10))
.navigationTitle("settings".localized)
.navigationBarTitleDisplayMode(.inline)
}
Expand Down
18 changes: 18 additions & 0 deletions LiveRecipes/Modules/Settings/SettingsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@
//

import Foundation
import SwiftUI

final class SettingsViewModel: ObservableObject, SettingsViewModelProtocol {
var model: SettingsModelProtocol

let segments = ["light.theme".localized, "system.theme".localized, "dark.theme".localized]
@Published var selectedSegment = 1
@Published var colorScheme: ColorScheme?

init(settingsModel: SettingsModelProtocol) {
self.model = settingsModel
}
Expand Down Expand Up @@ -40,4 +45,17 @@ final class SettingsViewModel: ObservableObject, SettingsViewModelProtocol {
}
}
}
func changeTheme() {
switch selectedSegment {
case 0:
colorScheme = .light
case 1:
colorScheme = nil
case 2:
colorScheme = .dark
default:
break
}
print(segments[selectedSegment])
}
}

0 comments on commit 096c00e

Please sign in to comment.