Skip to content

Commit

Permalink
[Zen mode] Hide navigation column when entering Zen mode. (Requires n…
Browse files Browse the repository at this point in the history
…ew navigation structures on iOS 16)
  • Loading branch information
honganhkhoa committed Feb 25, 2024
1 parent daf3295 commit d28f793
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 60 deletions.
16 changes: 8 additions & 8 deletions Surround.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,7 @@
ENABLE_PREVIEWS = YES;
GCC_PREPROCESSOR_DEFINITIONS = "";
INFOPLIST_FILE = Surround/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -1545,7 +1545,7 @@
ENABLE_PREVIEWS = YES;
GCC_PREPROCESSOR_DEFINITIONS = "";
INFOPLIST_FILE = Surround/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -1649,7 +1649,7 @@
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 269H7P4WSN;
INFOPLIST_FILE = SurroundNotificationContent/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -1671,7 +1671,7 @@
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 269H7P4WSN;
INFOPLIST_FILE = SurroundNotificationContent/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -1696,7 +1696,7 @@
DEVELOPMENT_TEAM = 269H7P4WSN;
GCC_PREPROCESSOR_DEFINITIONS = "";
INFOPLIST_FILE = SurroundWidgets/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -1722,7 +1722,7 @@
DEVELOPMENT_TEAM = 269H7P4WSN;
GCC_PREPROCESSOR_DEFINITIONS = "";
INFOPLIST_FILE = SurroundWidgets/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -1745,7 +1745,7 @@
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 269H7P4WSN;
INFOPLIST_FILE = SurroundNotificationService/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -1767,7 +1767,7 @@
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 269H7P4WSN;
INFOPLIST_FILE = SurroundNotificationService/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
2 changes: 2 additions & 0 deletions Surround/Services/NavigationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class NavigationService: ObservableObject {
@Published var home = HomeViewParameters()
@Published var main = MainViewParameters()
@Published var publicGames = PublicGamesViewParameter()

@Published var columnVisibility = NavigationSplitViewVisibility.automatic

static func instance(forSceneWithID sceneID: String) -> NavigationService {
if let result = instances[sceneID] {
Expand Down
25 changes: 22 additions & 3 deletions Surround/Views/GameDetail/GameDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ struct GameDetailView: View {
@State var needsToHideActiveGameCarousel = false
@State var zenMode = false
@State var analyzeMode = false

@State var columnVisibilityBeforeZenMode = NavigationSplitViewVisibility.automatic

@ObservedObject var settings = userDefaults

Expand Down Expand Up @@ -91,6 +93,21 @@ struct GameDetailView: View {
}
}

func enterZenMode() {
withAnimation {
columnVisibilityBeforeZenMode = nav.columnVisibility
zenMode = true
nav.columnVisibility = .detailOnly
}
}

func exitZenMode() {
withAnimation {
zenMode = false
nav.columnVisibility = columnVisibilityBeforeZenMode
}
}

var compactBody: some View {
GeometryReader { geometry -> AnyView in
// print("Geometry \(geometry.size)")
Expand All @@ -114,6 +131,7 @@ struct GameDetailView: View {
reducedPlayerInfoVerticalPadding: reducedPlayerInfoVerticalPadding,
goToNextGame: goToNextGame,
zenMode: $zenMode,
exitZenMode: self.exitZenMode,
attachedKeyboardVisible: self.attachedKeyboardVisible,
analyzeMode: self.$analyzeMode,
shouldHideActiveGamesCarousel: self.$needsToHideActiveGameCarousel
Expand Down Expand Up @@ -142,6 +160,7 @@ struct GameDetailView: View {
goToNextGame: goToNextGame,
horizontal: horizontal,
zenMode: $zenMode,
exitZenMode: self.exitZenMode,
attachedKeyboardVisible: self.attachedKeyboardVisible,
analyzeMode: self.$analyzeMode
)
Expand Down Expand Up @@ -253,7 +272,7 @@ struct GameDetailView: View {
if !navigationBarHidden {
HStack {
if !analyzeMode {
Button(action: { withAnimation { zenMode = true } }) {
Button(action: enterZenMode) {
Label("Zen mode", systemImage: "arrow.up.backward.and.arrow.down.forward")
}
}
Expand All @@ -262,7 +281,7 @@ struct GameDetailView: View {
}
}
} else if zenMode {
Button(action: { withAnimation { zenMode = false } }) {
Button(action: exitZenMode) {
Label("Exit Zen mode", systemImage: "arrow.down.forward.and.arrow.up.backward")
}
}
Expand Down Expand Up @@ -300,7 +319,7 @@ struct GameDetailView: View {
.disabled(!shouldShowActiveGamesCarousel)
}
ToolbarItem(placement: .navigationBarTrailing) {
Button(action: { withAnimation { zenMode = true } }) {
Button(action: enterZenMode) {
Label("Zen mode", systemImage: "arrow.up.backward.and.arrow.down.forward")
}
.disabled(analyzeMode)
Expand Down
3 changes: 2 additions & 1 deletion Surround/Views/GameDetail/SingleGameView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct SingleGameView: View {
var goToNextGame: (() -> ())?
var horizontal = false
@Binding var zenMode: Bool
var exitZenMode: (() -> ())?

@EnvironmentObject var ogs: OGSService
@Environment(\.colorScheme) private var colorScheme
Expand Down Expand Up @@ -493,7 +494,7 @@ struct SingleGameView: View {
}
}
if !compact || !iOS15 {
Button(action: { withAnimation { zenMode = false } }) {
Button(action: { if let exitZenMode { exitZenMode() } }) {
Label("Exit Zen mode", systemImage: "arrow.down.forward.and.arrow.up.backward")
.labelStyle(IconOnlyLabelStyle())
}
Expand Down
26 changes: 6 additions & 20 deletions Surround/Views/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ struct HomeView: View {
@EnvironmentObject var ogs: OGSService
@EnvironmentObject var nav: NavigationService

@State var showRegisterWebView = false
@State var gameDetailCancellable: AnyCancellable?

@State var displayMode: GameCell.CellDisplayMode
Expand Down Expand Up @@ -240,26 +239,13 @@ struct HomeView: View {
} else {
WelcomeView()
}
NavigationLink(
destination: GameDetailView(currentGame: nav.home.activeGame),
isActive: Binding(
get: { nav.home.activeGame != nil },
set: { if !$0 { nav.home.activeGame = nil } }
)) {
EmptyView()
}
NavigationLink(
destination: OGSBrowserView(initialURL: URL(string: "\(OGSService.ogsRoot)/register")!),
isActive: $showRegisterWebView
) {
EmptyView()
}
// Workaround for an issue on iOS 14.5 where the NavigationLink pops out by itself.
// https://developer.apple.com/forums/thread/677333#672042022
NavigationLink(destination: EmptyView()) {
EmptyView()
}
}
.navigationDestination(isPresented: Binding(
get: { nav.home.activeGame != nil },
set: { if !$0 { nav.home.activeGame = nil } }
), destination: {
GameDetailView(currentGame: nav.home.activeGame)
})
.onAppear {
if nav.home.ogsIdToOpen != -1 {
DispatchQueue.main.async {
Expand Down
43 changes: 26 additions & 17 deletions Surround/Views/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,27 +94,36 @@ struct MainView: View {
set: { if let rootView = $0 { nav.main.rootView = rootView } }
)
return ZStack(alignment: .top) {
NavigationView {
Group {
if compactSizeClass {
nav.main.rootView.view
.modifier(RootViewSwitchingMenu())
NavigationStack {
nav.main.rootView.view
.modifier(RootViewSwitchingMenu())
}
} else {
List(selection: navigationCurrentView) {
RootView.home.navigationLink(currentView: navigationCurrentView)
RootView.publicGames.navigationLink(currentView: navigationCurrentView)
if ogs.privateMessagesActivePeerIds.count > 0 {
RootView.privateMessages.navigationLink(currentView: navigationCurrentView)
NavigationSplitView(columnVisibility: Binding(
get: { nav.columnVisibility },
set: { nav.columnVisibility = $0 })) {
List(selection: navigationCurrentView) {
RootView.home.navigationLink(currentView: navigationCurrentView)
RootView.publicGames.navigationLink(currentView: navigationCurrentView)
if ogs.privateMessagesActivePeerIds.count > 0 {
RootView.privateMessages.navigationLink(currentView: navigationCurrentView)
}
Divider()
RootView.settings.navigationLink(currentView: navigationCurrentView)
RootView.about.navigationLink(currentView: navigationCurrentView)
Divider()
RootView.browser.navigationLink(currentView: navigationCurrentView)
RootView.forums.navigationLink(currentView: navigationCurrentView)
}
.listStyle(SidebarListStyle())
.navigationTitle("Surround")
} detail: {
NavigationStack {
nav.main.rootView.view
}
Divider()
RootView.settings.navigationLink(currentView: navigationCurrentView)
RootView.about.navigationLink(currentView: navigationCurrentView)
Divider()
RootView.browser.navigationLink(currentView: navigationCurrentView)
RootView.forums.navigationLink(currentView: navigationCurrentView)
}
.listStyle(SidebarListStyle())
.navigationTitle("Surround")
nav.main.rootView.view
}
}
.fullScreenCover(isPresented: Binding(
Expand Down
2 changes: 1 addition & 1 deletion Surround/Views/NewGameView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ struct CustomGameForm: View {
.leadingAlignedInScrollView()
Spacer().frame(height: 10)
Divider()
NavigationLink(destination: UserSelectionView(user: $opponent, isPresented: $selectingOpponent), isActive: $selectingOpponent) {
NavigationLink(destination: UserSelectionView(user: $opponent)) {
HStack {
if let opponent = opponent, let opponentIconURL = opponent.iconURL(ofSize: 64) {
URLImage(url: opponentIconURL) { $0.resizable() }
Expand Down
14 changes: 6 additions & 8 deletions Surround/Views/PublicGamesList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,14 @@ struct PublicGamesList: View {
}
}
.background(Color(colorScheme == .dark ? UIColor.systemGray5 : UIColor.white))
NavigationLink(
destination: GameDetailView(currentGame: nav.publicGames.activeGame),
isActive: Binding(
get: { nav.publicGames.activeGame != nil },
set: { if !$0 { nav.publicGames.activeGame = nil } }
)) {
EmptyView()
}
}
}
.navigationDestination(isPresented: Binding(
get: { nav.publicGames.activeGame != nil },
set: { if !$0 { nav.publicGames.activeGame = nil } }
), destination: {
GameDetailView(currentGame: nav.publicGames.activeGame)
})
.onAppear {
// print("Appeared \(self)")
ogs.fetchPublicGames()
Expand Down
4 changes: 2 additions & 2 deletions Surround/Views/UserSelectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ struct SearchBar: UIViewRepresentable {

struct UserSelectionView: View {
@EnvironmentObject var ogs: OGSService
@Environment(\.dismiss) private var dismiss

var user: Binding<OGSUser?> = .constant(nil)
var isPresented: Binding<Bool> = .constant(true)
@State var searchText = ""
@State var searchResultByKeyword = [String: [OGSUser]]()
@State var searchRequestByKeyword = [String: AnyCancellable]()

func selectUser(_ user: OGSUser) {
if user.id != ogs.user?.id {
self.user.wrappedValue = user
self.isPresented.wrappedValue = false
dismiss()
}
}

Expand Down

0 comments on commit d28f793

Please sign in to comment.