Skip to content

Instantly share code, notes, and snippets.

View ryanlintott's full-sized avatar

Ryan Lintott ryanlintott

View GitHub Profile
@ryanlintott
ryanlintott / ContentView.swift
Last active July 20, 2024 01:25
A SwiftUI environment value for the keyboard height that updates with animation. This is useful when you want a specific view in a stack to stick to the bottom of the keyboard when the keyboard moves up. Now included in FrameUp https://github.com/ryanlintott/FrameUp
import SwiftUI
struct ContentView: View {
var body: some View {
KeyboardAvoidingWithOffset()
.keyboardHeightEnvironmentValue()
}
}
struct KeyboardAvoidingWithOffset: View {
@ryanlintott
ryanlintott / NoClipTextRenderer.swift
Last active July 9, 2024 01:29
SwiftUI may be clipping your Text views but TextRenderer in iOS 18 might let you fix it in a far less hacky way. Hacky methods that support older OS versions can be found here: https://github.com/ryanlintott/Unicodices
//
// NoClipTextRenderer.swift
//
//
// Created by Ryan Lintott on 2024-07-08.
//
import SwiftUI
@available(iOS 18, *)
@ryanlintott
ryanlintott / CustomColorScheme.swift
Last active July 6, 2024 12:53
Custom color scheme view modifier for SwiftUI. Sets the color scheme to light mode, dark mode, or matches the system. If set to match, the app will respond to system-wide color scheme changes properly. A simple widget color scheme implementation is also provided.
import SwiftUI
enum CustomColorScheme: Int, CaseIterable, Identifiable, Codable {
static var defaultKey = "customColorScheme"
static var defaultValue = CustomColorScheme.system
case system = 0
case light = 1
case dark = 2
@ryanlintott
ryanlintott / AnimatablePack.swift
Last active June 18, 2024 17:23
AnimatablePair is limited to only two values. You can nest AnimatablePair to add more values but theres a lot of repetition and using .first.second.first etc… when accessing the values. Now that we have access to Swift 6 with parameter pack iteration we could have an AnimatablePack. Similar to how view builders are no longer limited to 10 views …
//
// AnimatablePack.swift
// ShapeUp
//
// Created by Ryan Lintott on 2023-08-02.
//
/// AnimatablePack uses parameter pack iteration that is only available in swift 6.0
/// https://forums.swift.org/t/pitch-enable-pack-iteration/66168
#if compiler(>=6.0)
@ryanlintott
ryanlintott / AutoLayoutTestApp.swift
Last active March 8, 2024 04:33
A SwiftUI example of an alert window that would be easy to implement using AutoLayout. This implementation uses onSizeChange from FrameUp https://github.com/ryanlintott/FrameUp
//
// AutoLayoutTestApp.swift
// AutoLayoutTest
//
// Created by Ryan Lintott on 2024-03-07.
//
import FrameUp
import SwiftUI
@ryanlintott
ryanlintott / KeyboardButtonStyle.swift
Last active February 25, 2024 01:15
A SwiftUI ButtonStyle that looks like an iOS keyboard key.
//
// KeyboardButtonStyle.swift
// Wordhord
//
// Created by Ryan Lintott on 2024-02-06.
//
import ShapeUp
import SwiftUI
@ryanlintott
ryanlintott / ShrinkingLabel.swift
Last active February 21, 2024 18:31
An example of a label that grows and shrinks in overall size and frame height. Requires FrameUp https://github.com/ryanlintott/FrameUp
//
// ShrinkingLabel.swift
// FrameUpExample
//
// Created by Ryan Lintott on 2024-02-21.
//
import FrameUp
import SwiftUI
@ryanlintott
ryanlintott / ThemeListSelection.swift
Created February 12, 2024 20:54
A SwiftUI List where a single item is selected across Sections.
import SwiftUI
struct Theme: Identifiable {
let id: UUID
let name: String
}
extension Theme {
static let blue = Self(id: UUID(), name: "Blue")
static let red = Self(id: UUID(), name: "Red")
@ryanlintott
ryanlintott / LayoutThatFits.swift
Last active December 8, 2023 15:14
An alternative to ViewThatFits. Updated version can be found here: https://github.com/ryanlintott/LayoutThatFits
//
// LayoutThatFits.swift
// WWDC22Experiments
//
// Created by Ryan Lintott on 2022-06-08.
//
import SwiftUI
struct LayoutThatFits: Layout {
@ryanlintott
ryanlintott / GridAccessibilityTest.swift
Created October 23, 2023 19:20
SwiftUI Grid by default does not have a way to add accessibility labels to an entire row. This is an example workaround to provide that feature. It also provides a background view for each row but the colours can be set to Color.clear if you only want the accessibility label.
//
// GridAccessibilityTest.swift
// FrameUpExample
//
// Created by Ryan Lintott on 2023-10-22.
//
import FrameUp
import SwiftUI