-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: 💡 [JIRA:HCPSDKFIORIUIKIT-2880] ActionItems Refactor (#939)
* refactor: 💡 [JIRA:HCPSDKFIORIUIKIT-2880] ActionItems Refactor * refactor: 💡 [JIRA:HCPSDKFIORIUIKIT-2880] ActionItems Refactor * refactor: 💡 [JIRA:HCPSDKFIORIUIKIT-2880] ActionItems Refactor Support fiori style for action items * refactor: 💡 [JIRA:HCPSDKFIORIUIKIT-2880] ActionItems Refactor Doc grammer fix
- Loading branch information
1 parent
6ca89fa
commit 33d3788
Showing
17 changed files
with
523 additions
and
2 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
146 changes: 146 additions & 0 deletions
146
Apps/Examples/Examples/FioriSwiftUICore/ActionItems/ActionItemsExample.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,146 @@ | ||
import FioriSwiftUICore | ||
import SwiftUI | ||
|
||
struct ActionItemsExample: View { | ||
var body: some View { | ||
List { | ||
Section { | ||
ActionItems(actionItems: [ | ||
.init(type: .phone, didSelectActivityItem: { | ||
print("click phone") | ||
}) | ||
]) | ||
ActionItems(actionItems: [ | ||
.init(type: .phone, didSelectActivityItem: { | ||
print("click phone") | ||
}), | ||
.init(type: .email, didSelectActivityItem: { | ||
print("click email") | ||
}) | ||
]) | ||
ActionItems(actionItems: [ | ||
.init(type: .phone, didSelectActivityItem: { | ||
print("click phone") | ||
}), | ||
.init(type: .email, didSelectActivityItem: { | ||
print("click email") | ||
}), | ||
.init(type: .message, didSelectActivityItem: { | ||
print("click message") | ||
}) | ||
]) | ||
ActionItems(actionItems: [ | ||
.init(type: .phone, didSelectActivityItem: { | ||
print("click phone") | ||
}), | ||
.init(type: .email, didSelectActivityItem: { | ||
print("click email") | ||
}), | ||
.init(type: .message, didSelectActivityItem: { | ||
print("click message") | ||
}), | ||
.init(type: .videoCall, didSelectActivityItem: { | ||
print("click videoCall") | ||
}) | ||
]) | ||
ActionItems(actionItems: [ | ||
.init(type: .phone, didSelectActivityItem: { | ||
print("click phone") | ||
}), | ||
.init(type: .email, didSelectActivityItem: { | ||
print("click email") | ||
}), | ||
.init(type: .message, didSelectActivityItem: { | ||
print("click message") | ||
}), | ||
.init(type: .videoCall, didSelectActivityItem: { | ||
print("click videoCall") | ||
}), | ||
.init(type: .detail, didSelectActivityItem: { | ||
print("click detail") | ||
}) | ||
]) | ||
.actionItemsStyle { conf in | ||
conf.actionItems | ||
.font(.fiori(forTextStyle: .headline).weight(.bold)) | ||
.foregroundColor(.red) | ||
} | ||
} header: { | ||
Text("Usual Type") | ||
.textCase(.none) | ||
} | ||
|
||
Section { | ||
ActionItems(actionItems: [ | ||
.init(type: .custom(Image(systemName: "person")), didSelectActivityItem: { | ||
print("custom person") | ||
}), | ||
.init(type: .custom(Image(systemName: "heart")), didSelectActivityItem: { | ||
print("custom heart") | ||
}), | ||
.init(type: .custom(Image(systemName: "clock")), didSelectActivityItem: { | ||
print("custom clock") | ||
}) | ||
]) | ||
} header: { | ||
Text("Custom Type") | ||
.textCase(.none) | ||
} | ||
|
||
Section { | ||
ActionItems { | ||
Button { | ||
print("click person") | ||
} label: { | ||
Image(systemName: "person") | ||
.font(.fiori(forTextStyle: .headline).weight(.heavy)) | ||
.imageScale(.large) | ||
.foregroundColor(.red) | ||
.frame(width: 44, height: 44) | ||
} | ||
.buttonStyle(BorderlessButtonStyle()) | ||
|
||
Button { | ||
print("click heart") | ||
} label: { | ||
Image(systemName: "heart") | ||
.font(.fiori(forTextStyle: .headline).weight(.heavy)) | ||
.imageScale(.large) | ||
.foregroundColor(.yellow) | ||
.frame(width: 44, height: 44) | ||
} | ||
.buttonStyle(BorderlessButtonStyle()) | ||
|
||
Button { | ||
print("click info.circle") | ||
} label: { | ||
Image(systemName: "info.circle") | ||
.font(.fiori(forTextStyle: .headline).weight(.heavy)) | ||
.imageScale(.large) | ||
.foregroundColor(.blue) | ||
.frame(width: 44, height: 44) | ||
} | ||
.buttonStyle(BorderlessButtonStyle()) | ||
|
||
Button { | ||
print("click book") | ||
} label: { | ||
Image(systemName: "book") | ||
.font(.fiori(forTextStyle: .headline).weight(.heavy)) | ||
.imageScale(.large) | ||
.foregroundColor(.green) | ||
.frame(width: 44, height: 44) | ||
} | ||
.buttonStyle(BorderlessButtonStyle()) | ||
} | ||
} header: { | ||
Text("Custom items") | ||
} | ||
} | ||
.navigationTitle("ActionItemsExample") | ||
} | ||
} | ||
|
||
#Preview { | ||
ActionItemsExample() | ||
} |
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
111 changes: 111 additions & 0 deletions
111
Sources/FioriSwiftUICore/Views/ActionItems/ActionItemsBuilder.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,111 @@ | ||
import SwiftUI | ||
|
||
/// :nodoc: | ||
public protocol ActionItemsList: View, _ViewEmptyChecking { | ||
associatedtype V: View | ||
var count: Int { get } | ||
func view(at index: Int) -> V | ||
} | ||
|
||
struct ActionItemsListStack: ActionItemsList { | ||
let actionItems: [any View] | ||
|
||
init(_ actionItemsData: [ActivityItemDataType]) { | ||
var temp: [any View] = [] | ||
for element in actionItemsData { | ||
let item = Button { | ||
element.didSelectActivityItem?() | ||
} label: { | ||
element.icon | ||
.imageScale(.large) | ||
.frame(width: 44, height: 44, alignment: .center) | ||
} | ||
.buttonStyle(BorderlessButtonStyle()) | ||
.typeErased | ||
|
||
temp.append(item.typeErased) | ||
} | ||
|
||
self.actionItems = temp | ||
} | ||
|
||
init(actionItems: [any View]) { | ||
self.actionItems = actionItems | ||
} | ||
|
||
public var count: Int { | ||
self.actionItems.count | ||
} | ||
|
||
var isEmpty: Bool { | ||
self.actionItems.isEmpty | ||
} | ||
|
||
public func view(at index: Int) -> some View { | ||
self.actionItems[index].typeErased | ||
} | ||
|
||
var body: some View { | ||
HStack(spacing: 0) { | ||
ForEach(0 ..< self.actionItems.count, id: \.self) { index in | ||
self.actionItems[index].typeErased | ||
} | ||
} | ||
} | ||
} | ||
|
||
/// A custom parameter attribute that constructs views from closures. | ||
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *) | ||
@resultBuilder | ||
public enum ActionItemsBuilder { | ||
/// :nodoc: | ||
public static func buildBlock(_ components: any View...) -> some ActionItemsList { | ||
let flatAvatars = components.flatMap { component -> [any View] in | ||
if let c = component as? ActionItemsListStack { | ||
return c.actionItems | ||
} else { | ||
return [component] | ||
} | ||
} | ||
return ActionItemsListStack(actionItems: flatAvatars) | ||
} | ||
|
||
/// :nodoc: | ||
public static func buildBlock() -> EmptyView { | ||
EmptyView() | ||
} | ||
|
||
/// :nodoc: | ||
public static func buildExpression(_ expression: some View) -> some View { | ||
expression | ||
} | ||
|
||
/// :nodoc: | ||
public static func buildExpression<Data: RandomAccessCollection>( | ||
_ expression: ForEach<Data, Data.Element, some View> | ||
) -> some ActionItemsList { | ||
ActionItemsListStack(actionItems: expression.data.map { item in | ||
expression.content(item) | ||
}) | ||
} | ||
|
||
/// :nodoc: | ||
public static func buildEither(first: any View) -> some ActionItemsList { | ||
ActionItemsListStack(actionItems: [first]) | ||
} | ||
|
||
/// :nodoc: | ||
public static func buildEither(second: any View) -> some ActionItemsList { | ||
ActionItemsListStack(actionItems: [second]) | ||
} | ||
|
||
/// :nodoc: | ||
public static func buildOptional(_ component: (any View)?) -> some ActionItemsList { | ||
ActionItemsListStack(actionItems: component.map { [$0] } ?? []) | ||
} | ||
|
||
/// :nodoc: | ||
public static func buildArray(_ components: [any View]) -> some ActionItemsList { | ||
ActionItemsListStack(actionItems: components) | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
Sources/FioriSwiftUICore/_FioriStyles/ActionItemsStyle.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,22 @@ | ||
import FioriThemeManager | ||
import Foundation | ||
import SwiftUI | ||
|
||
// Base Layout style | ||
public struct ActionItemsBaseStyle: ActionItemsStyle { | ||
@ViewBuilder | ||
public func makeBody(_ configuration: ActionItemsConfiguration) -> some View { | ||
// Add default layout here | ||
configuration.actionItems | ||
} | ||
} | ||
|
||
// Default fiori styles | ||
public struct ActionItemsFioriStyle: ActionItemsStyle { | ||
@ViewBuilder | ||
public func makeBody(_ configuration: ActionItemsConfiguration) -> some View { | ||
ActionItems(configuration) | ||
.font(.fiori(forTextStyle: .body).weight(.light)) | ||
.foregroundColor(.preferredColor(.tintColor)) | ||
} | ||
} |
Oops, something went wrong.