-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🎸 [JIRA:HCPSDKFIORIUIKIT-2880] ActivityItemModel Refactor
- Loading branch information
1 parent
1f463ad
commit c3a8927
Showing
30 changed files
with
464 additions
and
70 deletions.
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
49 changes: 49 additions & 0 deletions
49
Apps/Examples/Examples/FioriSwiftUICore/ActivityItem/ActivityItemExample.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,49 @@ | ||
import FioriSwiftUICore | ||
import SwiftUI | ||
|
||
struct ActivityItemExample: View { | ||
var body: some View { | ||
List { | ||
Section { | ||
ActivityItem(icon: Image(systemName: "phone"), subtitle: AttributedString("phone")) | ||
ActivityItem(icon: Image(systemName: "envelope"), subtitle: AttributedString("envelope")) | ||
ActivityItem(icon: Image(systemName: "message"), subtitle: AttributedString("message")) | ||
ActivityItem(icon: Image(systemName: "video"), subtitle: AttributedString("video")) | ||
} header: { | ||
Text("Normal-Vertical") | ||
} | ||
|
||
Section { | ||
ActivityItem(icon: Image(systemName: "phone"), subtitle: AttributedString("phone"), layout: .horizontal) | ||
ActivityItem(icon: Image(systemName: "envelope"), subtitle: AttributedString("envelope"), layout: .horizontal) | ||
ActivityItem(icon: Image(systemName: "message"), subtitle: AttributedString("message"), layout: .horizontal) | ||
ActivityItem(icon: Image(systemName: "video"), subtitle: AttributedString("video"), layout: .horizontal) | ||
} header: { | ||
Text("Normal-Horizontal") | ||
} | ||
|
||
Section { | ||
ActivityItem(icon: Image(systemName: "phone")) | ||
ActivityItem(icon: Image(systemName: "envelope")) | ||
ActivityItem(icon: Image(systemName: "message")) | ||
ActivityItem(icon: Image(systemName: "video")) | ||
} header: { | ||
Text("Only Icon") | ||
} | ||
|
||
Section { | ||
ActivityItem(subtitle: AttributedString("phone")) | ||
ActivityItem(subtitle: AttributedString("envelope")) | ||
ActivityItem(subtitle: AttributedString("message")) | ||
ActivityItem(subtitle: AttributedString("video")) | ||
} header: { | ||
Text("Only Subtitle") | ||
} | ||
} | ||
.navigationTitle(Text("ActivityItemExample")) | ||
} | ||
} | ||
|
||
#Preview { | ||
ActivityItemExample() | ||
} |
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
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
57 changes: 57 additions & 0 deletions
57
Sources/FioriSwiftUICore/_FioriStyles/ActivityItemStyle.fiori.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,57 @@ | ||
import FioriThemeManager | ||
import Foundation | ||
import SwiftUI | ||
|
||
/// Activity item layout | ||
public enum ActivityItemLayout { | ||
/// Vertical layout for ActivityItem. | ||
case vertical | ||
/// Horizontal layout for ActivityItem. | ||
case horizontal | ||
} | ||
|
||
// Base Layout style | ||
public struct ActivityItemBaseStyle: ActivityItemStyle { | ||
public func makeBody(_ configuration: ActivityItemConfiguration) -> some View { | ||
// Add default layout here | ||
switch configuration.layout { | ||
case .vertical: | ||
VStack { | ||
configuration.icon | ||
configuration.subtitle | ||
} | ||
.typeErased | ||
case .horizontal: | ||
HStack { | ||
configuration.icon | ||
configuration.subtitle | ||
} | ||
.typeErased | ||
} | ||
} | ||
} | ||
|
||
// Default fiori styles | ||
extension ActivityItemFioriStyle { | ||
struct ContentFioriStyle: ActivityItemStyle { | ||
func makeBody(_ configuration: ActivityItemConfiguration) -> some View { | ||
ActivityItem(configuration) | ||
} | ||
} | ||
|
||
struct IconFioriStyle: IconStyle { | ||
let activityItemConfiguration: ActivityItemConfiguration | ||
|
||
func makeBody(_ configuration: IconConfiguration) -> some View { | ||
Icon(configuration) | ||
} | ||
} | ||
|
||
struct SubtitleFioriStyle: SubtitleStyle { | ||
let activityItemConfiguration: ActivityItemConfiguration | ||
|
||
func makeBody(_ configuration: SubtitleConfiguration) -> some View { | ||
Subtitle(configuration) | ||
} | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
...FioriSwiftUICore/_generated/StyleableComponents/ActivityItem/ActivityItem.generated.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,76 @@ | ||
// Generated using Sourcery 2.1.7 — https://github.com/krzysztofzablocki/Sourcery | ||
// DO NOT EDIT | ||
import Foundation | ||
import SwiftUI | ||
|
||
public struct ActivityItem { | ||
let icon: any View | ||
let subtitle: any View | ||
/// Activity item layout. The default is .vertical | ||
let layout: ActivityItemLayout | ||
|
||
@Environment(\.activityItemStyle) var style | ||
|
||
fileprivate var _shouldApplyDefaultStyle = true | ||
|
||
public init(@ViewBuilder icon: () -> any View = { EmptyView() }, | ||
@ViewBuilder subtitle: () -> any View = { EmptyView() }, | ||
layout: ActivityItemLayout = .vertical) | ||
{ | ||
self.icon = Icon(icon: icon) | ||
self.subtitle = Subtitle(subtitle: subtitle) | ||
self.layout = layout | ||
} | ||
} | ||
|
||
public extension ActivityItem { | ||
init(icon: Image? = nil, | ||
subtitle: AttributedString? = nil, | ||
layout: ActivityItemLayout = .vertical) | ||
{ | ||
self.init(icon: { icon }, subtitle: { OptionalText(subtitle) }, layout: layout) | ||
} | ||
} | ||
|
||
public extension ActivityItem { | ||
init(_ configuration: ActivityItemConfiguration) { | ||
self.init(configuration, shouldApplyDefaultStyle: false) | ||
} | ||
|
||
internal init(_ configuration: ActivityItemConfiguration, shouldApplyDefaultStyle: Bool) { | ||
self.icon = configuration.icon | ||
self.subtitle = configuration.subtitle | ||
self.layout = configuration.layout | ||
self._shouldApplyDefaultStyle = shouldApplyDefaultStyle | ||
} | ||
} | ||
|
||
extension ActivityItem: View { | ||
public var body: some View { | ||
if self._shouldApplyDefaultStyle { | ||
self.defaultStyle() | ||
} else { | ||
self.style.resolve(configuration: .init(icon: .init(self.icon), subtitle: .init(self.subtitle), layout: self.layout)).typeErased | ||
.transformEnvironment(\.activityItemStyleStack) { stack in | ||
if !stack.isEmpty { | ||
stack.removeLast() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private extension ActivityItem { | ||
func shouldApplyDefaultStyle(_ bool: Bool) -> some View { | ||
var s = self | ||
s._shouldApplyDefaultStyle = bool | ||
return s | ||
} | ||
|
||
func defaultStyle() -> some View { | ||
ActivityItem(.init(icon: .init(self.icon), subtitle: .init(self.subtitle), layout: self.layout)) | ||
.shouldApplyDefaultStyle(false) | ||
.activityItemStyle(ActivityItemFioriStyle.ContentFioriStyle()) | ||
.typeErased | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...SwiftUICore/_generated/StyleableComponents/ActivityItem/ActivityItemStyle.generated.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,39 @@ | ||
// Generated using Sourcery 2.1.7 — https://github.com/krzysztofzablocki/Sourcery | ||
// DO NOT EDIT | ||
import Foundation | ||
import SwiftUI | ||
|
||
public protocol ActivityItemStyle: DynamicProperty { | ||
associatedtype Body: View | ||
|
||
func makeBody(_ configuration: ActivityItemConfiguration) -> Body | ||
} | ||
|
||
struct AnyActivityItemStyle: ActivityItemStyle { | ||
let content: (ActivityItemConfiguration) -> any View | ||
|
||
init(@ViewBuilder _ content: @escaping (ActivityItemConfiguration) -> any View) { | ||
self.content = content | ||
} | ||
|
||
public func makeBody(_ configuration: ActivityItemConfiguration) -> some View { | ||
self.content(configuration).typeErased | ||
} | ||
} | ||
|
||
public struct ActivityItemConfiguration { | ||
public let icon: Icon | ||
public let subtitle: Subtitle | ||
public let layout: ActivityItemLayout | ||
|
||
public typealias Icon = ConfigurationViewWrapper | ||
public typealias Subtitle = ConfigurationViewWrapper | ||
} | ||
|
||
public struct ActivityItemFioriStyle: ActivityItemStyle { | ||
public func makeBody(_ configuration: ActivityItemConfiguration) -> some View { | ||
ActivityItem(configuration) | ||
.iconStyle(IconFioriStyle(activityItemConfiguration: configuration)) | ||
.subtitleStyle(SubtitleFioriStyle(activityItemConfiguration: configuration)) | ||
} | ||
} |
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
Oops, something went wrong.