Skip to content

Commit

Permalink
Merge pull request #111 from ldakhoa/fix/list_navigation_ios_18
Browse files Browse the repository at this point in the history
Fix cannot navigate to gist list in iOS 18
  • Loading branch information
ldakhoa authored Jul 27, 2024
2 parents 8b0dd4d + ca7b43a commit de36596
Showing 1 changed file with 96 additions and 99 deletions.
195 changes: 96 additions & 99 deletions Packages/Sources/Home/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,35 @@ import SwiftUI
import DesignSystem
import Environment
import AppAccount
import Gist

public struct HomeView: View {
@EnvironmentObject private var currentAccount: CurrentAccount
@EnvironmentObject private var appAccountsManager: AppAccountsManager
@EnvironmentObject private var routerPath: RouterPath
@StateObject private var viewModel: HomeViewModel = HomeViewModel()
@State private var selectedItem: Item? =
UIDevice.current.userInterfaceIdiom == .pad ? .gists : nil

private enum Item: String, CaseIterable, Identifiable {
case gists = "Gists"
case starred = "Starred"
case forked = "Forked"

var id: Self { self }

@ViewBuilder func image() -> some View {
switch self {
case .gists:
Image(systemName: "doc.text.magnifyingglass")
.font(.system(size: 14))
.fontWeight(.medium)
.frame(width: 32, height: 32)
.foregroundColor(.white)
.background(Colors.buttonForeground.color)
.cornerRadius(6.0)

case .starred:
Image(systemName: "star")
.font(.system(size: 14))
.fontWeight(.medium)
.frame(width: 32, height: 32)
.foregroundColor(.white)
.background(Colors.Palette.Yellow.yellow2.dynamicColor.color)
.cornerRadius(6.0)

case .forked:
Image(uiImage: UIImage(named: "fork")!)
.renderingMode(.template)
.frame(width: 9, height: 9)
.foregroundColor(.white)
.padding(12)
.background(Colors.Palette.Purple.purple3.dynamicColor.color)
.cornerRadius(6.0)
}
}
}

public init() {}

public var body: some View {
NavigationSplitView {
List(selection: $selectedItem) {
Section {
ForEach(Item.allCases) { item in
rowView(item)
}
List {
Section {
buttonRowView(
title: "Gists",
image: "doc.text.magnifyingglass",
imageBackground: Colors.buttonForeground.color
) {
routerPath.navigate(to: .gistLists(mode: .currentUserGists(filter: .all)))
}

buttonRowView(
title: "Starred",
image: "star",
imageBackground: Colors.Palette.Yellow.yellow2.dynamicColor.color
) {
routerPath.navigate(to: .gistLists(mode: .userStarredGists(userName: currentAccount.user?.login ?? "ghost")))
}

forkButtonRowView

// Temporary turn it off
// buttonRowView(
Expand All @@ -69,10 +40,10 @@ public struct HomeView: View {
// ) {
// routerPath.navigate(to: .draftGistLists)
// }
} header: {
Text("My Gist")
.headerProminence(.increased)
}
} header: {
Text("My Gist")
.headerProminence(.increased)
}

// Temporary turn it off
// Section {
Expand All @@ -82,43 +53,29 @@ public struct HomeView: View {
// .headerProminence(.increased)
// }

switch viewModel.contentState {
case .loading:
HStack {
Spacer()
ProgressView()
.tint(Colors.accent.color)
Spacer()
}
.listRowBackground(Color.clear)
case .error:
ErrorView(title: "Cannot Connect", message: "Something went wrong. Please try again.") {
Task {
await viewModel.refresh(from: currentAccount.user?.login)
}
}
case .content:
if !viewModel.recentComments.isEmpty {
Section {
RecentActivitiesSectionView(recentComments: viewModel.recentComments)
} header: {
Text("Recent Activities")
.headerProminence(.increased)
}
switch viewModel.contentState {
case .loading:
HStack {
Spacer()
ProgressView()
.tint(Colors.accent.color)
Spacer()
}
.listRowBackground(Color.clear)
case .error:
ErrorView(title: "Cannot Connect", message: "Something went wrong. Please try again.") {
Task {
await viewModel.refresh(from: currentAccount.user?.login)
}
}
}
.navigationTitle("Home")
.navigationBarTitleDisplayMode(.large)
} detail: {
if let selectedItem {
switch selectedItem {
case .gists:
GistListsView(listsMode: .currentUserGists(filter: .all))
case .starred:
GistListsView(listsMode: .userStarredGists(userName: currentAccount.user?.login ?? "ghost"))
case .forked:
GistListsView(listsMode: .userForkedGists(userName: currentAccount.user?.login ?? "ghost"))
case .content:
if !viewModel.recentComments.isEmpty {
Section {
RecentActivitiesSectionView(recentComments: viewModel.recentComments)
} header: {
Text("Recent Activities")
.headerProminence(.increased)
}
}
}
}
Expand All @@ -130,20 +87,60 @@ public struct HomeView: View {
await viewModel.fetchRecentComments(from: currentAccount.user?.login)
}
}
.navigationTitle("Home")
.navigationBarTitleDisplayMode(.large)
}

@ViewBuilder
private func rowView(_ item: Item) -> some View {
let textColor = UIDevice.current.userInterfaceIdiom == .pad && item == selectedItem ?
Color.white : Colors.neutralEmphasisPlus.color
HStack {
Label(title: {
Text(item.rawValue)
.foregroundColor(textColor)
}, icon: item.image)
Spacer()
RightChevronRowImage()
}
.frame(height: UIDevice.current.userInterfaceIdiom == .pad ? 32 : 37)
private var forkButtonRowView: some View {
Button(action: {
routerPath.navigate(to: .gistLists(mode: .userForkedGists(userName: currentAccount.user?.login ?? "ghost")))
}, label: {
HStack {
Label {
Text("Forked")
.foregroundColor(Colors.neutralEmphasisPlus.color)
} icon: {
Image(uiImage: UIImage(named: "fork")!)
.renderingMode(.template)
.frame(width: 9, height: 9)
.foregroundColor(.white)
.padding(12)
.background(Colors.Palette.Purple.purple3.dynamicColor.color)
.cornerRadius(6.0)
}
Spacer()
RightChevronRowImage()
}
})
.frame(height: 37)
}

@ViewBuilder
private func buttonRowView(
title: String,
image: String,
imageBackground: Color,
action: @escaping () -> Void
) -> some View {
Button(action: action, label: {
HStack {
Label {
Text(title)
.foregroundColor(Colors.neutralEmphasisPlus.color)
} icon: {
Image(systemName: image)
.font(.system(size: 14))
.fontWeight(.medium)
.frame(width: 32, height: 32)
.foregroundColor(.white)
.background(imageBackground)
.cornerRadius(6.0)
}
Spacer()
RightChevronRowImage()
}
})
.frame(height: 37)
}
}

0 comments on commit de36596

Please sign in to comment.