View SwiftUI_InterfaceOrientationObservingViewModifier.swift
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 | |
struct InterfaceOrientationObservingViewModifier: ViewModifier { | |
let onChange: (UIInterfaceOrientation) -> Void | |
func body(content: Content) -> some View { | |
content.background(InterfaceOrientationObservingView(onChange: onChange)) | |
} | |
} |
View SwiftUI_DeviceOrientationObservingViewModifier.swift
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 | |
struct DeviceOrientationObservingViewModifier: ViewModifier { | |
let onChange: (UIDeviceOrientation) -> Void | |
func body(content: Content) -> some View { | |
content.background(DeviceOrientationObservingView(onChange: onChange)) | |
} | |
} |
View SwiftUI_BottomBarViewModifier.swift
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, |
View SwiftUI_GeometryReaderViewModifier.swift
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 |
View SwiftUI_SizeChangeModifier.swift
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, |
View SwiftUI_DeviceOrientationObserver.swift
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 | |
} |
View SwiftUI_onInterfaceOrientationChange.swift
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)) | |
} | |
} |
View SwiftUI_DeviceOrientationObserver.swift
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 |
View CaseSwitchable.swift
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! | |
} |
NewerOlder