-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #1 :O Only downside is the setting doesn't propagate to the main app view. I'm *guessing* it's because the environment is set again in RecentRoomsView. Not sure though.
- Loading branch information
Showing
6 changed files
with
91 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import SwiftUI | ||
|
||
extension Color { | ||
static var allAccentOptions: [Color] { | ||
[ | ||
.purple, | ||
.blue, | ||
.red, | ||
.orange, | ||
.green, | ||
.gray, | ||
.yellow | ||
] | ||
} | ||
|
||
init?(description: String) { | ||
switch description { | ||
case "purple": self = .purple | ||
case "blue": self = .blue | ||
case "red": self = .red | ||
case "orange": self = .orange | ||
case "green": self = .green | ||
case "gray": self = .gray | ||
case "yellow": self = .yellow | ||
default: self = .purple | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import Foundation | ||
import SwiftUI | ||
import Combine | ||
|
||
class AppSettings: ObservableObject { | ||
var accentColor: Color { | ||
get { | ||
guard | ||
let stored = UserDefaults.standard.string(forKey: "accentColor"), | ||
let color = Color(description: stored) | ||
else { return .purple } | ||
return color | ||
} | ||
set { | ||
UserDefaults.standard.set(newValue.description, forKey: "accentColor") | ||
objectWillChange.send() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,50 @@ | ||
import SwiftUI | ||
|
||
struct SettingsView: View { | ||
struct SettingsContainerView: View { | ||
@EnvironmentObject var store: AccountStore | ||
@EnvironmentObject var settings: AppSettings | ||
|
||
var body: some View { | ||
SettingsView(accentColor: $settings.accentColor, logoutAction: { self.store.logout() }) | ||
} | ||
} | ||
|
||
struct SettingsView: View { | ||
@Binding var accentColor: Color | ||
var logoutAction: () -> Void | ||
|
||
var body: some View { | ||
NavigationView { | ||
List { | ||
Form { | ||
Section { | ||
Picker(selection: $accentColor, label: Text("Accent Color")) { | ||
ForEach(Color.allAccentOptions, id: \.self) { color in | ||
HStack { | ||
Circle() | ||
.frame(width: 20) | ||
.foregroundColor(color) | ||
Text(color.description.capitalized) | ||
} | ||
.tag(color) | ||
} | ||
} | ||
} | ||
|
||
Section { | ||
Button(action: { | ||
self.store.logout() | ||
self.logoutAction() | ||
}, label: { | ||
Text("Log Out") | ||
}) | ||
} | ||
} | ||
.listStyle(GroupedListStyle()) | ||
.navigationBarTitle("Settings", displayMode: .inline) | ||
} | ||
} | ||
} | ||
|
||
struct SettingsView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
SettingsView() | ||
SettingsView(accentColor: .constant(.purple), logoutAction: {}) | ||
} | ||
} |