Last active
August 7, 2019 23:31
-
-
Save PaulWoodIII/3501cc61182b3e8c653ac84edaf36498 to your computer and use it in GitHub Desktop.
I wonder if Ari wants to use SwiftUI in Shortcuts
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
//: [Previous](@previous) | |
import SwiftUI | |
import PlaygroundSupport | |
struct SiriShortcutsActionCard<U>: View where U : StringProtocol { | |
let action: () -> () | |
let onMore:() -> () | |
let iconImage: AnyView | |
let title: U | |
let description: U | |
let color: Color | |
var body: some View { | |
ZStack{ | |
Button(action: { | |
self.action() | |
}) { | |
RoundedRectangle(cornerRadius: 20) | |
.foregroundColor(color) | |
} | |
Button(action: self.onMore) { | |
ZStack { | |
Circle() | |
.foregroundColor(Color(.sRGB, white: 1, opacity: 0.20)) | |
.frame(width: 26, height: 26, alignment: .topLeading) | |
Image(systemName: "ellipsis") | |
.font(.headline) | |
.foregroundColor(Color.white) | |
} | |
} | |
.frame(minWidth: 22, idealWidth: 22, maxWidth: .infinity, minHeight: 22, idealHeight: 22, maxHeight: .infinity, alignment: .topTrailing) | |
.padding() | |
.cornerRadius(22) | |
HStack { | |
VStack { | |
iconImage | |
.frame(maxWidth: 60, maxHeight: 60, alignment: .topTrailing) | |
.padding() | |
Spacer() | |
} | |
Spacer() | |
} | |
HStack{ | |
VStack(alignment: .leading) { | |
Spacer() | |
Text(title) | |
.font(.headline) | |
.lineLimit(1) | |
.foregroundColor(Color.white) | |
Text(description) | |
.font(.caption) | |
.lineLimit(2) | |
.foregroundColor(Color.white.opacity(0.70)) | |
}.padding() | |
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottomLeading) | |
} | |
} | |
} | |
} | |
let viewController = UIHostingController(rootView: | |
SiriShortcutsActionCard(action: { | |
print("card action clicked") | |
}, onMore: { | |
print("clicked more") | |
}, iconImage: AnyView( IconView(fetcher: ImageFetcher(url: URL(string: "https://appstoreconnect.apple.com/static/img/ico_homepage/themed/apps/Apps@2x.d3ce493e56172e92aed6.png")!) )), | |
title: "Shortcut Title", | |
description: "A few words on this subject perhaps I should write enough to be two lines", | |
color: Color(.sRGB, red: 0.429, green: 0.477, blue: 0.746, opacity: 1.0)) | |
.frame(width: 300, height: 150, alignment: .center) | |
) | |
PlaygroundPage.current.liveView = viewController | |
//: [Next](@next) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment