Skip to content

Instantly share code, notes, and snippets.


Dariusz Rybicki darrarski

View GitHub Profile
darrarski / SwiftUI_BottomBarViewModifier.swift
Created Jan 16, 2022
SwiftUI extension that adds bottom bar (like toolbar tor tabbar) to the provided view.
View SwiftUI_BottomBarViewModifier.swift
import SwiftUI
extension View {
func bottomBar<Bar: View>(
ignoresKeyboard: Bool = true,
frameChangeAnimation: Animation? = .default,
@ViewBuilder bar: @escaping () -> Bar
) -> some View {
ignoresKeyboard: ignoresKeyboard,
darrarski / SwiftUI_GeometryReaderViewModifier.swift
Last active Jan 16, 2022
SwiftUI extension that attaches geometry reader to a view and notifies whenever provided geometry changes.
View SwiftUI_GeometryReaderViewModifier.swift
import SwiftUI
extension View {
func geometryReader<Geometry: Codable>(
geometry: @escaping (GeometryProxy) -> Geometry,
onChange: @escaping (Geometry) -> Void
) -> some View {
geometry: geometry,
onChange: onChange
darrarski / SwiftUI_SizeChangeModifier.swift
Last active Aug 25, 2021
Swift UI vie modifier for retrieving the view size
View SwiftUI_SizeChangeModifier.swift
import SwiftUI
public extension View {
func onSizeChange(
ignoreSafeArea: Bool = false,
round: Bool = false,
perform action: @escaping (CGSize) -> Void
) -> some View {
ignoreSafeArea: ignoreSafeArea,
darrarski / SwiftUI_DeviceOrientationObserver.swift
Created Aug 23, 2021
SwiftUI CoreMotion driven DeviceOrientationObserver
View SwiftUI_DeviceOrientationObserver.swift
import CoreMotion
import SwiftUI
public final class DeviceOrientationObserver: ObservableObject {
public init() {
manager.startAccelerometerUpdates(to: OperationQueue.main) { [weak self] data, error in
guard error == nil, let acceleration = data?.acceleration else {
self?.value = .unknown
darrarski / SwiftUI_onInterfaceOrientationChange.swift
Created Aug 23, 2021
SwiftUI view modifier that performs action when UIInterfaceOrientation changes
View SwiftUI_onInterfaceOrientationChange.swift
import SwiftUI
public extension View {
/// Perform action when interface orientation of the view changes
/// - Parameter perform: Action to perform
/// - Returns: Modified view
func onInterfaceOrientationChange(perform: @escaping (UIInterfaceOrientation) -> Void) -> some View {
modifier(OnInterfaceOrientationChangeViewModifier(onChange: perform))
darrarski / SwiftUI_DeviceOrientationObserver.swift
Last active Jul 20, 2021
SwiftUI DeviceOrientationObserver
View SwiftUI_DeviceOrientationObserver.swift
import SwiftUI
public final class DeviceOrientationObserver: ObservableObject {
public init(notificationCenter: NotificationCenter = .default) {
observation = notificationCenter.addObserver(
forName: UIDevice.orientationDidChangeNotification,
object: nil,
queue: .main,
using: { [weak self] notification in
self?.value = (notification.object as? UIDevice)?.orientation ?? .unknown
darrarski / CaseSwitchable.swift
Created Jul 13, 2021
Swift `switch()` and `next()` extension for enums
View CaseSwitchable.swift
protocol CaseSwitchable: CaseIterable, Equatable {}
extension CaseSwitchable {
mutating func `switch`() {
self = next()
func next() -> Self { ?? Self.allCases.first!
darrarski / CaseTogglable.swift
Created Jul 13, 2021
Swift `toggle()` extension for enums
View CaseTogglable.swift
protocol CaseTogglable {}
extension CaseTogglable where Self: CaseIterable, Self: Equatable {
mutating func toggle() {
assert(Self.allCases.isEmpty == false, "CaseTogglable cannot be applied to an enum with no cases!")
let index = Self.allCases.firstIndex(of: self)!
let nextIndex = Self.allCases.index(after: index)
if nextIndex < Self.allCases.endIndex {
self = Self.allCases[nextIndex]
} else {
darrarski / App.swift
Created Apr 7, 2021
Lazy navigation in SwiftUI - animations issue
View App.swift
// Based on "Lazy navigation in SwiftUI" blogpost by Majid Jabrayilov
// Blogpost url:
// This gist shows an issue with using conditional NavigationLinks.
// When using StackNavigationViewStyle push animations are not present.
import SwiftUI
struct LazyNavApp: App {
var body: some Scene {
darrarski / TimeZones.js
Last active Oct 3, 2020 — forked from fcrespo82/TimeZones.js
Scriptable time zones widget
View TimeZones.js
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: cyan; icon-glyph: clock;
// list of time zones:
let configs = [
{name: "Warsaw", timzeZone: "Europe/Berlin", bgColor: new Color("BF0D3E",1)},
{name: "Recife", timeZone: "America/Recife", bgColor: new Color("009639",1)},
{name: "Los Angeles", timeZone: "America/Los_Angeles", bgColor: new Color("3878d1",1)}