Skip to content

Instantly share code, notes, and snippets.

Avatar

Ryan Ashcraft ryanashcraft

View GitHub Profile
View PatchedHighPriorityGesture.swift
import SwiftUI
// Works around a critical issue observed on iPads with a trackpad cursor.
//
// With highPriorityGesture, other interactive content on the screen can become unresponsive after
// triggering the gesture with an iPad cursor. It's as if the gesture seems to never relinquish its
// grasp on the entire UI, until you interact with the screen directly with a tap or trigger a
// context menu.
//
// This view modifier and extension works around this by forcing the gesture to be "cancelled" by
@ryanashcraft
ryanashcraft / UIKitTabView.swift
Created Mar 25, 2021 — forked from Amzd/UIKitTabView.swift
UIKitTabView. SwiftUI tab bar view that respects navigation stacks when tabs are switched (unlike the TabView implementation)
View UIKitTabView.swift
/// An iOS style TabView that doesn't reset it's childrens navigation stacks when tabs are switched.
public struct UIKitTabView: View {
private var viewControllers: [UIHostingController<AnyView>]
private var selectedIndex: Binding<Int>?
@State private var fallbackSelectedIndex: Int = 0
public init(selectedIndex: Binding<Int>? = nil, @TabBuilder _ views: () -> [Tab]) {
self.viewControllers = views().map {
let host = UIHostingController(rootView: $0.view)
host.tabBarItem = $0.barItem
View LyricsDemoApp.swift
import SwiftUI
// Models
enum Lyric {
case line(String)
case pause(TimeInterval)
}
class ScrollToModel: ObservableObject {
View WidthGetterDemo.swift
import SwiftUI
struct WidthPreferenceKey: PreferenceKey {
typealias Value = CGFloat?
static var defaultValue: CGFloat?
static func reduce(value: inout CGFloat?, nextValue: () -> CGFloat?) {
if let nextValue = nextValue(), value != nextValue {
value = nextValue
View RemoteInspector.swift
import Foundation
public class RemoteInspector {
private struct UpdateMessage<T: Encodable>: Encodable {
let type = "update"
var id: String
var data: T
}
private struct LogMessage: Encodable {
@ryanashcraft
ryanashcraft / Using-NavigationDestinationLink.swift
Last active Jul 11, 2019
Here's a working implementation of controlled push/pop NavigationView actions in SwiftUI with NavigationDestinationLink.
View Using-NavigationDestinationLink.swift
View Memoized.swift
struct Memoized<A: Equatable, R> {
typealias Value = (_ params: A) -> R
var callback: Value
@XState private var prevParam: A? = nil
@XState private var prevValue: R? = nil
init(_ callback: @escaping Value) {
self.callback = callback
}
@ryanashcraft
ryanashcraft / NowPlayingView.jsx
Last active Jul 5, 2018
AmpliTunes without react-amplitude
View NowPlayingView.jsx
import React, { Fragment } from "react";
class NowPlayingView extends React.Component {
componentDidMount() {
this.props.logViewNowPlayingScreen();
}
componentDidUpdate = prevProps => {
if (prevProps.songId !== this.props.songId) {
this.props.logChangeSong(songId);
@ryanashcraft
ryanashcraft / NowPlayingView.jsx
Last active Jul 5, 2018
AmpliTunes with react-amplitude
View NowPlayingView.jsx
import React, { Fragment } from "react";
import { Amplitude, LogOnMount } from "@amplitude/react-amplitude";
const NowPlayingView = props => {
return (
<Amplitude
// All events logged in this subtree will include these event properties
eventProperties={inheritedProps => ({
...inheritedProps,
"song id": props.songId,
@ryanashcraft
ryanashcraft / Makefile
Last active Aug 4, 2017
Ghost on Docker Makefile
View Makefile
DOCKER_IMAGE ?= ryanashcraft/ghost:1.0
DOCKER_CONTAINER ?= ghost
dev:
docker build -f Dockerfile.dev -t $(DOCKER_IMAGE) .
docker rm $(DOCKER_CONTAINER) && docker run \
-p 2368:2368 \
-v ${PWD}/content/data:/var/www/ghost/content/data \
-v ${PWD}/content/images:/var/www/ghost/content/images \
--name $(DOCKER_CONTAINER) \