mirror of
https://github.com/metabolist/metatext.git
synced 2024-12-18 11:46:27 +00:00
Add preference to override color scheme / appearance (#142)
* Add color scheme / appearance switcher * Refactoring * Refactoring Co-authored-by: Justin Mazzocchi <2831158+jzzocc@users.noreply.github.com>
This commit is contained in:
parent
436cf0a045
commit
5d7d28dbe5
11 changed files with 99 additions and 2 deletions
|
@ -201,6 +201,10 @@
|
||||||
"preferences" = "Einstellungen";
|
"preferences" = "Einstellungen";
|
||||||
"preferences.app" = "App Einstellungen";
|
"preferences.app" = "App Einstellungen";
|
||||||
"preferences.app-icon" = "App Icon";
|
"preferences.app-icon" = "App Icon";
|
||||||
|
"preferences.app.color-scheme" = "Erscheinungsbild";
|
||||||
|
"preferences.app.color-scheme.dark" = "Dunkel";
|
||||||
|
"preferences.app.color-scheme.light" = "Hell";
|
||||||
|
"preferences.app.color-scheme.system" = "System";
|
||||||
"preferences.blocked-domains" = "Gesperrte Domains";
|
"preferences.blocked-domains" = "Gesperrte Domains";
|
||||||
"preferences.blocked-users" = "Gesperrte Nutzer";
|
"preferences.blocked-users" = "Gesperrte Nutzer";
|
||||||
"preferences.media" = "Medien";
|
"preferences.media" = "Medien";
|
||||||
|
|
|
@ -201,6 +201,10 @@
|
||||||
"preferences" = "Preferences";
|
"preferences" = "Preferences";
|
||||||
"preferences.app" = "App Preferences";
|
"preferences.app" = "App Preferences";
|
||||||
"preferences.app-icon" = "App Icon";
|
"preferences.app-icon" = "App Icon";
|
||||||
|
"preferences.app.color-scheme" = "Appearance";
|
||||||
|
"preferences.app.color-scheme.dark" = "Dark";
|
||||||
|
"preferences.app.color-scheme.light" = "Light";
|
||||||
|
"preferences.app.color-scheme.system" = "System";
|
||||||
"preferences.blocked-domains" = "Blocked Domains";
|
"preferences.blocked-domains" = "Blocked Domains";
|
||||||
"preferences.blocked-users" = "Blocked Users";
|
"preferences.blocked-users" = "Blocked Users";
|
||||||
"preferences.media" = "Media";
|
"preferences.media" = "Media";
|
||||||
|
|
|
@ -201,6 +201,10 @@
|
||||||
"preferences" = "Ajustes";
|
"preferences" = "Ajustes";
|
||||||
"preferences.app" = "Ajustes de la App";
|
"preferences.app" = "Ajustes de la App";
|
||||||
"preferences.app-icon" = "Icono de la App";
|
"preferences.app-icon" = "Icono de la App";
|
||||||
|
"preferences.app.color-scheme" = "Appearance";
|
||||||
|
"preferences.app.color-scheme.dark" = "Dark";
|
||||||
|
"preferences.app.color-scheme.light" = "Light";
|
||||||
|
"preferences.app.color-scheme.system" = "System";
|
||||||
"preferences.blocked-domains" = "Dominios bloqueados";
|
"preferences.blocked-domains" = "Dominios bloqueados";
|
||||||
"preferences.blocked-users" = "Usuarios bloqueados";
|
"preferences.blocked-users" = "Usuarios bloqueados";
|
||||||
"preferences.media" = "Multimedia";
|
"preferences.media" = "Multimedia";
|
||||||
|
|
|
@ -201,6 +201,10 @@
|
||||||
"preferences" = "環境設定";
|
"preferences" = "環境設定";
|
||||||
"preferences.app" = "アプリ環境設定";
|
"preferences.app" = "アプリ環境設定";
|
||||||
"preferences.app-icon" = "アプリアイコン";
|
"preferences.app-icon" = "アプリアイコン";
|
||||||
|
"preferences.app.color-scheme" = "Appearance";
|
||||||
|
"preferences.app.color-scheme.dark" = "Dark";
|
||||||
|
"preferences.app.color-scheme.light" = "Light";
|
||||||
|
"preferences.app.color-scheme.system" = "System";
|
||||||
"preferences.blocked-domains" = "ブロックしたドメイン";
|
"preferences.blocked-domains" = "ブロックしたドメイン";
|
||||||
"preferences.blocked-users" = "ブロックしたユーザー";
|
"preferences.blocked-users" = "ブロックしたユーザー";
|
||||||
"preferences.media" = "メディア";
|
"preferences.media" = "メディア";
|
||||||
|
|
|
@ -201,6 +201,10 @@
|
||||||
"preferences" = "설정";
|
"preferences" = "설정";
|
||||||
"preferences.app" = "앱 설정";
|
"preferences.app" = "앱 설정";
|
||||||
"preferences.app-icon" = "앱 아이콘";
|
"preferences.app-icon" = "앱 아이콘";
|
||||||
|
"preferences.app.color-scheme" = "Appearance";
|
||||||
|
"preferences.app.color-scheme.dark" = "Dark";
|
||||||
|
"preferences.app.color-scheme.light" = "Light";
|
||||||
|
"preferences.app.color-scheme.system" = "System";
|
||||||
"preferences.blocked-domains" = "차단된 도메인";
|
"preferences.blocked-domains" = "차단된 도메인";
|
||||||
"preferences.blocked-users" = "차단된 사용자";
|
"preferences.blocked-users" = "차단된 사용자";
|
||||||
"preferences.media" = "미디어";
|
"preferences.media" = "미디어";
|
||||||
|
|
|
@ -201,6 +201,10 @@
|
||||||
"preferences" = "Właściwości";
|
"preferences" = "Właściwości";
|
||||||
"preferences.app" = "Ustawienia aplikacji";
|
"preferences.app" = "Ustawienia aplikacji";
|
||||||
"preferences.app-icon" = "Ikona aplikacji";
|
"preferences.app-icon" = "Ikona aplikacji";
|
||||||
|
"preferences.app.color-scheme" = "Appearance";
|
||||||
|
"preferences.app.color-scheme.dark" = "Dark";
|
||||||
|
"preferences.app.color-scheme.light" = "Light";
|
||||||
|
"preferences.app.color-scheme.system" = "System";
|
||||||
"preferences.blocked-domains" = "Zablokowane domeny";
|
"preferences.blocked-domains" = "Zablokowane domeny";
|
||||||
"preferences.blocked-users" = "Zablokowane profile";
|
"preferences.blocked-users" = "Zablokowane profile";
|
||||||
"preferences.media" = "Media";
|
"preferences.media" = "Media";
|
||||||
|
|
|
@ -201,6 +201,10 @@
|
||||||
"preferences" = "Настройки";
|
"preferences" = "Настройки";
|
||||||
"preferences.app" = "Настройки приложения";
|
"preferences.app" = "Настройки приложения";
|
||||||
"preferences.app-icon" = "Значок приложения";
|
"preferences.app-icon" = "Значок приложения";
|
||||||
|
"preferences.app.color-scheme" = "Appearance";
|
||||||
|
"preferences.app.color-scheme.dark" = "Dark";
|
||||||
|
"preferences.app.color-scheme.light" = "Light";
|
||||||
|
"preferences.app.color-scheme.system" = "System";
|
||||||
"preferences.blocked-domains" = "Заблокированные домены";
|
"preferences.blocked-domains" = "Заблокированные домены";
|
||||||
"preferences.blocked-users" = "Заблокированные пользователи";
|
"preferences.blocked-users" = "Заблокированные пользователи";
|
||||||
"preferences.media" = "Медиафайлы";
|
"preferences.media" = "Медиафайлы";
|
||||||
|
|
|
@ -201,6 +201,10 @@
|
||||||
"preferences" = "偏好设置";
|
"preferences" = "偏好设置";
|
||||||
"preferences.app" = "应用偏好设置";
|
"preferences.app" = "应用偏好设置";
|
||||||
"preferences.app-icon" = "应用图标";
|
"preferences.app-icon" = "应用图标";
|
||||||
|
"preferences.app.color-scheme" = "Appearance";
|
||||||
|
"preferences.app.color-scheme.dark" = "Dark";
|
||||||
|
"preferences.app.color-scheme.light" = "Light";
|
||||||
|
"preferences.app.color-scheme.system" = "System";
|
||||||
"preferences.blocked-domains" = "已屏蔽的域名";
|
"preferences.blocked-domains" = "已屏蔽的域名";
|
||||||
"preferences.blocked-users" = "已屏蔽的用户";
|
"preferences.blocked-users" = "已屏蔽的用户";
|
||||||
"preferences.media" = "媒体";
|
"preferences.media" = "媒体";
|
||||||
|
|
|
@ -17,6 +17,14 @@ public struct AppPreferences {
|
||||||
}
|
}
|
||||||
|
|
||||||
public extension AppPreferences {
|
public extension AppPreferences {
|
||||||
|
enum ColorScheme: String, CaseIterable, Identifiable {
|
||||||
|
case system
|
||||||
|
case light
|
||||||
|
case dark
|
||||||
|
|
||||||
|
public var id: String { rawValue }
|
||||||
|
}
|
||||||
|
|
||||||
enum StatusWord: String, CaseIterable, Identifiable {
|
enum StatusWord: String, CaseIterable, Identifiable {
|
||||||
case toot
|
case toot
|
||||||
case post
|
case post
|
||||||
|
@ -47,6 +55,18 @@ public extension AppPreferences {
|
||||||
public var id: String { rawValue }
|
public var id: String { rawValue }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var colorScheme: ColorScheme {
|
||||||
|
get {
|
||||||
|
if let rawValue = self[.colorScheme] as String?,
|
||||||
|
let value = ColorScheme(rawValue: rawValue) {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
return .system
|
||||||
|
}
|
||||||
|
set { self[.colorScheme] = newValue.rawValue }
|
||||||
|
}
|
||||||
|
|
||||||
var statusWord: StatusWord {
|
var statusWord: StatusWord {
|
||||||
get {
|
get {
|
||||||
if let rawValue = self[.statusWord] as String?,
|
if let rawValue = self[.statusWord] as String?,
|
||||||
|
@ -185,6 +205,7 @@ public extension AppPreferences {
|
||||||
|
|
||||||
private extension AppPreferences {
|
private extension AppPreferences {
|
||||||
enum Item: String {
|
enum Item: String {
|
||||||
|
case colorScheme
|
||||||
case statusWord
|
case statusWord
|
||||||
case requireDoubleTapToReblog
|
case requireDoubleTapToReblog
|
||||||
case requireDoubleTapToFavorite
|
case requireDoubleTapToFavorite
|
||||||
|
|
|
@ -88,6 +88,11 @@ struct PreferencesView: View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Picker("preferences.app.color-scheme", selection: $identityContext.appPreferences.colorScheme) {
|
||||||
|
ForEach(AppPreferences.ColorScheme.allCases) { option in
|
||||||
|
Text(option.localizedStringKey).tag(option)
|
||||||
|
}
|
||||||
|
}
|
||||||
NavigationLink("preferences.notifications",
|
NavigationLink("preferences.notifications",
|
||||||
destination: NotificationPreferencesView(viewModel: viewModel))
|
destination: NotificationPreferencesView(viewModel: viewModel))
|
||||||
Picker("preferences.status-word",
|
Picker("preferences.status-word",
|
||||||
|
@ -153,6 +158,19 @@ struct PreferencesView: View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension AppPreferences.ColorScheme {
|
||||||
|
var localizedStringKey: LocalizedStringKey {
|
||||||
|
switch self {
|
||||||
|
case .system:
|
||||||
|
return "preferences.app.color-scheme.system"
|
||||||
|
case .light:
|
||||||
|
return "preferences.app.color-scheme.light"
|
||||||
|
case .dark:
|
||||||
|
return "preferences.app.color-scheme.dark"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extension AppPreferences.StatusWord {
|
extension AppPreferences.StatusWord {
|
||||||
var localizedStringKey: LocalizedStringKey {
|
var localizedStringKey: LocalizedStringKey {
|
||||||
switch self {
|
switch self {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// Copyright © 2020 Metabolist. All rights reserved.
|
// Copyright © 2020 Metabolist. All rights reserved.
|
||||||
|
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
import UIKit
|
||||||
import ViewModels
|
import ViewModels
|
||||||
|
|
||||||
struct RootView: View {
|
struct RootView: View {
|
||||||
|
@ -13,13 +14,15 @@ struct RootView: View {
|
||||||
.environmentObject(viewModel)
|
.environmentObject(viewModel)
|
||||||
.transition(.opacity)
|
.transition(.opacity)
|
||||||
.edgesIgnoringSafeArea(.all)
|
.edgesIgnoringSafeArea(.all)
|
||||||
|
.onReceive(navigationViewModel.identityContext.$appPreferences.map(\.colorScheme),
|
||||||
|
perform: setColorScheme)
|
||||||
} else {
|
} else {
|
||||||
NavigationView {
|
NavigationView {
|
||||||
AddIdentityView(
|
AddIdentityView(
|
||||||
viewModelClosure: { viewModel.addIdentityViewModel() },
|
viewModelClosure: { viewModel.addIdentityViewModel() },
|
||||||
displayWelcome: true)
|
displayWelcome: true)
|
||||||
.navigationBarTitleDisplayMode(.inline)
|
.navigationBarTitleDisplayMode(.inline)
|
||||||
.navigationBarHidden(true)
|
.navigationBarHidden(true)
|
||||||
}
|
}
|
||||||
.environmentObject(viewModel)
|
.environmentObject(viewModel)
|
||||||
.navigationViewStyle(StackNavigationViewStyle())
|
.navigationViewStyle(StackNavigationViewStyle())
|
||||||
|
@ -28,6 +31,29 @@ struct RootView: View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private extension RootView {
|
||||||
|
func setColorScheme(_ colorScheme: AppPreferences.ColorScheme) {
|
||||||
|
for scene in UIApplication.shared.connectedScenes.compactMap({ $0 as? UIWindowScene }) {
|
||||||
|
for window in scene.windows {
|
||||||
|
window.overrideUserInterfaceStyle = colorScheme.uiKit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension AppPreferences.ColorScheme {
|
||||||
|
var uiKit: UIUserInterfaceStyle {
|
||||||
|
switch self {
|
||||||
|
case .system:
|
||||||
|
return .unspecified
|
||||||
|
case .light:
|
||||||
|
return .light
|
||||||
|
case .dark:
|
||||||
|
return .dark
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
import Combine
|
import Combine
|
||||||
import PreviewViewModels
|
import PreviewViewModels
|
||||||
|
|
Loading…
Reference in a new issue