Skip to content

Instantly share code, notes, and snippets.

@fbradyirl
Created July 23, 2020 12:39
Show Gist options
  • Save fbradyirl/4e28c41c27bb63ac0d05de5b39fa32dc to your computer and use it in GitHub Desktop.
Save fbradyirl/4e28c41c27bb63ac0d05de5b39fa32dc to your computer and use it in GitHub Desktop.
SwiftUI Wrapper for a view which is pending real data. Uses new .redacted(reason: .placeholder) in SwiftUI for iOS 14, macOS 11
//
// PendingView.swift
// Dream Stream
//
// Created by Finbarr Brady on 23/07/2020.
//
import SwiftUI
struct PendingView<Content: View>: View {
var isRedacted = true
let content: Content
init(isRedacted: Bool, @ViewBuilder content: () -> Content) {
self.content = content()
self.isRedacted = isRedacted
}
var body: some View {
if self.isRedacted {
content
.redacted(reason: .placeholder)
} else {
content
.unredacted()
}
}
}
struct PendingView_Previews: PreviewProvider {
static var previews: some View {
PendingView(isRedacted: true) {
NavigationView {
Form {
Text("test")
.font(.largeTitle)
Text("test")
Text("Longer Line I can see here")
Text("test")
HStack(spacing: 12) {
RoundedRectangle(cornerRadius: 4)
.foregroundColor(Color.blue)
.frame(width: 24, height: 24)
.overlay(
RoundedRectangle(cornerRadius: 4)
.stroke(Color("StrokeColor"), lineWidth: 1)
)
Text("Blue Color showing here")
Spacer()
}
Text("What about this thing")
HStack {
Image(systemName: "gear")
Toggle("This is a big decision", isOn: .constant(false))
}
HStack(spacing: 12) {
RoundedRectangle(cornerRadius: 4)
.foregroundColor(Color.red)
.frame(width: 24, height: 24)
.overlay(
RoundedRectangle(cornerRadius: 4)
.stroke(Color("StrokeColor"), lineWidth: 1)
)
Text("Red Color showing here")
Spacer()
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment