Skip to content

Instantly share code, notes, and snippets.

Thomas Visser Thomvis

Block or report user

Report or block Thomvis

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View StateDrivenNavigationView.swift
import SwiftUI
private final class StateDrivenNavigationController<V>: NSObject, UIViewControllerRepresentable, UIDocumentPickerDelegate where V: Hashable {
let stack: [V]
let content: (V) -> AnyView
let onStackChanged: ([V]) -> Void
init(stack: [V], onStackChanged: @escaping ([V]) -> Void, content: @escaping (V) -> AnyView) {
self.stack = stack
View NavigationViewActiveIssue.swift
import SwiftUI
struct ContentView: View {
@State var tab = 0
@State var selections: [Int: Int] = [:]
var body: some View {
ZStack {
TabView {
View CV+ScrollView.swift
// ContentView.swift
// FlowLayoutST
// Created by Chris Eidhof on 22.08.19.
// Copyright © 2019 Chris Eidhof. All rights reserved.
import SwiftUI
struct FlowLayout {
Thomvis / UIControlEventPublisher.swift
Last active Jul 4, 2019
View UIControlEventPublisher.swift
class ActionTarget {
let handler: () -> Void
init(handler: @escaping () -> Void) {
self.handler = handler
@IBAction func handle() {
Thomvis / FunctionView.swift
Created Jun 7, 2019
Function components are a thing in React. Here's what they look like in SwiftUI.
View FunctionView.swift
func ShieldIcon(ac: Int) -> some View {
ZStack {
Image(systemName: "shield")
Thomvis / SwiftUI-Circular.swift
Last active Jun 27, 2019
Rough attempt at creating a container view that lays out its children in a circle #SwiftUI
View SwiftUI-Circular.swift
struct ContentView: View {
@State var count: Int = 3
var body: some View {
return NavigationView {
VStack(spacing: 50) {
HStack {
Button(action: { self.count += 1 }) {
Thomvis / gist:dac2327ea253ed2c3ed6bd3dc13a95f2
Created Jun 6, 2019
Thought it would be nice to create a custom stack implementation. Immediately ran into all kinds of walls.
View gist:dac2327ea253ed2c3ed6bd3dc13a95f2
struct Stack<Item>: View where Item: View {
let items: [Item]
init(@ViewBuilder items: () -> Item) {
fatalError("How to get the views out of the view builder's result (TupleView) into self.items?")
var body: some View {
fatalError("How to layout self.items in a Group/ZStack?")
return EmptyView()
type loadableData('e) =
| Loading
| Loaded(list('e));
type loadableDataAction('e) =
| DidLoad(list('e));
type state = {data: loadableData(Api.product)};
/* Action declaration */
View TransformIgnoringSafeAreaInsetsView.swift
// This view overrides safeAreaInsets in order to work around
// (possibly erroneous) behavior of UIKit where safe area insets change
// when a view is transformed. (see
// Use this view as the direct subview of the view that has the transform applied.
// This view's frame should be equal to the superview's bounds for this to work.
@objc public class TransformIgnoringSafeAreaInsetsView: UIView {
@available(iOS 11.0, *)
override public var safeAreaInsets: UIEdgeInsets {
guard let superview = self.superview, superview.transform != .identity else {
Thomvis /
Created May 19, 2017
To the person that asked me a question about backpressure after my talk at UIKonf to which I said "Let's talk about it over lunch" and wasn't able to find...

I didn't cover backpressure because it is quite complex and - from my experience - not a core concept of reactive programming for mobile development. Some implementations do have it (e.g. RxJava), but to my knowledge none of the (big) iOS implementations, such as RxSwift and ReactiveSwift, have support for it. I use RxJava, but have never really needed its backpressure capabilities.

Adding backpressure to my minimal reactive programming implementation would require a layer of indirection that would establish the backchannel needed to allow for backpressure. It could look something like this:

o.subscribe { producer in
  producer.observe {
    // $0 is every element as it gets emitted
    producer.request(1) // makes sure the number of requested events stays 5 (requests are additive)
You can’t perform that action at this time.