mirror of
https://github.com/metabolist/metatext.git
synced 2025-04-24 04:24:11 +00:00
Refactoring
This commit is contained in:
parent
77a1c799f5
commit
948db9d274
3 changed files with 12 additions and 18 deletions
Localizations/en.lproj
ViewModels/Sources/ViewModels/View Models
Views/SwiftUI
|
@ -348,7 +348,6 @@
|
|||
"status.visibility.unlisted.description" = "Visible for all, but not in public timelines";
|
||||
"status.visibility.private.description" = "Visible for followers only";
|
||||
"status.visibility.direct.description" = "Visible for mentioned users only";
|
||||
"system" = "System";
|
||||
"tag.accessibility-recent-uses-%ld" = "%ld recent uses";
|
||||
"tag.accessibility-hint.post" = "View posts associated with trend";
|
||||
"tag.accessibility-hint.toot" = "View toots associated with trend";
|
||||
|
|
|
@ -6,7 +6,7 @@ import Mastodon
|
|||
import ServiceLayer
|
||||
|
||||
public final class NavigationViewModel: ObservableObject {
|
||||
@Published public private(set) var identityContext: IdentityContext
|
||||
public let identityContext: IdentityContext
|
||||
public let navigations: AnyPublisher<Navigation, Never>
|
||||
|
||||
@Published public private(set) var recentIdentities = [Identity]()
|
||||
|
|
|
@ -6,11 +6,6 @@ import ViewModels
|
|||
|
||||
struct RootView: View {
|
||||
@StateObject var viewModel: RootViewModel
|
||||
@State private var previousColorScheme: AppPreferences.ColorScheme = .system
|
||||
var appPreferencesPublisher: AnyPublisher<AppPreferences, Never> {
|
||||
viewModel.navigationViewModel?.identityContext.$appPreferences.eraseToAnyPublisher()
|
||||
?? Empty<AppPreferences, Never>().eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
Group {
|
||||
|
@ -20,6 +15,8 @@ struct RootView: View {
|
|||
.environmentObject(viewModel)
|
||||
.transition(.opacity)
|
||||
.edgesIgnoringSafeArea(.all)
|
||||
.onReceive(navigationViewModel.identityContext.$appPreferences.map(\.colorScheme),
|
||||
perform: setColorScheme)
|
||||
} else {
|
||||
NavigationView {
|
||||
AddIdentityView(
|
||||
|
@ -33,20 +30,18 @@ struct RootView: View {
|
|||
.transition(.opacity)
|
||||
}
|
||||
}
|
||||
.onReceive(appPreferencesPublisher) { preferences in
|
||||
if preferences.colorScheme != previousColorScheme {
|
||||
self.previousColorScheme = preferences.colorScheme
|
||||
setColorScheme(preferences.colorScheme)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func setColorScheme(_ colorScheme: AppPreferences.ColorScheme) {
|
||||
let scenes = UIApplication.shared.connectedScenes
|
||||
let windowScenes = scenes.first as? UIWindowScene
|
||||
let window = windowScenes?.windows.first
|
||||
window?.overrideUserInterfaceStyle = colorScheme.uiKit
|
||||
}
|
||||
}
|
||||
|
||||
extension AppPreferences.ColorScheme {
|
||||
|
|
Loading…
Reference in a new issue