Skip to content

Instantly share code, notes, and snippets.

import SwiftUI
struct CheckboxToggleStyle: ToggleStyle {
@Environment (\.isEnabled) var isEnabled
func makeBody(configuration: Configuration) -> some View {
HStack {
configuration.label
Image(systemName: configuration.isOn ? "checkmark.square" : "square")
import SwiftUI
struct UndoRightToLeftMirroring: ViewModifier {
// @Environment(\.layoutDirection) var layoutDirection
// @ViewBuilder
func body(content: Content) -> some View {
content // !!! Just do this undo the mirroring
// VStack {
// if layoutDirection == .leftToRight {
import SwiftUI
struct NavViewFormLabelRightJustified: View {
@State private var width = 25
@State private var height = 50
@State private var updatePeriod: Double = 1.0
var body: some View {
NavigationView {
Form {
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