This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
extension View { | |
func bottomBar<Bar: View>( | |
ignoresKeyboard: Bool = true, | |
frameChangeAnimation: Animation? = .default, | |
@ViewBuilder bar: @escaping () -> Bar | |
) -> some View { | |
modifier(BottomBarViewModifier( | |
ignoresKeyboard: ignoresKeyboard, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
extension View { | |
func geometryReader<Geometry: Codable>( | |
geometry: @escaping (GeometryProxy) -> Geometry, | |
onChange: @escaping (Geometry) -> Void | |
) -> some View { | |
modifier(GeometryReaderViewModifier( | |
geometry: geometry, | |
onChange: onChange |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
public extension View { | |
func onSizeChange( | |
ignoreSafeArea: Bool = false, | |
round: Bool = false, | |
perform action: @escaping (CGSize) -> Void | |
) -> some View { | |
modifier(SizeChangeModifier( | |
ignoreSafeArea: ignoreSafeArea, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
return | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol CaseSwitchable: CaseIterable, Equatable {} | |
extension CaseSwitchable { | |
mutating func `switch`() { | |
self = next() | |
} | |
func next() -> Self { | |
self.next() ?? Self.allCases.first! | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Based on "Lazy navigation in SwiftUI" blogpost by Majid Jabrayilov | |
// Blogpost url: https://swiftwithmajid.com/2021/01/27/lazy-navigation-in-swiftui/ | |
// This gist shows an issue with using conditional NavigationLinks. | |
// When using StackNavigationViewStyle push animations are not present. | |
import SwiftUI | |
@main | |
struct LazyNavApp: App { | |
var body: some Scene { |