[ad_1]
As a result of I need to use SwiftUI whereas concurrently supporting earlier iOS variations, I’ve needed to discover a totally different grid system. I’ve a easy design working, however I can not work out tips on how to do one thing with these views of mine. I’ve tried exhibiting alerts, including faucet gestures, nothing works. Am I simply making it out more durable than it must be?
Here is a picture of my interface, which is working fantastic, I simply can’t make these views to something! 
I based mostly my code off of this github repository: https://github.com/pietropizzi/GridStack/blob/grasp/Sources/GridStack/GridStack.swift
struct ContentView : View {
let colours: [Color] = [.red, .green, .blue, .yellow, .purple]
@State non-public var orientation = UIDeviceOrientation.unknown
@State non-public var showAlert = false
@State non-public var selectedShortcut: Int = 0 {
didSet {
showingHUD = false
}
}
@State non-public var showingHUD = true
var rows: CGFloat orientation == .unknown ? 5 : 3
var columns: CGFloat orientation == .unknown ? 3 : 5
var physique: some View {
GeometryReader { proxy in
GridStack(minCellWidth: (proxy.dimension.width / (columns + 1)), spacing: 6, numItems: 15) { index, cellWidth in
CardView(iconName: "star.fill", title: "(index + 1)", description: "(# (index + 1))", width: cellWidth, peak: (proxy.dimension.peak / (rows)) - 7)
.background(colours.randomElement())
.cornerRadius(10)
.onTapGesture {
selectedShortcut = index
showingHUD.toggle()
}
}
if showingHUD {
HUD {
Label("Shortcut: (selectedShortcut)", systemImage: "star.fill")
}
.transition(AnyTransition.transfer(edge: .prime).mixed(with: .opacity))
.onAppear {
DispatchQueue.major.asyncAfter(deadline: .now() + 3) {
withAnimation {
showingHUD = false
}
}
}
.zIndex(1)
}
}.background(Coloration.rgba(pink: 40, inexperienced: 40, blue: 40, alpha: 1))
.statusBar(hidden: true)
}
}
struct HUD<Content material: View>: View {
@ViewBuilder let content material: Content material
var physique: some View {
content material
.padding(.horizontal, 12)
.padding(16)
.background(
Capsule()
.foregroundColor(Coloration.white)
.shadow(coloration: Coloration(.black).opacity(0.16), radius: 12, x: 0, y: 5)
)
}
}
struct CardView: View {
var iconName: String
var title: String
var description: String
var width: CGFloat
var peak: CGFloat
var physique: some View {
VStack(alignment: .middle, spacing: 4) {
Picture(systemName: iconName)
.font(.system(dimension: 24))
.padding(.prime)
VStack(alignment: .main, spacing: 2) {
Textual content(description)
.lineLimit(2)
.multilineTextAlignment(.main)
}
.padding()
}.foregroundColor(.white)
.shadow(coloration: .darkGray, radius: 2, x: 2, y: 2)
.body(minWidth: width, maxWidth: width, minHeight: peak, maxHeight: peak)
// .onTapGesture {
// Alert(title: Textual content("Alert Title"), message: Textual content("Message"))
// }
}
}
[ad_2]
