Skip to content

Instantly share code, notes, and snippets.

View xspyhack's full-sized avatar
🏖️
Need a vacation

xspyhack

🏖️
Need a vacation
View GitHub Profile
@xspyhack
xspyhack / LazyVGrid.swift
Last active June 18, 2021 18:04
FB7812486: LazyVGrid poor performance
import SwiftUI
// https://developer.apple.com/documentation/swiftui/lazyvgrid
struct ContentView: View {
var columns: [GridItem] =
Array(repeating: .init(.flexible()), count: 4)
var body: some View {
ScrollView {
@xspyhack
xspyhack / GridPicker.swift
Created March 5, 2020 09:22
SwiftUI GridPicker
import SwiftUI
struct GridPicker<Data, Label, Content>: View where Data: RandomAccessCollection, Data.Index == Int, Data.Element: Hashable, Data.Element: Identifiable, Label: View, Content: View {
@Environment(\.gridPickerStyle) private var pickerStyle
typealias SelectionValue = Data.Element
let data: Data
let selection: Binding<SelectionValue>
@xspyhack
xspyhack / AutoLayoutDSL.swift
Last active March 20, 2019 08:36
A simple AutoLayout DSL
//: A UIKit based Playground for presenting user interface
import UIKit
import PlaygroundSupport
/// AutoLayout DSL extended from https://www.swiftbysundell.com/posts/building-dsls-in-swift
public protocol LayoutAnchor {
func constraint(equalTo anchor: Self,
constant: CGFloat) -> NSLayoutConstraint
@xspyhack
xspyhack / Player.swift
Created November 20, 2018 07:37
一种简单的控制播放器控制的方法
/// Queue player
struct Player {
/// The player status
///
/// - idle: before play
/// - waiting: means it is waiting for loading asset
/// - playing: now playing
/// - paused: paused
/// - stopped: end play