Skip to content

Instantly share code, notes, and snippets.

View Codelaby's full-sized avatar

Codelaby Codelaby

View GitHub Profile
@Codelaby
Codelaby / ContentView.swift
Created October 22, 2024 21:56 — forked from Lofionic/ContentView.swift
Shader fun
import SwiftUI
struct ContentView: View {
@State private var start = Date.now
var body: some View {
VStack {
TimelineView(.animation) { timeline in
let time = start.distance(to: timeline.date)
Rectangle()
import SwiftUI
struct CustomGlyphPicker: View {
@State private var name: String = "Default Name"
@State private var selectedImage: String = "defaultImage"
@State private var images: [String] = [
"face.smiling.inverse",
"list.bullet",
"house.fill",
"star.fill",
import SwiftUI
import AuthenticationServices
class AppleAuthViewModel: ObservableObject {
@Published var shouldShowAlert: Bool = false
@Published var alertTitle: String = ""
@Published var alertMessage: String = ""
//get notified when autherization state gets change
init() {
import Foundation
fileprivate extension String {
func containsConsecutiveCharacters(length: Int) -> Bool {
let characters = Array(self)
for i in 0..<(characters.count - length + 1) {
let substring = String(characters[i..<(i + length)])
if substring.allSatisfy({ $0 == substring.first }) {
return true
}
@Codelaby
Codelaby / MixedToggleStyle.swift
Created November 28, 2024 15:10
How to set Mixed toggle in SwiftUI
struct MixedToggleStyle: ToggleStyle {
func makeBody(configuration: Configuration) -> some View {
HStack {
configuration.label
Spacer()
Button {
configuration.isOn.toggle()
} label: {
@Codelaby
Codelaby / DebouncingTaskViewModifier.swift
Last active December 3, 2024 09:12
List music swift
struct DebouncingTaskViewModifier<ID: Equatable>: ViewModifier {
let id: ID
let priority: TaskPriority
let duration: Duration
let task: @Sendable () async -> Void
init(
id: ID,
priority: TaskPriority = .userInitiated,
duration: Duration = .nanoseconds(0),
@Codelaby
Codelaby / TwoListPlayground.swift
Created December 28, 2024 11:03
Drag drop two list swift
struct TwoListPlayground: View {
@State private var users1 = ["Paul", "Taylor", "Adele"]
@State private var users2 = ["Pauline", "Tom", "Adam"]
var body: some View {
VStack {
HStack {
Spacer()
@Codelaby
Codelaby / StreakActor.swift
Last active January 9, 2025 09:42
Streak Manager Swift
/*
Third Library based -> https://github.com/lukerobertsapps/LRStreakKit
*/
import Foundation
/// Data for a streak, codable so it can be persisted
struct Streak: Codable {
/// The length of the streak in days
var length: Int = 0
@Codelaby
Codelaby / CustomTextField.swift
Last active January 24, 2025 12:01
Floating Label input field by SwiftUI
import SwiftUI
fileprivate extension View {
@ViewBuilder func reverseMask<Mask: View>(
alignment: Alignment = .center,
@ViewBuilder _ mask: () -> Mask
) -> some View {
self.mask {
Rectangle()
@Codelaby
Codelaby / BezierGridView.swift
Created February 6, 2025 08:37 — forked from rygrob/BezierGridView.swift
Bézier Grid View
import SwiftUI
struct BezierGridView: View {
@State private var vertices: [[BezierVertex]]
let rows: Int
let cols: Int
init(rows: Int, cols: Int) {
self.rows = rows