Skip to content

Commit

Permalink
fix: two TabBars in course dashboard screen for iOS 15 (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
forgotvas authored Jul 31, 2024
1 parent 5f92db6 commit 6f9ab22
Show file tree
Hide file tree
Showing 36 changed files with 57 additions and 55 deletions.
3 changes: 2 additions & 1 deletion Core/Core/Data/Model/Data_UserProfile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@ public extension DataLayer {
// MARK: - AccountPrivacy
public enum AccountPrivacy: String, Codable {
case privateAccess = "private"
case privateAccessBig = "PRIVATE"
case allUsers = "all_users"
case allUsersBig = "ALL_USERS"

public var boolValue: Bool {
switch self {
case .privateAccess:
case .privateAccess, .privateAccessBig:
return false
case .allUsers, .allUsersBig:
return true
Expand Down
18 changes: 10 additions & 8 deletions Core/Core/Extensions/ViewExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,18 @@ public extension View {
}
}

func hideNavigationBar() -> some View {
func hideNavigationBar(_ isHidden: Bool = true) -> some View {
if #available(iOS 16.0, *) {
return self.navigationBarHidden(true)
return self.navigationBarHidden(isHidden)
} else {
return self.introspect(
.navigationView(style: .stack),
on: .iOS(.v15...),
scope: .ancestor) {
$0.isNavigationBarHidden = true
}
return self
.navigationBarHidden(isHidden)
.introspect(
.navigationView(style: .stack),
on: .iOS(.v15...),
scope: .ancestor) {
$0.isNavigationBarHidden = isHidden
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion Core/Core/View/Base/VideoDownloadQualityView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public struct VideoDownloadQualityView: View {
}
}
}
.navigationBarHidden(!isModal)
.hideNavigationBar(!isModal)
.navigationBarBackButtonHidden(!isModal)
.navigationTitle(CoreLocalization.Settings.videoDownloadQualityTitle)
.ignoresSafeArea(.all, edges: .horizontal)
Expand Down
2 changes: 1 addition & 1 deletion Core/Core/View/Base/WebBrowser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public struct WebBrowser: View {
}
}
.navigationBarTitle(Text(""))
.navigationBarHidden(true)
.hideNavigationBar(true)
.ignoresSafeArea()
}
}
Expand Down
11 changes: 7 additions & 4 deletions Course/Course/Presentation/Container/CourseContainerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public struct CourseContainerView: View {
ZStack(alignment: .top) {
content
}
.navigationBarHidden(true)
.hideNavigationBar(true)
.navigationBarBackButtonHidden(true)
.navigationTitle(title)
.onChange(of: viewModel.selection, perform: didSelect)
Expand Down Expand Up @@ -237,6 +237,7 @@ public struct CourseContainerView: View {
viewHeight: $viewHeight,
dateTabIndex: CourseTab.dates.rawValue
)
.padding(.bottom, 1)
.tabItem {
tab.image
Text(tab.title)
Expand All @@ -255,6 +256,7 @@ public struct CourseContainerView: View {
viewHeight: $viewHeight,
dateTabIndex: CourseTab.dates.rawValue
)
.padding(.bottom, 1)
.tabItem {
tab.image
Text(tab.title)
Expand All @@ -271,6 +273,7 @@ public struct CourseContainerView: View {
shouldShowUpgradeButton: $viewModel.shouldShowUpgradeButton,
shouldHideMenuBar: $viewModel.shouldHideMenuBar
)
.padding(.bottom, 1)
.tabItem {
tab.image
Text(tab.title)
Expand All @@ -289,6 +292,7 @@ public struct CourseContainerView: View {
shouldShowUpgradeButton: $viewModel.shouldShowUpgradeButton,
shouldHideMenuBar: $viewModel.shouldHideMenuBar
)
.padding(.bottom, 1)
.tabItem {
tab.image
Text(tab.title)
Expand All @@ -305,6 +309,7 @@ public struct CourseContainerView: View {
shouldShowUpgradeButton: $viewModel.shouldShowUpgradeButton,
shouldHideMenuBar: $viewModel.shouldHideMenuBar
)
.padding(.bottom, 1)
.tabItem {
tab.image
Text(tab.title)
Expand All @@ -320,9 +325,7 @@ public struct CourseContainerView: View {
.introspect(.scrollView, on: .iOS(.v16...), customize: { tabView in
tabView.isScrollEnabled = false
})
.introspect(.viewController, on: .iOS(.v15), customize: { controller in
controller.navigationController?.setNavigationBarHidden(true, animated: false)
})
.accentColor(Theme.Colors.accentXColor)
.onFirstAppear {
Task {
await viewModel.tryToRefreshCookies()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,13 @@ public class CourseContainerViewModel: BaseCourseViewModel {

@MainActor
func updateMenuBarVisibility() {
shouldHideMenuBar =
courseStructure == nil ||
courseStructure?.coursewareAccessDetails?.coursewareAccess?.hasAccess == false
if #available(iOS 16.0, *) {
shouldHideMenuBar =
courseStructure == nil ||
courseStructure?.coursewareAccessDetails?.coursewareAccess?.hasAccess == false
} else {
shouldHideMenuBar = true
}
}

@MainActor
Expand Down
1 change: 1 addition & 0 deletions Course/Course/Presentation/Dates/CourseDatesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public struct CourseDatesView: View {
.padding(.top, 200)
.padding(.horizontal)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
} else if let courseDates = viewModel.courseDates, !courseDates.courseDateBlocks.isEmpty {
CourseDateListView(
viewModel: viewModel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public struct HandoutsUpdatesDetailView: View {
}
}
}
.navigationBarHidden(false)
.hideNavigationBar(false)
.navigationBarBackButtonHidden(false)
.navigationTitle(title)
.onChange(of: colorSchemeNative) { _ in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public struct CourseVerticalView: View {
}
}
}
.navigationBarHidden(false)
.hideNavigationBar(false)
.navigationBarBackButtonHidden(false)
.navigationTitle(title)
.background(
Expand Down
2 changes: 1 addition & 1 deletion Course/Course/Presentation/Unit/CourseUnitView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public struct CourseUnitView: View {
showDiscussion = viewModel.selectedLesson().type == .discussion
}
}
.navigationBarHidden(true)
.hideNavigationBar(true)
.navigationBarBackButtonHidden(true)
.navigationTitle("")
.background(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ public struct NotAvailableOnMobileView: View {
}
.padding(24)
}
.navigationBarHidden(false)
.hideNavigationBar(false)
}
}
2 changes: 1 addition & 1 deletion Dashboard/Dashboard/Presentation/AllCoursesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public struct AllCoursesView: View {
.ignoresSafeArea()
)
.navigationBarBackButtonHidden(true)
.navigationBarHidden(true)
.hideNavigationBar(true)
.navigationTitle(DashboardLocalization.Learn.allCourses)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public struct PrimaryCourseDashboardView<ProgramView: View>: View {
.ignoresSafeArea()
)
.navigationBarBackButtonHidden(true)
.navigationBarHidden(true)
.hideNavigationBar(true)
.navigationTitle(DashboardLocalization.title)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public struct CourseDetailsView: View {
}
}
}.padding(.top, 8)
.navigationBarHidden(false)
.hideNavigationBar(false)
.navigationBarBackButtonHidden(false)
.navigationTitle(DiscoveryLocalization.Details.title)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public struct DiscoveryView: View {
}
}
}
.navigationBarHidden(sourceScreen != .startup)
.hideNavigationBar(sourceScreen != .startup)
.onFirstAppear {
if !(searchQuery.isEmpty) {
router.showDiscoverySearch(searchQuery: searchQuery)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public struct SearchView: View {
}
}
.navigationBarBackButtonHidden(true)
.navigationBarHidden(true)
.hideNavigationBar(true)
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now()) {
withAnimation(.easeIn(duration: 0.3)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public struct DiscoveryWebview: View {
}
}
}
.navigationBarHidden(viewModel.sourceScreen == .default && discoveryType == .discovery)
.hideNavigationBar(viewModel.sourceScreen == .default && discoveryType == .discovery)
.navigationTitle(CoreLocalization.Mainscreen.discovery)
.background(Theme.Colors.background.ignoresSafeArea())
.onFirstAppear {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public struct ProgramWebviewView: View {
}
}
}
.navigationBarHidden(viewType == .program)
.hideNavigationBar(viewType == .program)
.navigationTitle(CoreLocalization.Mainscreen.programs)
.background(Theme.Colors.background.ignoresSafeArea())
.animation(.default, value: viewModel.showError)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public struct ResponsesView: View {
}
}
.ignoresSafeArea(.all, edges: .horizontal)
.navigationBarHidden(false)
.hideNavigationBar(false)
.navigationBarBackButtonHidden(true)
.navigationTitle(title)
.toolbar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public struct ThreadView: View {
}
}
.ignoresSafeArea(.all, edges: .horizontal)
.navigationBarHidden(false)
.hideNavigationBar(false)
.navigationBarBackButtonHidden(true)
.navigationTitle(title)
.toolbar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public struct CreateNewThreadView: View {
}
}.padding(.top, 8)
}
.navigationBarHidden(false)
.hideNavigationBar(false)
.navigationBarBackButtonHidden(false)
.navigationTitle(DiscussionLocalization.CreateThread.newPost)
.background(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public struct DiscussionSearchTopicsView: View {
.background(Theme.Colors.background.ignoresSafeArea())
.avoidKeyboard(dismissKeyboardByTap: true)
.navigationBarBackButtonHidden(true)
.navigationBarHidden(true)
.hideNavigationBar(true)
.navigationTitle(DiscussionLocalization.search)
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now()) {
Expand All @@ -158,9 +158,6 @@ public struct DiscussionSearchTopicsView: View {
}
}
}
.introspect(.viewController, on: .iOS(.v15)) { controller in
controller.navigationController?.setNavigationBarHidden(true, animated: false)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ public struct DiscussionTopicsView: View {
await viewModel.getTopics(courseID: courseID)
}
}
.navigationBarHidden(false)
.navigationBarBackButtonHidden(false)
.navigationTitle(viewModel.title)
.background(
Expand Down
2 changes: 1 addition & 1 deletion Discussion/Discussion/Presentation/Posts/PostsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public struct PostsView: View {
)
}
}
.navigationBarHidden(!showTopMenu)
.hideNavigationBar(!showTopMenu)
.navigationBarBackButtonHidden(!showTopMenu)
.navigationTitle(title)
.background(
Expand Down
7 changes: 1 addition & 6 deletions OpenEdX/View/MainScreenView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ struct MainScreenView: View {
.tag(MainTab.profile)
.accessibilityIdentifier("profile_tabitem")
}
.navigationBarHidden(viewModel.selection == .dashboard)
.hideNavigationBar(viewModel.selection == .dashboard)
.navigationBarBackButtonHidden(viewModel.selection == .dashboard)
.navigationTitle(titleBar())
.toolbar {
Expand Down Expand Up @@ -194,11 +194,6 @@ struct MainScreenView: View {
}
}
.accentColor(Theme.Colors.accentXColor)
.introspect(.viewController, on: .iOS(.v15)) { controller in
if viewModel.selection != .profile {
controller.navigationController?.setNavigationBarHidden(true, animated: false)
}
}
}

@ViewBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public struct CoursesToSyncView: View {
.roundedBackground(Theme.Colors.background)
.ignoresSafeArea(.all, edges: .bottom)
}
.navigationBarHidden(true)
.hideNavigationBar(true)
.navigationBarBackButtonHidden(true)

if viewModel.showError {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public struct DatesAndCalendarView: View {
.roundedBackground(Theme.Colors.background)
.ignoresSafeArea(.all, edges: .bottom)
}
.navigationBarHidden(true)
.hideNavigationBar(true)
.navigationBarBackButtonHidden(true)

// Error Alert if needed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public struct SyncCalendarOptionsView: View {
.roundedBackground(Theme.Colors.background)
.ignoresSafeArea(.all, edges: .bottom)
}
.navigationBarHidden(true)
.hideNavigationBar(true)
.navigationBarBackButtonHidden(true)

// Error Alert if needed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public struct DeleteAccountView: View {
maxHeight: .infinity,
alignment: .top)
.padding(.top, 8)
.navigationBarHidden(false)
.hideNavigationBar(false)
.navigationBarBackButtonHidden(true)
.navigationTitle(ProfileLocalization.DeleteAccount.title)
.toolbar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public struct EditProfileView: View {
.accessibilityIdentifier("progress_bar")
}
}
.navigationBarHidden(false)
.hideNavigationBar(false)
.navigationBarBackButtonHidden(true)
.navigationTitle(ProfileLocalization.editProfile)
.toolbar {
Expand Down
2 changes: 1 addition & 1 deletion Profile/Profile/Presentation/Profile/ProfileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public struct ProfileView: View {
)
.accessibilityAction {}
.padding(.top, 8)
.navigationBarHidden(false)
.hideNavigationBar(false)
.navigationBarBackButtonHidden(false)
.navigationTitle(ProfileLocalization.title)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public struct UserProfileView: View {
.frameLimit(width: proxy.size.width)
}
.padding(.top, 8)
.navigationBarHidden(false)
.hideNavigationBar(false)
.navigationBarBackButtonHidden(false)

// MARK: - Error Alert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public struct ManageAccountView: View {
.padding(.horizontal, isHorizontal ? 24 : 0)
.roundedBackground(Theme.Colors.background)
}
.navigationBarHidden(true)
.hideNavigationBar(true)
.navigationBarBackButtonHidden(true)
.navigationTitle(ProfileLocalization.manageAccount)

Expand Down
Loading

0 comments on commit 6f9ab22

Please sign in to comment.