Skip to content

Instantly share code, notes, and snippets.

View ryanlintott's full-sized avatar

Ryan Lintott ryanlintott

View GitHub Profile
@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.
View GridAccessibilityTest.swift
//
// GridAccessibilityTest.swift
// FrameUpExample
//
// Created by Ryan Lintott on 2023-10-22.
//
import FrameUp
import SwiftUI
@ryanlintott
ryanlintott / WidgetConfiguration+disfavoredLocationsIfAvailable.swift
Created September 11, 2023 18:49
Sets the disfavored locations for a widget if the option is available (iOS 17 and up). Otherwise returns the same configuration.
View WidgetConfiguration+disfavoredLocationsIfAvailable.swift
//
// 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.
View NavigationStackWithoutLine.swift
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.
View Text+joined.swift
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.
View PreviewState.swift
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 September 8, 2023 14:31
A parameter pack implementation of `AnimatablePair`. Started off as a weird idea but I think this version works. Now included in my ShapeUp SPM. https://github.com/ryanlintott/ShapeUp
View AnimatablePack.swift
//
// AnimatablePack.swift
// ShapeUp
//
// Created by Ryan Lintott on 2023-08-02.
//
import Foundation
import SwiftUI
@ryanlintott
ryanlintott / ListWithMoveUpAction.swift
Last active May 25, 2023 21:47
A list of items with accessibility action to move an item up.
View ListWithMoveUpAction.swift
struct ListWithMoveUpAction: View {
@AccessibilityFocusState private var focus: String?
@State private var users = ["Glenn", "Malcolm", "Nicola", "Terri"]
var body: some View {
NavigationStack {
List(users, id: \.self) { user in
Text(user)
.accessibilityActions {
Button {
@ryanlintott
ryanlintott / PagedSelectableView.swift
Created January 12, 2023 19:11
Draggable paged views where clicking the focused view triggers an action and clicking any other view scrolls to that view.
View PagedSelectableView.swift
//
// PagedSelectableView.swift
// FrameUpExample
//
// Created by Ryan Lintott on 2023-01-12.
//
import SwiftUI
struct PagedSelectableView: View {
@ryanlintott
ryanlintott / JustifiedTextExample2.swift
Last active November 16, 2022 04:54
A way to justify text using a single SwiftUI Text view.
View JustifiedTextExample2.swift
//
// JustifiedTextExample2.swift
// FrameUpExample
//
// Created by Ryan Lintott on 2022-11-15.
//
import SwiftUI
import WidgetKit
@ryanlintott
ryanlintott / DoubleScrollTabView.swift
Created November 14, 2022 06:43
A header that scrolls away, a sticky tab bar and two scrollviews that remember their position. A quick implementation made using FrameUp's SmartScrollView.
View DoubleScrollTabView.swift
//
// DoubleScrollTabView.swift
// FrameUpExample
//
// Created by Ryan Lintott on 2022-11-13.
//
import FrameUp
import SwiftUI