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
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *) | |
extension AnyPublisher { | |
static var empty: Self { | |
Empty(completeImmediately: false).eraseToAnyPublisher() | |
} | |
static func constant(_ value: Output) -> Self where Failure == Never { | |
Just(value).eraseToAnyPublisher() | |
} | |
} |
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
extension View { | |
public func textFieldFocusableArea() -> some View { | |
TextFieldButton { self.contentShape(Rectangle()) } | |
} | |
} | |
fileprivate struct TextFieldButton<Label: View>: View { | |
init(label: @escaping () -> Label) { | |
self.label = label | |
} |
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 EmptyOrNil { | |
var isEmpty: Bool { get } | |
} | |
extension Optional where Wrapped: EmptyOrNil { | |
var isEmptyOrNil: Bool { | |
return self?.isEmpty ?? true | |
} | |
} |
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 | |
/// Reads the width of the selection box next to a List row when editing mode is .active | |
/// | |
/// Note: On iOS 15 the listRowInsets do not respond to updates so if you want to offset | |
/// the cell you should use negative leading padding. | |
public struct ListSelectionBoxWidthReader<Content: View>: View { | |
@State private var boxWidth: CGFloat = 0 | |
private var content: (CGFloat) -> Content |
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
public protocol HierarchyDescription { | |
associatedtype Child: HierarchyDescription | |
var children: [Child] { get } | |
var description: String { get } | |
} | |
extension HierarchyDescription { | |
public var hierarchyDescription: String { | |
var description = self.description | |
for child in children { |
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
// MARK: Appending closures `a + b` | |
/// Append closures, lhs first. | |
public func + <I>(lhs: @escaping (I) -> Void, rhs: @escaping (I) -> Void) -> ((I) -> Void) { | |
return { | |
lhs($0) | |
rhs($0) | |
} | |
} |
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 Foundation | |
extension Date { | |
/// Returns date where **-component** is rounded to its closest | |
/// multiple of **-amount**. Warning: month and day start at 1 | |
/// so round(to: 6, .month) will either return month 1 or 7! | |
func round(to amount: Int, _ component: Calendar.Component) -> Date { | |
let cal = Calendar.current | |
var value = cal.component(component, from: self) |
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
extension View { | |
/// Controls the application's preferred home indicator auto-hiding when this view is shown. | |
func prefersHomeIndicatorAutoHidden(_ value: Bool) -> some View { | |
preference(key: PreferenceUIHostingController.PrefersHomeIndicatorAutoHiddenPreferenceKey.self, value: value) | |
} | |
/// Controls the application's preferred screen edges deferring system gestures when this view is shown. Default is UIRectEdgeNone. | |
func edgesDeferringSystemGestures(_ edge: UIRectEdge) -> some View { | |
preference(key: PreferenceUIHostingController.PreferredScreenEdgesDeferringSystemGesturesPreferenceKey.self, value: edge) | |
} |
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
extension Binding { | |
/// Wrapper to listen to didSet of Binding | |
func didSet(_ didSet: @escaping ((newValue: Value, oldValue: Value)) -> Void) -> Binding<Value> { | |
return .init(get: { self.wrappedValue }, set: { newValue in | |
let oldValue = self.wrappedValue | |
self.wrappedValue = newValue | |
didSet((newValue, oldValue)) | |
}) | |
} | |