Skip to content

Instantly share code, notes, and snippets.

Avatar

Shaun Donnelly shaundon

View GitHub Profile
@shaundon
shaundon / NavigationStack.swift
Created Jul 24, 2022
Proof of concept of a NavigationStack not updating when a value changes
View NavigationStack.swift
import SwiftUI
struct ContentView: View {
@State private var foo: String? = nil
var body: some View {
// Change this to `NavigationView` and it'll work.
NavigationStack {
@shaundon
shaundon / ImageRendererPoC.swift
Last active Jun 10, 2022
Proof of concept of using a SwiftUI `ImageRenderer` with a map, and how it blanks out the map.
View ImageRendererPoC.swift
import SwiftUI
import MapKit
struct ContentView: View {
@State private var mapRegion = MKCoordinateRegion(
center: CLLocationCoordinate2D(
latitude: 51.5,
longitude: -0.12
),
View ScrollingEmojiView.swift
import SwiftUI
struct ScrollingEmojiView: View {
@Environment(\.accessibilityReduceMotion) var reduceMotion
@State private var isAnimating = false
let rows = 15
/*
In Personal Best (getpersonalbest.com) I get a random emoji to represent a workout type,
@shaundon
shaundon / ScreenshotView.swift
Created Dec 15, 2021
Proof of concept of code to take a screenshot of a view in SwiftUI.
View ScreenshotView.swift
import SwiftUI
struct ScreenShotView: View {
var body: some View {
GeometryReader { geo in
VStack {
Text("Hello world")
Button("Take screenshot") {
let generatedImage = self.takeScreenshot(
@shaundon
shaundon / InstagramShareView.swift
Created Jul 6, 2021
Proof of concept of sharing to Instagram Stories from SwiftUI
View InstagramShareView.swift
import SwiftUI
struct InstagramShareView: View {
var imageToShare: Image {
// An image defined in your app's asset catalogue.
return Image("SomeImage")
}
var body: some View {
@shaundon
shaundon / ContentView.swift
Created Mar 4, 2021
MapView with polyline support in SwiftUI
View ContentView.swift
import SwiftUI
import MapKit
struct ContentView: View {
@State private var region = MKCoordinateRegion(
// Apple Park
center: CLLocationCoordinate2D(latitude: 37.334803, longitude: -122.008965),
span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01)
)
@shaundon
shaundon / WorkoutSplit.swift
Created Feb 21, 2021
Convert an array of HKQuantitySample into splits.
View WorkoutSplit.swift
import Foundation
import HealthKit
struct WorkoutSplit: Hashable {
let label: String
let distance: HKQuantity
let duration: TimeInterval
}
extension WorkoutSplit {
@shaundon
shaundon / ContentView.swift
Last active Jul 4, 2022
PHPicker in SwiftUI
View ContentView.swift
import SwiftUI
struct ContentView: View {
@State private var showPhotoSheet = false
@State private var image: UIImage? = nil
var body: some View {
VStack {
Button(action: { showPhotoSheet = true }) {
Label("Choose photo", systemImage: "photo.fill")
View bongos.js
/*
Adds an input to bongo.cat so you can preset your own tunes.
*/
(() => {
const simulateKey = (simKey) => {
var instrument = InstrumentPerKeyEnum[simKey.toUpperCase()];
var key = KeyEnum[simKey.toUpperCase()];
if (instrument !== undefined && key !== undefined) {
$.play(instrument, key, true);
View Heading.swift
import SwiftUI
struct Heading: View {
let title: String
let accessoryView: AnyView?
init(
_ title: String,
accessoryView: AnyView? = nil
) {