Skip to content

Instantly share code, notes, and snippets.

import SwiftUI
/// Animated volume widget like the one on the iPhone Control Center, used like this:
///
/// SpeakerVolumeView(volumeSetting: self.volumeSetting)
/// .frame(height: 123)
///
/// Only need to constrain the height dimension, this widget set its width accordingly
///
/// volumeSetting: indicates the volume value 0...1
/*
Note:
- To disable all shadows, comment out all .modifier(Emboss()) and .modifier(Deboss())
- Search for .drawingGroup(), uncomment it to see it kills all shadows
*/
import SwiftUI
// Problem with Timer.publisher not work in navigation stack
//
// Timer.publisher *do not* fire reliably if the View is shown through NavigationLink()
// Work fine if it's not inside navigation stack
//
// The Pointfree Publisher.Timer do not fire at all when navigate in
// but start receiving timer when pop back out navigation stack
// run debug preview and watch print message in .onReceive()
import SwiftUI
protocol Record: Equatable {
func save()
}
extension Record {
func save() {
// save to disk
print("Record: Disk")
}
}
// https://twitter.com/jsngr/status/1282116429152751617
import SwiftUI
struct AppleRemote: View {
var body: some View {
VStack(spacing: 24) {
Text("Apple TV")
.font(.headline)
import SwiftUI
struct SimpleAnimation: View {
// In Xcode preview? animation doesn't work
// animate only if these are set to true
// why when set to false, no animation?
@State var flag = false
@State var anotherFlag = true
var body: some View {
//
// PlayButtonOffsetProblem.swift
// NewWorld12
//
// Created by Matthew on 7/21/20.
//
import SwiftUI
struct KeyboardAvoidance: View {
@State var text = ""
var body: some View {
VStack {
// Only work if something is added below the list
TextField("Enter", text: $text)
List {
ForEach(1...50, id: \.self) {
Text("More \($0)")
import SwiftUI
struct RedactedReasonReplaceIsPlaceholder: View {
@Environment(\.redactionReasons) private var redactionReason
let junk: RedactionReasons = .placeholder
var body: some View {
VStack {
Text("Want this to be shown even when redacted!")
.redacted(reason: .init())
import SwiftUI
struct AnimateForever: View {
@State private var flag = false
var body: some View {
VStack {
Rectangle()
// on rectangle, foregroundColor() animate