Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [iOS] On Course "Home" tab the row height changes after a while #483 #486

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions Core/Core/Extensions/UIApplicationExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@ import Theme

public extension UIApplication {

var windows: [UIWindow]? {
let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene
return scene?.windows
}

var keyWindow: UIWindow? {
UIApplication.shared.windows.first { $0.isKeyWindow }
windows?.first { $0.isKeyWindow }
}

func endEditing(force: Bool = true) {
windows.forEach { $0.endEditing(force) }
windows?.forEach { $0.endEditing(force) }
}

class func topViewController(
Expand All @@ -36,8 +41,7 @@ public extension UIApplication {
}

var windowInsets: UIEdgeInsets {
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let window = windowScene.windows.first else {
guard let window = windows?.first else {
return .zero
}

Expand Down
2 changes: 1 addition & 1 deletion Core/Core/View/Base/SnackBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public struct SnackBarView: View {
var action: (() -> Void)?

private var safeArea: CGFloat {
UIApplication.shared.windows.first { $0.isKeyWindow }?.safeAreaInsets.bottom ?? 0
UIApplication.shared.keyWindow?.safeAreaInsets.bottom ?? 0
}

private let minHeight: CGFloat = 50
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,26 @@ public class CourseContainerViewModel: BaseCourseViewModel {
)
}

@MainActor
func getCourseStructure(courseID: String) async throws -> CourseStructure? {
if isInternetAvaliable {
return try await interactor.getCourseBlocks(courseID: courseID)
} else {
return try await interactor.getLoadedCourseBlocks(courseID: courseID)
}
}

@MainActor
func getCourseBlocks(courseID: String, withProgress: Bool = true) async {
guard let courseStart, courseStart < Date() else { return }

isShowProgress = withProgress
isShowRefresh = !withProgress
do {
let courseStructure = try await getCourseStructure(courseID: courseID)
await setDownloadsStates(courseStructure: courseStructure)
self.courseStructure = courseStructure
if isInternetAvaliable {
courseStructure = try await interactor.getCourseBlocks(courseID: courseID)
NotificationCenter.default.post(name: .getCourseDates, object: courseID)
isShowProgress = false
isShowRefresh = false
Expand All @@ -194,11 +205,8 @@ public class CourseContainerViewModel: BaseCourseViewModel {
courseStructure: courseStructure
)
}
} else {
courseStructure = try await interactor.getLoadedCourseBlocks(courseID: courseID)
}
courseVideosStructure = interactor.getCourseVideoBlocks(fullStructure: courseStructure!)
await setDownloadsStates()
isShowProgress = false
isShowRefresh = false

Expand Down Expand Up @@ -529,7 +537,7 @@ public class CourseContainerViewModel: BaseCourseViewModel {
}

@MainActor
func setDownloadsStates() async {
func setDownloadsStates(courseStructure: CourseStructure?) async {
guard let course = courseStructure else { return }
courseDownloadTasks = await manager.getDownloadTasksForCourse(course.id)
downloadableVerticals = []
Expand Down Expand Up @@ -602,7 +610,7 @@ public class CourseContainerViewModel: BaseCourseViewModel {
if case .progress = state { return }
Task(priority: .background) {
debugLog(state, "--- state ---")
await self.setDownloadsStates()
await self.setDownloadsStates(courseStructure: self.courseStructure)
}
}
.store(in: &cancellables)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ final class CourseContainerViewModelTests: XCTestCase {
coreAnalytics: CoreAnalyticsMock()
)
viewModel.courseStructure = courseStructure
await viewModel.setDownloadsStates()
await viewModel.setDownloadsStates(courseStructure: courseStructure)

await viewModel.onDownloadViewTap(
chapter: chapter,
Expand Down Expand Up @@ -607,7 +607,7 @@ final class CourseContainerViewModelTests: XCTestCase {
coreAnalytics: CoreAnalyticsMock()
)
viewModel.courseStructure = courseStructure
await viewModel.setDownloadsStates()
await viewModel.setDownloadsStates(courseStructure: courseStructure)

await viewModel.onDownloadViewTap(
chapter: chapter,
Expand Down Expand Up @@ -733,7 +733,7 @@ final class CourseContainerViewModelTests: XCTestCase {
coreAnalytics: CoreAnalyticsMock()
)
viewModel.courseStructure = courseStructure
await viewModel.setDownloadsStates()
await viewModel.setDownloadsStates(courseStructure: courseStructure)

await viewModel.onDownloadViewTap(
chapter: chapter,
Expand Down Expand Up @@ -860,7 +860,7 @@ final class CourseContainerViewModelTests: XCTestCase {
coreAnalytics: CoreAnalyticsMock()
)
viewModel.courseStructure = courseStructure
await viewModel.setDownloadsStates()
await viewModel.setDownloadsStates(courseStructure: courseStructure)

let exp = expectation(description: "Task Starting")
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
Expand Down Expand Up @@ -995,7 +995,7 @@ final class CourseContainerViewModelTests: XCTestCase {
coreAnalytics: CoreAnalyticsMock()
)
viewModel.courseStructure = courseStructure
await viewModel.setDownloadsStates()
await viewModel.setDownloadsStates(courseStructure: courseStructure)

let exp = expectation(description: "Task Starting")
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
Expand Down Expand Up @@ -1130,7 +1130,7 @@ final class CourseContainerViewModelTests: XCTestCase {
coreAnalytics: CoreAnalyticsMock()
)
viewModel.courseStructure = courseStructure
await viewModel.setDownloadsStates()
await viewModel.setDownloadsStates(courseStructure: courseStructure)

let exp = expectation(description: "Task Starting")
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
Expand Down Expand Up @@ -1286,7 +1286,7 @@ final class CourseContainerViewModelTests: XCTestCase {
coreAnalytics: CoreAnalyticsMock()
)
viewModel.courseStructure = courseStructure
await viewModel.setDownloadsStates()
await viewModel.setDownloadsStates(courseStructure: courseStructure)

let exp = expectation(description: "Task Starting")
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
Expand Down
Loading