Skip to content

Instantly share code, notes, and snippets.

View ryanlintott's full-sized avatar

Ryan Lintott ryanlintott

View GitHub Profile
@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 / 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 / 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 / ContentView.swift
Last active August 15, 2025 23:36
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 / 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
@ryanlintott
ryanlintott / WidgetConfiguration+extensions.swift
Last active May 5, 2025 19:59
Extensions for WidgetConfiguration that make it easier to add disfavoredLocations and promptsForUserConfiguration while supporting older versions of iOS.
//
// WidgetConfiguration+extensions.swift
//
//
// Created by Ryan Lintott on 2023-09-11.
//
import SwiftUI
import WidgetKit
@ryanlintott
ryanlintott / NavigationStackWithoutLine.swift
Created July 23, 2023 02:26
A SwiftUI NavigationStack with a custom background color and no line below the title.
struct NavigationStackWithoutLine: View {
let backgroundColor = Color.green
var body: some View {
NavigationStack {
ScrollView {
Text("Hello, world!")
.frame(maxWidth: .infinity)
.foregroundColor(.white)
}
.navigationTitle("Hello")
@ryanlintott
ryanlintott / Text+joined.swift
Last active July 10, 2023 15:13
An extension to Text that allows you to join an array of Text into a single Text with optional separators.
extension Collection where Element == Text {
func joined() -> Text {
reduce(into: Text("")) {
$0 = $0 + $1
}
}
func joined(separator: String) -> Text {
joined(separator: Text(separator))
}
@ryanlintott
ryanlintott / PreviewState.swift
Last active June 11, 2023 02:45
A wrapper to create any number of arbitrary state variables using parameter packs for testing bindable values in a preview.
import SwiftUI
struct PreviewState<each T, Content: View>: View {
@State private var value: (repeat each T)
var content: (Binding<(repeat each T)>) -> Content
init(
_ value: repeat each T,
@ViewBuilder content: @escaping (Binding<(repeat each T)>) -> Content
) {
@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)