-
Notifications
You must be signed in to change notification settings - Fork 121
[MBL-19529][S] Learner Dashboard - Widget Settings Save #3931
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
Merged
vargaat
merged 38 commits into
master
from
feature/MBL-19529-Learner-Dashboard-settings-save
Mar 16, 2026
Merged
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
d75edfe
Create UI
petkybenedek 7323f78
Merge branch 'master' into feature/MBL-19529-Dashboard-simple-edit-mode
petkybenedek aeb8276
Merge master
petkybenedek 3713440
Correct animation
petkybenedek 35fdfc9
Correct logic
petkybenedek bffad74
Correct tests and claude findings
petkybenedek eb5320a
Requested changes
petkybenedek eeb566e
Color selector corrections
petkybenedek 52aac49
Merge branch 'master' into feature/MBL-19529-Dashboard-simple-edit-mode
petkybenedek 2336355
Remove no longer set variable tests.
vargaat 4742afb
Remove unnecessary test
petkybenedek 3e2bca1
Merge branch 'feature/MBL-19529-Dashboard-simple-edit-mode' of https:…
petkybenedek 19bd6ab
Increase popver size
petkybenedek 198391f
- Split DashboardWidgetIdentifier into SystemWidgetIdentifier (fixe…
vargaat 7c4c007
Add color saving.
vargaat 2afe479
Add course settings switches. Move converences to system widgets.
vargaat 70ad1d1
Add unit tests.
vargaat 2ed5649
Use ID based color saving.
vargaat a7ebd90
Requested changes, change settings presentation logic
petkybenedek 09d93cb
Update unit tests.
vargaat 40bac3e
Merge branch 'feature/MBL-19529-Dashboard-simple-edit-mode' into feat…
vargaat 763f10a
Rename dashboard settings view to screen.
vargaat 704c4d6
Move factory methods to widget enums.
vargaat 3dbcdcd
Also move custom settings view factory to widget id file.
vargaat afeca50
Update colors.
vargaat 3bad66c
Update hidden widget update logic.
vargaat 614361b
Fix unit test. Update done button color.
vargaat 82f547c
Merge branch 'master' into feature/MBL-19529-Dashboard-simple-edit-mode
vargaat 47f125f
Merge branch 'feature/MBL-19529-Dashboard-simple-edit-mode' into feat…
vargaat 08f384c
Implement code review suggestions.
vargaat 3359454
Merge branch 'master' into feature/MBL-19529-Learner-Dashboard-settin…
vargaat df062d5
Shorten test file name.
vargaat 617c604
Create FlexibleGrid and place the dashboard colors in it.
petkybenedek 9c8dd1e
Extract default course colors from interactor.
vargaat a83bbaa
Remove unnecessary helper.
vargaat fc45bfb
Implement multiple UI related code review suggestions.
vargaat c0f9aa0
Add back bottom padding.
vargaat 882f35a
Fix lint violation.
vargaat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| // | ||
| // This file is part of Canvas. | ||
| // Copyright (C) 2026-present Instructure, Inc. | ||
| // | ||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU Affero General Public License as | ||
| // published by the Free Software Foundation, either version 3 of the | ||
| // License, or (at your option) any later version. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU Affero General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU Affero General Public License | ||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| // | ||
|
|
||
| import SwiftUI | ||
|
|
||
| /// FlexibleGrid places as many subviews in a row as possible. The remaining space is distributed evenly between the row's subviews. | ||
| /// If the last row is not complete the subviews are placed from the leading edge. | ||
| public struct FlexibleGrid: Layout { | ||
| let minimumSpacing: CGFloat | ||
| let lineSpacing: CGFloat | ||
|
|
||
| public init(minimumSpacing: CGFloat = 8, lineSpacing: CGFloat = 8) { | ||
| self.minimumSpacing = minimumSpacing | ||
| self.lineSpacing = lineSpacing | ||
| } | ||
|
|
||
| public func sizeThatFits( | ||
| proposal: ProposedViewSize, | ||
| subviews: Subviews, | ||
| cache: inout () | ||
| ) -> CGSize { | ||
| guard !subviews.isEmpty, let maxWidth = proposal.width else { return .zero } | ||
|
|
||
| let itemWidth = measureItemWidth(subviews: subviews, maxWidth: maxWidth) | ||
| let columns = columnCount(itemWidth: itemWidth, maxWidth: maxWidth) | ||
| let rowCount = (subviews.count + columns - 1) / columns | ||
| let rowHeight = measureRowHeight(subviews: subviews, maxWidth: maxWidth) | ||
|
|
||
| let totalHeight = CGFloat(rowCount) * rowHeight + CGFloat(max(rowCount - 1, 0)) * lineSpacing | ||
|
|
||
| let contentWidth = { | ||
| if let proposedWidth = proposal.width { | ||
| return proposedWidth | ||
| } else { | ||
| let gaps = max(columns - 1, 0) | ||
| return CGFloat(columns) * itemWidth + CGFloat(gaps) * minimumSpacing | ||
| } | ||
| }() | ||
|
|
||
| return CGSize(width: contentWidth, height: totalHeight) | ||
| } | ||
|
|
||
| public func placeSubviews( | ||
| in bounds: CGRect, | ||
| proposal: ProposedViewSize, | ||
| subviews: Subviews, | ||
| cache: inout () | ||
| ) { | ||
| guard !subviews.isEmpty else { return } | ||
|
|
||
| let itemWidth = measureItemWidth(subviews: subviews, maxWidth: bounds.width) | ||
| let columns = columnCount(itemWidth: itemWidth, maxWidth: bounds.width) | ||
| let rowHeight = measureRowHeight(subviews: subviews, maxWidth: bounds.width) | ||
|
|
||
| let totalItemWidth = CGFloat(columns) * itemWidth | ||
| let gaps = max(columns - 1, 0) | ||
| let uniformSpacing = gaps > 0 ? (bounds.width - totalItemWidth) / CGFloat(gaps) : 0 | ||
|
|
||
| for (index, subview) in subviews.enumerated() { | ||
| let col = index % columns | ||
| let row = index / columns | ||
|
|
||
| let x = bounds.minX + CGFloat(col) * (itemWidth + uniformSpacing) | ||
|
|
||
| let y = bounds.minY + CGFloat(row) * (rowHeight + lineSpacing) | ||
| let size = subview.sizeThatFits(ProposedViewSize(width: itemWidth, height: nil)) | ||
| let yOffset = (rowHeight - size.height) / 2 | ||
|
|
||
| subview.place( | ||
| at: CGPoint(x: x, y: y + yOffset), | ||
| anchor: .topLeading, | ||
| proposal: ProposedViewSize(width: size.width, height: size.height) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| private func measureItemWidth(subviews: Subviews, maxWidth: CGFloat) -> CGFloat { | ||
| subviews.reduce(CGFloat(0)) { maxSoFar, subview in | ||
| let size = subview.sizeThatFits(ProposedViewSize(width: maxWidth, height: nil)) | ||
| return max(maxSoFar, size.width) | ||
| } | ||
| } | ||
|
|
||
| private func measureRowHeight(subviews: Subviews, maxWidth: CGFloat) -> CGFloat { | ||
| subviews.reduce(CGFloat(0)) { maxSoFar, subview in | ||
| let size = subview.sizeThatFits(ProposedViewSize(width: maxWidth, height: nil)) | ||
| return max(maxSoFar, size.height) | ||
| } | ||
| } | ||
|
|
||
| private func columnCount(itemWidth: CGFloat, maxWidth: CGFloat) -> Int { | ||
| guard itemWidth > 0 else { return 1 } | ||
| var count = 1 | ||
| while CGFloat(count + 1) * itemWidth + CGFloat(count) * minimumSpacing <= maxWidth { | ||
| count += 1 | ||
| } | ||
| return count | ||
| } | ||
| } | ||
|
|
||
| #Preview("Left to Right") { | ||
| let colors: [Color] = [.red, .blue, .green, .yellow, .indigo, .teal, .purple] | ||
|
|
||
| FlexibleGrid { | ||
| ForEach(colors, id: \.self) { color in | ||
| Circle() | ||
| .fill(color) | ||
| .scaledFrame(size: 40) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #Preview("Right to Left") { | ||
| let colors: [Color] = [.red, .blue, .green, .yellow, .indigo, .teal, .purple] | ||
|
|
||
| FlexibleGrid { | ||
| ForEach(colors, id: \.self) { color in | ||
| Circle() | ||
| .fill(color) | ||
| .scaledFrame(size: 40) | ||
| } | ||
| } | ||
| .environment(\.layoutDirection, .rightToLeft) | ||
| } |
50 changes: 50 additions & 0 deletions
50
Core/Core/Features/Dashboard/CourseCardList/Model/CourseColorData.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // | ||
| // This file is part of Canvas. | ||
| // Copyright (C) 2026-present Instructure, Inc. | ||
| // | ||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU Affero General Public License as | ||
| // published by the Free Software Foundation, either version 3 of the | ||
| // License, or (at your option) any later version. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU Affero General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU Affero General Public License | ||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| // | ||
|
|
||
| import UIKit | ||
|
|
||
| public extension CourseColorData { | ||
| static let all: [CourseColorData] = [ | ||
| .init(persistentId: "plum", color: .course1, name: String(localized: "Plum", bundle: .core, comment: "This is a name of a color.")), | ||
| .init(persistentId: "fuchsia", color: .course2, name: String(localized: "Fuchsia", bundle: .core, comment: "This is a name of a color.")), | ||
| .init(persistentId: "violet", color: .course3, name: String(localized: "Violet", bundle: .core, comment: "This is a name of a color.")), | ||
| .init(persistentId: "ocean", color: .course4, name: String(localized: "Ocean", bundle: .core, comment: "This is a name of a color.")), | ||
| .init(persistentId: "sky", color: .course5, name: String(localized: "Sky", bundle: .core, comment: "This is a name of a color.")), | ||
| .init(persistentId: "sea", color: .course6, name: String(localized: "Sea", bundle: .core, comment: "This is a name of a color.")), | ||
| .init(persistentId: "aurora", color: .course7, name: String(localized: "Aurora", bundle: .core, comment: "This is a name of a color.")), | ||
| .init(persistentId: "forest", color: .course8, name: String(localized: "Forest", bundle: .core, comment: "This is a name of a color.")), | ||
| .init(persistentId: "honey", color: .course9, name: String(localized: "Honey", bundle: .core, comment: "This is a name of a color.")), | ||
| .init(persistentId: "copper", color: .course10, name: String(localized: "Copper", bundle: .core, comment: "This is a name of a color.")), | ||
| .init(persistentId: "rose", color: .course11, name: String(localized: "Rose", bundle: .core, comment: "This is a name of a color.")), | ||
| .init(persistentId: "stone", color: .course12, name: String(localized: "Stone", bundle: .core, comment: "This is a name of a color.")) | ||
| ] | ||
| } | ||
|
|
||
| public struct CourseColorData: Identifiable { | ||
| public let persistentId: String | ||
| public let color: UIColor | ||
| public let name: String | ||
|
|
||
| public var id: String { persistentId } | ||
|
|
||
| public init(persistentId: String, color: UIColor, name: String) { | ||
| self.persistentId = persistentId | ||
| self.color = color | ||
| self.name = name | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.