This repository has been archived by the owner on Dec 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e9eb14f
commit 9df363d
Showing
19 changed files
with
405 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
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,69 @@ | ||
{ | ||
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json", | ||
"type": "AdaptiveCard", | ||
"version": "1.0", | ||
"body": [ | ||
{ | ||
"type": "TextBlock", | ||
"text": "Here are some cool photos", | ||
"size": "large" | ||
}, | ||
{ | ||
"type": "TextBlock", | ||
"text": "from picsum.photos", | ||
"size": "medium", | ||
"weight": "lighter", | ||
"spacing": "none" | ||
}, | ||
{ | ||
"type": "ImageSet", | ||
"images": [ | ||
{ | ||
"type": "Image", | ||
"url": "https://picsum.photos/200/200?image=100", | ||
"altText": "White beach panorama" | ||
}, | ||
{ | ||
"type": "Image", | ||
"url": "https://picsum.photos/300/200?image=200", | ||
"altText": "Cow on a grassy field" | ||
}, | ||
{ | ||
"type": "Image", | ||
"url": "https://picsum.photos/300/200?image=301", | ||
"altText": "Orange leaves on the sidewalk of a park" | ||
}, | ||
{ | ||
"type": "Image", | ||
"url": "https://picsum.photos/200/200?image=400", | ||
"altText": "Green leaves" | ||
}, | ||
{ | ||
"type": "Image", | ||
"url": "https://picsum.photos/300/200?image=500", | ||
"altText": "Top of a sky scrapper" | ||
}, | ||
{ | ||
"type": "Image", | ||
"url": "https://picsum.photos/200/200?image=600", | ||
"altText": "Foggy forest" | ||
}, | ||
{ | ||
"type": "Image", | ||
"url": "https://picsum.photos/300/200?image=700", | ||
"altText": "Picure of the blue ocean" | ||
}, | ||
{ | ||
"type": "Image", | ||
"url": "https://picsum.photos/300/200?image=800", | ||
"altText": "Crowded train station" | ||
}, | ||
{ | ||
"type": "Image", | ||
"url": "https://picsum.photos/300/200?image=900", | ||
"altText": "Sunset under a dock" | ||
} | ||
] | ||
} | ||
] | ||
} |
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
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
15 changes: 15 additions & 0 deletions
15
Sources/AdaptiveCardUI/Logic/ToggleVisibility/Image+Toggleable.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,15 @@ | ||
import Foundation | ||
|
||
extension Image: Toggleable { | ||
mutating func toggleVisibility(of target: TargetElement) -> Bool { | ||
guard id == target.elementId else { return false } | ||
|
||
if let isVisible = target.isVisible { | ||
self.isVisible = isVisible | ||
} else { | ||
isVisible.toggle() | ||
} | ||
|
||
return true | ||
} | ||
} |
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 DefaultCodable | ||
import Foundation | ||
|
||
public enum MediumImageSize: DefaultValueProvider { | ||
public static var `default` = ImageSize.medium | ||
} | ||
|
||
/// The `ImageSet` element displays a collection of images. | ||
public struct ImageSet: CardElementProtocol, Codable, Equatable { | ||
/// A unique identifier associated with the item. | ||
@ItemIdentifier public var id: String | ||
|
||
/// If `false`, this item will be removed from the visual tree. | ||
@Default<True> public var isVisible: Bool | ||
|
||
/// When `true`, draw a separating line at the top of the element. | ||
@Default<False> public var separator: Bool | ||
|
||
/// Controls the amount of spacing between this element and the preceding element. | ||
@Default<FirstCase> public var spacing: Spacing | ||
|
||
/// Describes what to do when an unknown element is encountered or the requires of this or any children can’t be met. | ||
@Default<Fallback.None> public var fallback: Fallback<CardElement> | ||
|
||
/// A series of key/value pairs indicating features that the item requires with corresponding minimum version. | ||
/// When a feature is missing or of insufficient version, fallback is triggered. | ||
@Default<EmptyDictionary> public var requires: [String: SemanticVersion] | ||
|
||
/// The array of `Image` elements to show. | ||
public var images: [Image] | ||
|
||
/// Controls the approximate size of each image. | ||
/// | ||
/// `auto` and `stretch` are not supported for ImageSet. The size will | ||
/// default to `medium` if those values are set. | ||
@Default<MediumImageSize> public var imageSize: ImageSize | ||
|
||
public init( | ||
id: String = "", | ||
isVisible: Bool = true, | ||
separator: Bool = false, | ||
spacing: Spacing = .default, | ||
fallback: Fallback<CardElement> = .none, | ||
requires: [String: SemanticVersion] = [:], | ||
images: [Image], | ||
imageSize: ImageSize = .medium | ||
) { | ||
self.id = id | ||
self.isVisible = isVisible | ||
self.separator = separator | ||
self.spacing = spacing | ||
self.fallback = fallback | ||
self.requires = requires | ||
self.images = images | ||
self.imageSize = imageSize | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#if canImport(SwiftUI) | ||
|
||
import SwiftUI | ||
|
||
// Adapted from https://gist.github.com/chriseidhof/3c6ea3fb2102052d1898d8ea27fbee07 | ||
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) | ||
struct FlowLayout { | ||
private let proposedSize: CGSize | ||
private let horizontalSpacing: CGFloat | ||
private let verticalSpacing: CGFloat | ||
|
||
private var position = CGPoint.zero | ||
private var lineHeight: CGFloat = 0 | ||
|
||
var size: CGSize { | ||
CGSize(width: proposedSize.width, height: position.y + lineHeight) | ||
} | ||
|
||
init(proposedSize: CGSize, horizontalSpacing: CGFloat, verticalSpacing: CGFloat) { | ||
self.proposedSize = proposedSize | ||
self.horizontalSpacing = horizontalSpacing | ||
self.verticalSpacing = verticalSpacing | ||
} | ||
|
||
mutating func addElementWithSize(_ size: CGSize) -> CGRect { | ||
if position.x + size.width > proposedSize.width { | ||
position.x = 0 | ||
position.y += lineHeight + verticalSpacing | ||
lineHeight = 0 | ||
} | ||
|
||
let result = CGRect(origin: position, size: size) | ||
|
||
lineHeight = max(lineHeight, size.height) | ||
position.x += size.width + horizontalSpacing | ||
|
||
return result | ||
} | ||
} | ||
|
||
#endif |
Oops, something went wrong.