-
Notifications
You must be signed in to change notification settings - Fork 57
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
feat: 🎸 [JIRA: HCPSDKFIORIUIKIT-2348] shadow effect api #791
Merged
Merged
Changes from 2 commits
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 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 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
46 changes: 46 additions & 0 deletions
46
Apps/Examples/Examples/FioriSwiftUICore/Views/ShadowEffectExample.swift
This file contains 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,46 @@ | ||
import FioriSwiftUICore | ||
import SwiftUI | ||
|
||
struct ShadowEffectExample: View { | ||
var body: some View { | ||
ScrollView { | ||
VStack(spacing: 20) { | ||
ForEach(FioriShadowStyle.allCases, id: \.self) { style in | ||
ZStack { | ||
Color.preferredColor(.secondaryGroupedBackground) | ||
.frame(width: 300, height: 100) | ||
.clipShape(RoundedRectangle(cornerRadius: 10)) | ||
.shadow(style) | ||
.padding() | ||
|
||
self.styleDescription(style) | ||
.bold() | ||
.font(.fiori(forTextStyle: .title1)) | ||
} | ||
} | ||
}.frame(maxWidth: .infinity) | ||
} | ||
.frame(maxWidth: .infinity) | ||
.background(Color.preferredColor(.primaryGroupedBackground)) | ||
.navigationTitle("Shadow Effect") | ||
} | ||
|
||
@ViewBuilder func styleDescription(_ style: FioriShadowStyle) -> some View { | ||
switch style { | ||
case .level0: | ||
Text("Level 0") | ||
case .level1: | ||
Text("Level 1") | ||
case .level2: | ||
Text("Level 2") | ||
case .level3: | ||
Text("Level 3") | ||
case .level4: | ||
Text("Level 3") | ||
case .smallElement: | ||
Text("Small Shape") | ||
case .mediumElement: | ||
Text("Medium Shape") | ||
} | ||
} | ||
} |
This file contains 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,74 @@ | ||
import FioriThemeManager | ||
import SwiftUI | ||
|
||
/// Fiori style shadow. | ||
public enum FioriShadowStyle: CaseIterable { | ||
/// Shadow level 0. Most used in banner, header or previews. | ||
case level0 | ||
/// Shadow Level 1. | ||
case level1 | ||
/// Shadow Level 2. Most used in cards or modal views. | ||
case level2 | ||
/// Shadow Level 3. Most used in toast message or quick sort. | ||
case level3 | ||
/// Shadow Level 4. Most used in popovers. | ||
case level4 | ||
|
||
/// Shadow for small element. Most used in switch or slider. | ||
case smallElement | ||
/// Shadow for medium element. Most used in segmented control. | ||
case mediumElement | ||
} | ||
|
||
public extension View { | ||
/// Apply a shadow with the specified fiori style. | ||
/// - Parameter style: Shadow style. | ||
/// - Returns: A new view with the specified shadow style. | ||
func shadow(_ style: FioriShadowStyle) -> some View { | ||
self.modifier(FioriShadowModifier(style: style)) | ||
} | ||
} | ||
|
||
struct FioriShadowModifier: ViewModifier { | ||
let style: FioriShadowStyle | ||
|
||
let color1 = Color(white: 0, opacity: 0.13) | ||
let color2 = Color(white: 0, opacity: 0.04) | ||
let color3 = Color(white: 0, opacity: 0.2) | ||
|
||
let color4 = Color(white: 0, opacity: 0.12) | ||
|
||
func body(content: Content) -> some View { | ||
switch self.style { | ||
case .level0: | ||
content | ||
.shadow(color: self.color1, radius: 1) | ||
case .level1: | ||
content | ||
.shadow(color: self.color1, radius: 1) | ||
.shadow(color: self.color2, radius: 2, y: 1) | ||
case .level2: | ||
content | ||
.shadow(color: self.color1, radius: 1) | ||
.shadow(color: self.color2, radius: 4, y: 2) | ||
case .level3: | ||
content | ||
.shadow(color: self.color1, radius: 1) | ||
.shadow(color: self.color2, radius: 16, y: 8) | ||
.shadow(color: self.color2, radius: 32, y: 16) | ||
xiaoyu0722 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
case .level4: | ||
content | ||
.shadow(color: self.color2, radius: 1) | ||
.shadow(color: self.color2, radius: 8, y: 8) | ||
.shadow(color: self.color3, radius: 50, y: 10) | ||
case .smallElement: | ||
content | ||
.shadow(color: self.color4, radius: 6.5, y: 6) | ||
.shadow(color: self.color4, radius: 2, y: 0.5) | ||
case .mediumElement: | ||
content | ||
.shadow(color: self.color2, radius: 0.5, y: 3) | ||
.shadow(color: self.color4, radius: 4, y: 3) | ||
} | ||
} | ||
} |
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.
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.
Does the spec say the color used here should be "white" ? I think opacity on top of a "white" color may not create any visual effect. Also, we need to consider dark mode. So base color should be a dynamic color , I assume. You can follow up with Designer on this.
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.
Yes, all shadows are black(0 white) with opacity and same values for light and dark mode.