Skip to content

Instantly share code, notes, and snippets.

View chriseidhof's full-sized avatar

Chris Eidhof chriseidhof

View GitHub Profile
//
import SwiftUI
struct ContentView: View {
@State var progress: Double = 0
var body: some View {
VStack {
Slider(value: $progress, in: 0...1)
Text("Hello, world")
//
import SwiftUI
struct Helper<Result: View>: _VariadicView_MultiViewRoot {
var _body: (_VariadicView.Children) -> Result
func body(children: _VariadicView.Children) -> some View {
_body(children)
}
//
import SwiftUI
struct MyTextEditor: NSViewRepresentable {
@Binding var text: String
final class Coordinator: NSObject, NSTextViewDelegate {
var text: Binding<String>
//
import SwiftUI
struct ContentView: View {
@State private var toggle = true
@Namespace private var ns
var body: some View {
let box = Rectangle()
.fill(.tertiary)
@chriseidhof
chriseidhof / SimpleRepresentable.swift
Last active September 8, 2023 07:12 — forked from vincefried/SimpleRepresentable.swift
A small demonstration of how I would like a way to modify a wrapped UIView.
import UIKit
import SwiftUI
struct ContentView2: View {
var body: some View {
VStack {
SimpleRepresentable(text: "Test")
}
}
}
//
import SwiftUI
struct MyProgress: View, Animatable {
var progress: Double
var animatableData: Double {
get { progress }
set { progress = newValue }
@chriseidhof
chriseidhof / ContentView.swift
Created August 30, 2023 13:12
OnAppearVsTask
import SwiftUI
struct ContentView: View {
@State private var color0 = Color.red
@State private var color1 = Color.red
var body: some View {
VStack {
color0
color1
}
//
import SwiftUI
import Observation
// easeInBounce
//
// https://easings.net
// https://gist.github.com/girish3/11167208
@chriseidhof
chriseidhof / .swiftlint.yml
Created February 7, 2023 09:59
SwiftLint rules for state, state object, environment and scaled metric
disabled_rules:
- trailing_comma
opt_in_rules:
- file_header
file_header:
forbidden_pattern: /./
custom_rules:
state_private:
name: "Private SwiftUI State"
regex: "\\@State\\s*var"
@chriseidhof
chriseidhof / ViewToPDF.swift
Created January 6, 2023 15:46
Image Rendering
import SwiftUI
extension View {
@MainActor
func pdf(size: ProposedViewSize) -> Data {
let renderer = ImageRenderer(content: self)
renderer.proposedSize = size
var pdfData = NSMutableData()
renderer.render { size, render in
var mediaBox = CGRect(origin: .zero, size: size)