Skip to content

Instantly share code, notes, and snippets.

@myurieff
myurieff / example.swift
Created February 8, 2023 15:20
TCA Inputs Outputs
struct SomeFeature: ReducerProtocol {
struct State: Equatable {}
enum Action: Equatable {
case didAppear
case refreshData
case didComplete
}
struct Input {
var shouldRefresh: () -> AsyncStream<Void>
@myurieff
myurieff / InputField.swift
Last active May 29, 2023 10:18
SwiftUI TCA Validated Input Field
public enum InputField<Value: Equatable> {
/// The state of current input validation
public enum InputValidation: Equatable {
/// A value that has undergone validation and is found to be valid.
case valid(Value)
/// A value that has undergone validation and is found to be invalid.
/// Optionally, a feedback message can be displayed to the user
/// to let them know what the issue with their input is.
/// For example: "Please enter a value between 10 and 100."
case invalid(Value, feedback: String?)
@myurieff
myurieff / CounterTransition.swift
Last active July 24, 2022 14:33
Counter Transition effect in SwiftUI
import SwiftUI
public extension AnyTransition {
static var carousel: AnyTransition {
.asymmetric(
insertion: .move(edge: .top)
.combined(
with: .modifier(
active: CarouselTransitionModifier(state: .insert),
identity: CarouselTransitionModifier(state: .identity)
@myurieff
myurieff / AsyncActivityItemProvider.swift
Created September 26, 2019 14:45
Async activity item. How to provide data to share after the activityController is presented and the activityType is selected.
import UIKit
/// Allows for asynchronously providing an item that will be shared
/// in an UIActivityViewController instance.
///
/// ### Usage: ###
/// ```
/// let activityItem = AsyncActivityItemProvider(placeholderItem: placeholderItem) { [weak self] (activityType, handler) in
/// // ⚠️ We're in a background thread.
///
@discardableResult
public func with<T>(_ value: T, _ builder: (T) -> Void) -> T {
builder(value)
return value
}
@discardableResult
public func with<T>(_ value: T, _ builder: (T) throws -> Void ) rethrows -> T {
try builder(value)
return value
@myurieff
myurieff / Rx+Animated.swift
Created May 18, 2019 18:50
Simple animatable bindings using RxSwift + RxCocoa
// Our binder will work universally for every UIView subclass.
extension Reactive where Base: UIView {
/// Provides an observer that will animate incoming values.
///
/// - Parameters:
/// - keyPath: keyPath to the property that will be mutated and animated.
/// - animator: the animator instance that will be used to animate changes.
/// - Returns: a Binder instance.
public func animated<Value>(