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

feat: 🎸 [JIRA: HCPSDKFIORIUIKIT-2348] shadow effect api #791

Merged
merged 4 commits into from
Sep 11, 2024
Merged
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
4 changes: 4 additions & 0 deletions Apps/Examples/Examples.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
B18D2E9F2988B07B000A1821 /* KPIHeaderExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = B18D2E9E2988B07B000A1821 /* KPIHeaderExample.swift */; };
B18D593C2B0C52C700ABB1AD /* TabViewExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = B18D593B2B0C52C700ABB1AD /* TabViewExample.swift */; };
B190065A2C201BBE000C8B10 /* ProfileHeaderExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = B19006592C201BBE000C8B10 /* ProfileHeaderExample.swift */; };
B1A78D982C88388B00432B0D /* ShadowEffectExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1A78D972C88388B00432B0D /* ShadowEffectExample.swift */; };
B1A98FF22C11592B00FC9998 /* BannerMessageExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1A98FF12C11592B00FC9998 /* BannerMessageExample.swift */; };
B1A98FF52C12E9A000FC9998 /* BannerMessageModifierExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1A98FF42C12E9A000FC9998 /* BannerMessageModifierExample.swift */; };
B1A98FF72C12EA1600FC9998 /* BannerMessageCustomInitExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1A98FF62C12EA1600FC9998 /* BannerMessageCustomInitExample.swift */; };
Expand Down Expand Up @@ -324,6 +325,7 @@
B18D2E9E2988B07B000A1821 /* KPIHeaderExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KPIHeaderExample.swift; sourceTree = "<group>"; };
B18D593B2B0C52C700ABB1AD /* TabViewExample.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TabViewExample.swift; sourceTree = "<group>"; };
B19006592C201BBE000C8B10 /* ProfileHeaderExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileHeaderExample.swift; sourceTree = "<group>"; };
B1A78D972C88388B00432B0D /* ShadowEffectExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShadowEffectExample.swift; sourceTree = "<group>"; };
B1A98FF12C11592B00FC9998 /* BannerMessageExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BannerMessageExample.swift; sourceTree = "<group>"; };
B1A98FF42C12E9A000FC9998 /* BannerMessageModifierExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BannerMessageModifierExample.swift; sourceTree = "<group>"; };
B1A98FF62C12EA1600FC9998 /* BannerMessageCustomInitExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BannerMessageCustomInitExample.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -727,6 +729,7 @@
children = (
9DEC27B42C3F3DB30070B571 /* KeyValueItemExample.swift */,
9DEC27B62C3F3DE70070B571 /* OtherViewExamples.swift */,
B1A78D972C88388B00432B0D /* ShadowEffectExample.swift */,
);
path = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -1100,6 +1103,7 @@
8A6DE30B28DD27F9003222E3 /* Colors.swift in Sources */,
8AD9DFB225D49967007448EC /* StylingModifierExample.swift in Sources */,
9D0B260A2B9BA5C0004278A5 /* NoteFormViewExample.swift in Sources */,
B1A78D982C88388B00432B0D /* ShadowEffectExample.swift in Sources */,
9DEC27B72C3F3DE70070B571 /* OtherViewExamples.swift in Sources */,
87F492332C73ADA1002B8703 /* SimpleTimelinePreviewExample.swift in Sources */,
8A5579D124C1293C0098003A /* Settings.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,14 @@ struct CoreContentView: View {
}
}

Section(header: Text("Utilities")) {
NavigationLink(
destination: ShadowEffectExample())
{
Text("Shadow Effect")
}
}

Section(header: Text("ExperimentalContentView")) {
NavigationLink(
destination: ExperimentalContentView())
Expand Down
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")
}
}
}
74 changes: 74 additions & 0 deletions Sources/FioriSwiftUICore/Utils/ShadowEffect.swift
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)
Copy link
Contributor

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.

Copy link
Contributor Author

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.
Screenshot 2024-09-06 at 07 54 05

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: 8, y: 8)
.shadow(color: self.color2, radius: 16, y: 16)
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)
}
}
}
Loading