Skip to content

Commit

Permalink
Merge branch 'feature/change-navigation-controller-to-swiftui' of htt…
Browse files Browse the repository at this point in the history
…ps://github.com/raccoongang/educationx-app-ios into feature/change-navigation-controller-to-swiftui
  • Loading branch information
IvanStepanok committed Aug 10, 2023
2 parents 2f87c93 + d53e988 commit b79aa7d
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 58 deletions.
54 changes: 29 additions & 25 deletions Discovery/Discovery/Presentation/DiscoveryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,28 @@ public struct DiscoveryView: View {
.padding(.bottom, 20)
Spacer()
}.padding(.leading, 10)
ForEach(Array(viewModel.courses.enumerated()),
id: \.offset) { index, course in
CourseCellView(model: course,
type: .discovery,
index: index,
cellsCount: viewModel.courses.count)
.padding(.horizontal, 24)
.onAppear {
Task {
await viewModel.getDiscoveryCourses(index: index)
ForEach(Array(viewModel.courses.enumerated()), id: \.offset) { index, course in
CourseCellView(
model: course,
type: .discovery,
index: index,
cellsCount: viewModel.courses.count
).padding(.horizontal, 24)
.onAppear {
Task {
await viewModel.getDiscoveryCourses(index: index)
}
}
.onTapGesture {
viewModel.discoveryCourseClicked(
courseID: course.courseID,
courseName: course.name
)
router.showCourseDetais(
courseID: course.courseID,
title: course.name
)
}
}
.onTapGesture {
viewModel.discoveryCourseClicked(courseID: course.courseID, courseName: course.name)
router.showCourseDetais(
courseID: course.courseID,
title: course.name
)
}
}

// MARK: - ProgressBar
Expand All @@ -116,13 +119,14 @@ public struct DiscoveryView: View {
}

// MARK: - Offline mode SnackBar
OfflineSnackBarView(connectivity: viewModel.connectivity,
reloadAction: {
viewModel.courses = []
viewModel.totalPages = 1
viewModel.nextPage = 1
await viewModel.discovery(page: 1, withProgress: isIOS14)
})
OfflineSnackBarView(
connectivity: viewModel.connectivity,
reloadAction: {
viewModel.courses = []
viewModel.totalPages = 1
viewModel.nextPage = 1
await viewModel.discovery(page: 1, withProgress: isIOS14)
})

// MARK: - Error Alert
if viewModel.showError {
Expand Down
8 changes: 5 additions & 3 deletions Discovery/Discovery/Presentation/DiscoveryViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ public class DiscoveryViewModel: ObservableObject {
private let interactor: DiscoveryInteractorProtocol
private let analytics: DiscoveryAnalytics

public init(interactor: DiscoveryInteractorProtocol,
connectivity: ConnectivityProtocol,
analytics: DiscoveryAnalytics) {
public init(
interactor: DiscoveryInteractorProtocol,
connectivity: ConnectivityProtocol,
analytics: DiscoveryAnalytics
) {
self.interactor = interactor
self.connectivity = connectivity
self.analytics = analytics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@
</TestAction>
<LaunchAction
buildConfiguration = "DebugStage"
selectedDebuggerIdentifier = ""
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
56 changes: 28 additions & 28 deletions OpenEdX/View/MainScreenView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,14 @@ struct MainScreenView: View {

@State private var selection: MainTab = .discovery

func titleBar() -> String {
switch selection {
case .discovery:
return DiscoveryLocalization.title
case .dashboard:
return DashboardLocalization.title
case .programs:
return CoreLocalization.Mainscreen.programs
case .profile:
return ProfileLocalization.title
}
}

enum MainTab {
case discovery
case dashboard
case programs
case profile
}

let analytics = Container.shared.resolve(MainScreenAnalytics.self)!
private let analytics = Container.shared.resolve(MainScreenAnalytics.self)!

init() {
UINavigationBar.appearance().isTranslucent = false
Expand Down Expand Up @@ -68,7 +55,7 @@ struct MainScreenView: View {
Text(CoreLocalization.Mainscreen.discovery)
}
.tag(MainTab.discovery)

VStack {
DashboardView(
viewModel: Container.shared.resolve(DashboardViewModel.self)!,
Expand All @@ -89,7 +76,7 @@ struct MainScreenView: View {
Text(CoreLocalization.Mainscreen.programs)
}
.tag(MainTab.programs)

VStack {
ProfileView(
viewModel: Container.shared.resolve(ProfileViewModel.self)!
Expand All @@ -104,18 +91,31 @@ struct MainScreenView: View {
.navigationBarHidden(selection == .profile)
.navigationBarBackButtonHidden(false)
.navigationTitle(titleBar())
.onChange(of: selection, perform: { selection in
switch selection {
case .discovery:
analytics.mainDiscoveryTabClicked()
case .dashboard:
analytics.mainDashboardTabClicked()
case .programs:
analytics.mainProgramsTabClicked()
case .profile:
analytics.mainProfileTabClicked()
}
})
.onChange(of: selection, perform: { selection in
switch selection {
case .discovery:
analytics.mainDiscoveryTabClicked()
case .dashboard:
analytics.mainDashboardTabClicked()
case .programs:
analytics.mainProgramsTabClicked()
case .profile:
analytics.mainProfileTabClicked()
}
})
}

private func titleBar() -> String {
switch selection {
case .discovery:
return DiscoveryLocalization.title
case .dashboard:
return DashboardLocalization.title
case .programs:
return CoreLocalization.Mainscreen.programs
case .profile:
return ProfileLocalization.title
}
}

struct MainScreenView_Previews: PreviewProvider {
Expand Down

0 comments on commit b79aa7d

Please sign in to comment.