-
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: 🎸 [HCPSDKFIORIUIKIT-2481] New Mobile Card (#665)
* feat: 🎸 [HCPSDKFIORIUIKIT-2481] New Mobile Card * fix: 🐛 [HCPSDKFIORIUIKIT-2481] remove one public TagStyle
- Loading branch information
Showing
23 changed files
with
1,157 additions
and
600 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
Apps/Examples/Examples/Assets.xcassets/card_image.imageset/Contents.json
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,21 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "MicrosoftTeams-image.png", | ||
"idiom" : "universal", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Binary file added
BIN
+2.38 MB
.../Examples/Examples/Assets.xcassets/card_image.imageset/MicrosoftTeams-image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
803 changes: 393 additions & 410 deletions
803
Apps/Examples/Examples/FioriSwiftUICore/Card/MobileCardExample.swift
Large diffs are not rendered by default.
Oops, something went wrong.
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
97 changes: 97 additions & 0 deletions
97
Sources/FioriSwiftUICore/Utils/EqualWidthWithMaxWidthHStackLayout.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,97 @@ | ||
import SwiftUI | ||
|
||
struct EqualWidthWithMaxWidthHStackLayout: Layout { | ||
/// The distance between adjacent subviews. | ||
var spacing: CGFloat? = 4 | ||
|
||
/// Same height for all subviews | ||
var isSameHeight: Bool = true | ||
|
||
/// The vertical alignment of subviews. | ||
var alignment: VerticalAlignment = .center | ||
|
||
/// Maximum width for each element in the container | ||
var maxWidth: CGFloat? = nil | ||
|
||
var horizontalSizeClass: UserInterfaceSizeClass? = .compact | ||
|
||
func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize { | ||
guard let containerWidth = proposal.width, containerWidth > 0, !subviews.isEmpty else { return .zero } | ||
let subViewSizes = subviews.map { | ||
$0.sizeThatFits(.unspecified) | ||
} | ||
let maxHeight: CGFloat = subViewSizes.reduce(0) { curr, subviewSize in | ||
max(curr, subviewSize.height) | ||
} | ||
|
||
return CGSize(width: containerWidth, height: maxHeight) | ||
} | ||
|
||
func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) { | ||
guard let containerWidth = proposal.width, containerWidth > 0, !subviews.isEmpty else { return } | ||
|
||
let subViewSizes = subviews.map { | ||
$0.sizeThatFits(.unspecified) | ||
} | ||
let maxHeight: CGFloat = subViewSizes.reduce(0) { curr, subviewSize in | ||
max(curr, subviewSize.height) | ||
} | ||
let theSpacing: CGFloat = self.spacing ?? 0 | ||
let totalSpacing = theSpacing * CGFloat(subviews.count - 1) | ||
let theMaxWidth = self.horizontalSizeClass == .compact ? CGFloat.greatestFiniteMagnitude : self.maxWidth ?? CGFloat.greatestFiniteMagnitude | ||
let subviewWidth: CGFloat = min(theMaxWidth, (containerWidth - CGFloat(subviews.count - 1) * theSpacing) / CGFloat(subviews.count)) | ||
|
||
// align trailing | ||
var x: CGFloat = bounds.minX + subviewWidth / 2 + bounds.size.width - subviewWidth * CGFloat(subviews.count) - totalSpacing | ||
var y = bounds.midY | ||
var anchor = UnitPoint.center | ||
switch self.alignment { | ||
case .top: | ||
y = bounds.minY | ||
anchor = .top | ||
case .bottom: | ||
y = bounds.maxY | ||
anchor = .bottom | ||
default: | ||
y = bounds.midY | ||
anchor = .center | ||
} | ||
for i in subviews.indices { | ||
subviews[i].place(at: CGPointMake(x, y), | ||
anchor: anchor, | ||
proposal: ProposedViewSize(width: subviewWidth, height: self.isSameHeight ? maxHeight : subViewSizes[i].height)) | ||
x += subviewWidth + theSpacing | ||
} | ||
} | ||
} | ||
|
||
#Preview("layout top") { | ||
EqualWidthWithMaxWidthHStackLayout(spacing: 8, alignment: .top) { | ||
FioriButton(title: "Save") | ||
.border(Color.green) | ||
Text("Decline") | ||
.border(Color.green) | ||
}.border(Color.gray) | ||
} | ||
|
||
#Preview("layout center") { | ||
EqualWidthWithMaxWidthHStackLayout(spacing: 8, alignment: .center) { | ||
FioriButton(title: "Save") | ||
.frame(maxWidth: .infinity) | ||
.border(Color.green) | ||
Text("Decline") | ||
.border(Color.green) | ||
}.border(Color.gray) | ||
} | ||
|
||
#Preview("layout bottom") { | ||
EqualWidthWithMaxWidthHStackLayout(spacing: 8, alignment: .bottom, maxWidth: 120) { | ||
FioriButton(title: "Save") | ||
.frame(maxWidth: .infinity) | ||
.border(Color.green) | ||
|
||
Text("Decline") | ||
.frame(maxWidth: .infinity) | ||
.border(Color.green) | ||
}.border(Color.gray) | ||
} |
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,28 @@ | ||
import SwiftUI | ||
|
||
struct OptionalImage: View { | ||
let image: Image? | ||
|
||
init(_ image: Image?) { | ||
self.image = image | ||
} | ||
|
||
var body: some View { | ||
if let image { | ||
image | ||
.resizable() | ||
} else { | ||
EmptyView() | ||
} | ||
} | ||
} | ||
|
||
extension OptionalImage: _ViewEmptyChecking { | ||
var isEmpty: Bool { | ||
self.image == nil | ||
} | ||
} | ||
|
||
#Preview { | ||
OptionalImage(Image(systemName: "square.and.arrow.up.circle")) | ||
} |
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,30 @@ | ||
import SwiftUI | ||
|
||
struct OptionalKPIItem: View { | ||
let data: KPIItemData? | ||
|
||
init(_ data: KPIItemData?) { | ||
self.data = data | ||
} | ||
|
||
var body: some View { | ||
if let d = data { | ||
KPIItem(data: d) | ||
} else { | ||
EmptyView() | ||
} | ||
} | ||
} | ||
|
||
extension OptionalKPIItem: _ViewEmptyChecking { | ||
var isEmpty: Bool { | ||
self.data == nil | ||
} | ||
} | ||
|
||
#Preview { | ||
OptionalKPIItem(KPIItemData.components([.icon(Image(systemName: "arrowtriangle.up.fill")), | ||
.unit("$"), | ||
.metric("26.9"), | ||
.unit("M")])) | ||
} |
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.