Skip to content

Instantly share code, notes, and snippets.

View swiftui-lab's full-sized avatar

SwiftUI-Lab swiftui-lab

View GitHub Profile
@swiftui-lab
swiftui-lab / Inspecting-View-Tree-1a.swift
Last active March 16, 2022 09:40
Inspecting The View Tree - Compatible with Xcode 11, Beta 5
// The SwiftUI Lab: https://swiftui-lab.com
// Article: Inspecting the View Tree – Part 1
// https://swiftui-lab.com/communicating-with-the-view-tree-part-1/
import SwiftUI
struct EasyExample : View {
@State private var activeIdx: Int = 0
var body: some View {
// The SwiftUI Lab: https://swiftui-lab.com
// Article: Inspecting the View Tree – Part 1
// https://swiftui-lab.com/communicating-with-the-view-tree-part-1/
import SwiftUI
struct MyTextPreferenceKey: PreferenceKey {
typealias Value = [MyTextPreferenceData]
static var defaultValue: [MyTextPreferenceData] = []
// The SwiftUI Lab: https://swiftui-lab.com
// Article: Inspecting the View Tree – Part 2
// https://swiftui-lab.com/communicating-with-the-view-tree-part-2/
import SwiftUI
struct MyTextPreferenceData {
let viewIdx: Int
let bounds: Anchor<CGRect>
}
// The SwiftUI Lab: https://swiftui-lab.com
// Article: Inspecting the View Tree – Part 2
// https://swiftui-lab.com/communicating-with-the-view-tree-part-2/
import SwiftUI
struct MyTextPreferenceData {
let viewIdx: Int
var topLeading: Anchor<CGPoint>? = nil
var bottomTrailing: Anchor<CGPoint>? = nil
// The SwiftUI Lab: https://swiftui-lab.com
// Article: Inspecting the View Tree – Part 3
// https://swiftui-lab.com/communicating-with-the-view-tree-part-3/
import SwiftUI
enum MyViewType: Equatable {
case formContainer // main container
case fieldContainer // contains a text label + text field
case field(Int) // text field (with an associated value that indicates the character count in the field)
// The SwiftUI Lab: https://swiftui-lab.com
import SwiftUI
struct ContentView: View {
var body: some View {
Text("hello world!")
.padding(20)
.addBorder(Color.blue, width: 3.0, cornerRadius: 80)
}
}
struct ContentView: View {
@State private var flag = false
var body: some View {
GeometryReader { proxy in
ZStack(alignment: .topLeading) {
// Draw the Infinity Shape
InfinityShape().stroke(Color.purple, style: StrokeStyle(lineWidth: 5, lineCap: .round, lineJoin: .miter, miterLimit: 0, dash: [7, 7], dashPhase: 0))
.foregroundColor(.blue)
// Authoer: The SwiftUI Lab
// Full article: https://swiftui-lab.com/scrollview-pull-to-refresh/
import SwiftUI
struct RefreshableScrollView<Content: View>: View {
@State private var previousScrollOffset: CGFloat = 0
@State private var scrollOffset: CGFloat = 0
@State private var frozen: Bool = false
@State private var rotation: Angle = .degrees(0)
// Authoer: The SwiftUI Lab
// Full article: https://swiftui-lab.com/scrollview-pull-to-refresh/
import SwiftUI
import Combine
struct Dog: Identifiable {
let id = UUID()
let name:String
let picture: String
// Authoer: The SwiftUI Lab
// Full article: https://swiftui-lab.com/scrollview-pull-to-refresh/
import SwiftUI
struct ContentView: View {
@ObservedObject var model = MyModel()
@State private var alternate: Bool = true
let array = Array<String>(repeating: "Hello", count: 100)