Skip to content

Commit ff979dd

Browse files
Fix Appearance (Light/Dark Mode) Issues of Course Smart Search (#3016)
refs: MBL-18169 affects: Student release note: Improved dark mode support for Smart Search.
1 parent 7cd7cb3 commit ff979dd

File tree

7 files changed

+25
-7
lines changed

7 files changed

+25
-7
lines changed

Core/Core/Contexts/Context.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
//
1818

1919
import Foundation
20+
import CoreData
2021

2122
public enum ContextType: String, Codable {
2223
case account, course, group, user, section, folder
@@ -95,3 +96,16 @@ public extension Context {
9596
return context.id.localID == id.localID
9697
}
9798
}
99+
100+
public extension Context {
101+
102+
func color(in client: NSManagedObjectContext) -> UIColor? {
103+
contextColor(in: client)?.color
104+
}
105+
106+
func contextColor(in client: NSManagedObjectContext) -> ContextColor? {
107+
client.fetch(
108+
scope: .where(#keyPath(ContextColor.canvasContextID), equals: canvasContextID)
109+
).first
110+
}
111+
}

Core/Core/Courses/SmartSearch/View/CourseSearchResultRowView.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ struct CourseSearchResultRowView: View {
8888
}
8989

9090
private var accentColor: Color {
91-
Color(uiColor: searchContext.accentColor ?? .textDarkest)
91+
searchContext.accentColor?.asColor ?? .textDarkest
9292
}
9393

9494
private var titleColor: Color {
95-
let visitedColor = searchContext.accentColor ?? .textDarkest
96-
return Color(uiColor: isVisited ? visitedColor : .textDarkest)
95+
let visitedColor: Color = searchContext.accentColor?.asColor ?? .textDarkest
96+
return isVisited ? visitedColor : .textDarkest
9797
}
9898
}

Core/Core/Courses/SmartSearch/View/CourseSmartSearchFilterEditorView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public struct CourseSmartSearchFilterEditorView: View {
126126
}
127127

128128
private var contextColor: Color {
129-
return Color(uiColor: searchContext.accentColor ?? .textDarkest)
129+
return searchContext.accentColor?.asColor ?? .textDarkest
130130
}
131131
}
132132

Core/Core/Courses/SmartSearch/View/CourseSmartSearchHelpView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public struct CourseSmartSearchHelpView: View {
110110
}
111111

112112
private var contextColor: Color {
113-
return Color(uiColor: searchContext.accentColor ?? .textDarkest)
113+
return searchContext.accentColor?.asColor ?? .textDarkest
114114
}
115115
}
116116

Core/Core/Extensions/UIColorExtensions.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
//
1818

1919
import Foundation
20+
import SwiftUI
2021
import UIKit
2122

2223
extension UIColor {
@@ -204,4 +205,6 @@ extension UIColor {
204205
}
205206
return color
206207
}
208+
209+
public var asColor: Color { Color(self) }
207210
}

Core/Core/Search/View/SearchContentContainerView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,6 @@ struct SearchContentContainerView<Attributes: SearchViewAttributes, ViewProvider
120120
}
121121

122122
private var clearButtonColor: Color {
123-
return searchContext.accentColor.flatMap({ Color(uiColor: $0) }) ?? .secondary
123+
return searchContext.accentColor?.asColor ?? .secondary
124124
}
125125
}

Student/Student/Routes.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,10 +589,11 @@ private func courseDetails(url: URLComponents, params: [String: String], userInf
589589

590590
let regularCourseDetails: () -> UIViewController = {
591591
let viewModel = CourseDetailsViewModel(context: .course(courseID), offlineModeInteractor: OfflineModeAssembly.make())
592+
let client = AppEnvironment.shared.database.viewContext
592593

593594
return CourseSmartSearchAssembly.makeHostController(
594595
courseID: courseID,
595-
color: url.contextColor,
596+
color: context.color(in: client) ?? url.contextColor,
596597
containing: CourseDetailsView(viewModel: viewModel)
597598
)
598599
}

0 commit comments

Comments
 (0)