Skip to content

Instantly share code, notes, and snippets.

View nathantannar4's full-sized avatar

Nathan Tannar nathantannar4

View GitHub Profile
@nathantannar4
nathantannar4 / Run an animation when a value changes
Created August 25, 2023 06:51
SwiftUI ChangeEffect ViewModifier
import SwiftUI
struct ContentView: View {
@State var counter: Int = 0
var body: some View {
VStack(spacing: 24) {
Image(systemName: "exclamationmark.triangle.fill")
.font(Font.system(size: 50))
//
// Copyright (c) Nathan Tannar
//
import SwiftUI
import Engine // https://github.com/nathantannar4/Engine
import Turbocharger // https://github.com/nathantannar4/Turbocharger
import Transmission // https://github.com/nathantannar4/Transmission
#if os(iOS)
import UIKit
protocol IView: AnyObject where Self: UIView {
func viewDidLoad()
func viewWillAppear(_ animated: Bool)
func viewDidAppear(_ animated: Bool)
func viewWillDisappear(_ animated: Bool)
func viewDidDisappear(_ animated: Bool)
}
import UIKit
class Controller<RootViewType: IView>: UIViewController {
var rootView: RootViewType! {
return view as? RootViewType
}
// MARK: - View Life Cycle
import UIKit
class TextFieldCell: RowView<UILabel, TextField, UIView> {
var label: UILabel { return leftView }
var textField: TextField { return rightView }
}
class TextViewCell: RowView<UILabel, InputTextView, UIView> {
var label: UILabel { return leftView }
var textView: InputTextView { return rightView }
import UIKit
class RowView<LeftViewType: UIView, RightViewType: UIView, AccessoryViewType: UIView>: View {
let leftView = LeftViewType()
let rightView = RightViewType()
let accessoryView = AccessoryViewType()
override func viewDidLoad() {
super.viewDidLoad()
import UIKit
protocol IReusableView: AnyObject where Self: UIView {
func prepareForReuse()
}
class TableViewCell<ViewType: IReusableView>: UITableViewCell {
let wrappedView = ViewType()
import UIKit
class ViewModelController<ViewModelType: IViewModel>: UIViewController {
let viewModel: ViewModelType
required init(viewModel: ViewModelType) {
self.viewModel = viewModel
super.init(nibName: nil, bundle: nil)
}
@nathantannar4
nathantannar4 / Switch.swift
Created December 21, 2018 00:43
Re-Engineering Switch Outline
class Switch: UIControl {
var isOn: Bool
// Determines if the thumbLayer stretches on touchDown
var isStretchEnable: Bool
// Border of the trackLayer, this also determines the inset of the innerLayer
var borderWidth: CGFloat
@nathantannar4
nathantannar4 / Switch.swift
Created December 20, 2018 23:57
Re-Engineering UISwitch
//
// Switch.swift
// Re-Engineering UISwitch
//
// Created by Nathan Tannar on 15/12/18.
// Copyright © 2018 Nathan Tannar. All rights reserved.
//
import UIKit