-
Notifications
You must be signed in to change notification settings - Fork 124
[Horizon] Add navigation bar #3034
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
Ahmed-Naguib93
merged 4 commits into
feature/horizon
from
feature/horizon-CLX-282-top-nav-bar-components
Jan 7, 2025
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
15 changes: 15 additions & 0 deletions
15
...urces/HorizonUI/Resources/Assets.xcassets/Icons/menu_book_notebook.imageset/Contents.json
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,15 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "menu_book_notebook.svg", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
}, | ||
"properties" : { | ||
"template-rendering-intent" : "template" | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...ources/Assets.xcassets/Icons/menu_book_notebook.imageset/menu_book_notebook.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions
35
...ources/HorizonUI/Sources/Components/NavigationBar/HorizonUI.NavigationBar.Storybook.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,35 @@ | ||
// | ||
// This file is part of Canvas. | ||
// Copyright (C) 2024-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 | ||
public extension HorizonUI.NavigationBar { | ||
struct Storybook: View { | ||
public var body: some View { | ||
VStack { | ||
|
||
} | ||
.navigationBarItems(leading: HorizonUI.NavigationBar.Leading(title: "Hi HorizonUI")) | ||
.navigationBarItems(trailing: HorizonUI.NavigationBar.Trailing(onEvent: { _ in })) | ||
.navigationTitle("NavigationBar") | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
HorizonUI.NavigationBar.Storybook() | ||
} |
42 changes: 42 additions & 0 deletions
42
...s/HorizonUI/Sources/HorizonUI/Sources/Components/NavigationBar/LeadingNavigationBar.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,42 @@ | ||
// | ||
// This file is part of Canvas. | ||
// Copyright (C) 2024-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 | ||
|
||
public extension HorizonUI.NavigationBar { | ||
struct Leading: View { | ||
let title: String | ||
|
||
public init(title: String) { | ||
self.title = title | ||
} | ||
|
||
public var body: some View { | ||
Text(title) | ||
.foregroundStyle(Color.huiColors.text.title) | ||
.huiTypography(.p3) | ||
.padding(.huiSpaces.primitives.mediumSmall) | ||
.background(Color.huiColors.surface.pageTertiary) | ||
} | ||
} | ||
} | ||
Ahmed-Naguib93 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#Preview { | ||
HorizonUI.NavigationBar.Leading(title: "HorizonUI") | ||
} | ||
|
90 changes: 90 additions & 0 deletions
90
.../HorizonUI/Sources/HorizonUI/Sources/Components/NavigationBar/TrailingNavigationBar.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,90 @@ | ||
// | ||
// This file is part of Canvas. | ||
// Copyright (C) 2024-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 | ||
|
||
public extension HorizonUI.NavigationBar { | ||
struct Trailing: View { | ||
public enum Event { | ||
case mail | ||
case notebook | ||
case notification | ||
} | ||
|
||
private let onEvent: (Event) -> Void | ||
|
||
public init(onEvent: @escaping (Event) -> Void) { | ||
self.onEvent = onEvent | ||
} | ||
|
||
public var body: some View { | ||
HStack(spacing: .zero) { | ||
Button { | ||
Ahmed-Naguib93 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
onEvent(.notebook) | ||
} label: { | ||
Image.huiIcons.menuBookNotebook | ||
.dropShadow() | ||
} | ||
|
||
Button { | ||
onEvent(.notification) | ||
} label: { | ||
Image.huiIcons.notificationsUnread | ||
.dropShadow() | ||
} | ||
|
||
Button { | ||
onEvent(.mail) | ||
} label: { | ||
Image.huiIcons.mail | ||
.dropShadow() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
HorizonUI.NavigationBar.Trailing { _ in } | ||
} | ||
|
||
fileprivate extension HorizonUI.NavigationBar.Trailing { | ||
struct DropShadowModifire: ViewModifier { | ||
func body(content: Content) -> some View { | ||
content | ||
.foregroundStyle(Color.huiColors.icon.default) | ||
.frame(width: 44, height: 44) | ||
.background { | ||
Rectangle() | ||
.fill(Color.huiColors.surface.pageSecondary) | ||
.huiCornerRadius(level: .level6) | ||
.huiElevation(level: .level4) | ||
} | ||
} | ||
} | ||
} | ||
|
||
fileprivate extension View { | ||
func dropShadow() -> some View { | ||
modifier(HorizonUI.NavigationBar.Trailing.DropShadowModifire()) | ||
} | ||
} | ||
|
||
public extension HorizonUI { | ||
struct NavigationBar {} | ||
} |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't love the pattern of requiring the view to set a property on the view model. I think it's better just to pass the viewController as an argument to the notebookDidTap method. That way it's always clear what is required. Otherwise it can be unclear to someone using the view model that they need to set that property before it'll work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok but i need to pass the closure direct to view model, because the navigation logic must be set in viewModel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would just be one of the parameters passed in the onEvent handler:
func onEvent(event: HorizonUI.NavigationBar.Trailing.Event, viewController: WeakViewController)
You might also consider creating a separate ViewModel to pair with the HorizonUI.NavigationBar.Trailing and putting the onEvent handler in there. Otherwise we must handle the navigation logic in the ViewModel for every View that uses the HorizonUI.NavigationBar.Trailing view.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm being honest though, the amount of logic that would go into the Trailing view controller is so small and unlikely to be broken, I'd probably just put it into the view. So it's up to you what you want to do there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, HorizonUI is just for creating UI only and shouldn't have any logic in it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this component will be used only on the dashboard, I'd simply pass 3 named
() -> Void
closure to theHorizonUI.NavigationBar.Trailing
initializer then we can have:that is readable easily.