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
@Thomvis
Thomvis / UIControlEventPublisher.swift
Last active Jul 4, 2019
UIControlEventPublisher.swift
View UIControlEventPublisher.swift
class ActionTarget {
let handler: () -> Void
init(handler: @escaping () -> Void) {
self.handler = handler
}
@IBAction func handle() {
handler()
}
@Thomvis
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")
.font(.title)
Text("\(ac)")
.font(.caption)
}
}
@Thomvis
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 }) {
Text("Add")
}
@Thomvis
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()
View ProductList.re
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 http://www.openradar.me/35532074)
//
// 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
Thomvis / backpressure.md
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...
View backpressure.md

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)
  }
View DependencyInjection.stencil
import Dispatch
public typealias Provider<E> = () -> E
class Container {
{% for type in types.all %}
{% if type|annotated:"singleton" %}
private let {{type.name|lowerFirstWord}}Queue = DispatchQueue(label: "singleton:{{type.name|lowerFirstWord}}")
private var __{{type.name|lowerFirstWord}}: {{type.name}}?
View DependencyContainer.swift
// Generated using Sourcery 0.5.9 — https://github.com/krzysztofzablocki/Sourcery
// DO NOT EDIT
import Dispatch
public typealias Provider<E> = () -> E
class Container {
private let apiServiceQueue = DispatchQueue(label: "singleton:apiService")
View MockGen.stencil
import Mimus
{% for type in types.protocols %}
{% if type.annotations.genMock %}
class {{ type.name }}Mock: {{ type.name }}, Mock {
var storage: [RecordedCall] = []
{% for method in type.allMethods %}
func {{ method.name }} {
You can’t perform that action at this time.