Refactoring

This commit is contained in:
Justin Mazzocchi 2020-09-09 16:40:40 -07:00
parent a729058add
commit 9a2fae9e4c
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C
2 changed files with 10 additions and 12 deletions

View file

@ -6,7 +6,6 @@ import ViewModels
struct SecondaryNavigationView: View { struct SecondaryNavigationView: View {
@ObservedObject var viewModel: NavigationViewModel @ObservedObject var viewModel: NavigationViewModel
@EnvironmentObject var identification: Identification
@EnvironmentObject var rootViewModel: RootViewModel @EnvironmentObject var rootViewModel: RootViewModel
@Environment(\.displayScale) var displayScale: CGFloat @Environment(\.displayScale) var displayScale: CGFloat
@ -15,28 +14,28 @@ struct SecondaryNavigationView: View {
Form { Form {
Section { Section {
NavigationLink( NavigationLink(
destination: IdentitiesView(viewModel: .init(identification: identification)), destination: IdentitiesView(viewModel: .init(identification: viewModel.identification)),
label: { label: {
HStack { HStack {
KFImage(identification.identity.image, KFImage(viewModel.identification.identity.image,
options: .downsampled(dimension: 50, scaleFactor: displayScale)) options: .downsampled(dimension: 50, scaleFactor: displayScale))
VStack(alignment: .leading) { VStack(alignment: .leading) {
if identification.identity.authenticated { if viewModel.identification.identity.authenticated {
if let account = identification.identity.account { if let account = viewModel.identification.identity.account {
CustomEmojiText( CustomEmojiText(
text: account.displayName, text: account.displayName,
emoji: account.emojis, emoji: account.emojis,
textStyle: .headline) textStyle: .headline)
} }
Text(identification.identity.handle) Text(viewModel.identification.identity.handle)
.font(.subheadline) .font(.subheadline)
.foregroundColor(.secondary) .foregroundColor(.secondary)
.lineLimit(1) .lineLimit(1)
.minimumScaleFactor(0.5) .minimumScaleFactor(0.5)
} else { } else {
Text(identification.identity.handle) Text(viewModel.identification.identity.handle)
.font(.headline) .font(.headline)
if let instance = identification.identity.instance { if let instance = viewModel.identification.identity.instance {
Text(instance.uri) Text(instance.uri)
.font(.subheadline) .font(.subheadline)
.foregroundColor(.secondary) .foregroundColor(.secondary)
@ -54,7 +53,7 @@ struct SecondaryNavigationView: View {
}) })
} }
Section { Section {
NavigationLink(destination: ListsView(viewModel: .init(identification: identification))) { NavigationLink(destination: ListsView(viewModel: .init(identification: viewModel.identification))) {
Label("secondary-navigation.lists", systemImage: "scroll") Label("secondary-navigation.lists", systemImage: "scroll")
} }
} }
@ -62,7 +61,7 @@ struct SecondaryNavigationView: View {
NavigationLink( NavigationLink(
"secondary-navigation.preferences", "secondary-navigation.preferences",
destination: PreferencesView( destination: PreferencesView(
viewModel: .init(identification: identification))) viewModel: .init(identification: viewModel.identification)))
} }
} }
.navigationBarTitleDisplayMode(.inline) .navigationBarTitleDisplayMode(.inline)
@ -77,6 +76,7 @@ struct SecondaryNavigationView: View {
} }
} }
.navigationViewStyle(StackNavigationViewStyle()) .navigationViewStyle(StackNavigationViewStyle())
.environmentObject(viewModel.identification)
} }
} }
@ -86,7 +86,6 @@ import PreviewViewModels
struct SecondaryNavigationView_Previews: PreviewProvider { struct SecondaryNavigationView_Previews: PreviewProvider {
static var previews: some View { static var previews: some View {
SecondaryNavigationView(viewModel: NavigationViewModel(identification: .preview)) SecondaryNavigationView(viewModel: NavigationViewModel(identification: .preview))
.environmentObject(Identification.preview)
.environmentObject(RootViewModel.preview) .environmentObject(RootViewModel.preview)
} }
} }

View file

@ -27,7 +27,6 @@ struct TabNavigationView: View {
.environmentObject(viewModel.identification) .environmentObject(viewModel.identification)
.sheet(isPresented: $viewModel.presentingSecondaryNavigation) { .sheet(isPresented: $viewModel.presentingSecondaryNavigation) {
SecondaryNavigationView(viewModel: viewModel) SecondaryNavigationView(viewModel: viewModel)
.environmentObject(viewModel.identification)
.environmentObject(viewModel) .environmentObject(viewModel)
.environmentObject(rootViewModel) .environmentObject(rootViewModel)
} }