-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from mzapatae/feature/storage-provider
Feature: Storage Provider
- Loading branch information
Showing
22 changed files
with
674 additions
and
37 deletions.
There are no files selected for viewing
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
26 changes: 26 additions & 0 deletions
26
Sources/Common/Extensions/Combine/Publisher+NoRetain.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// Publisher+NoRetain.swift | ||
// | ||
// | ||
// Created by Miguel Angel on 10-05-21. | ||
// | ||
|
||
import Combine | ||
|
||
extension Publisher where Self.Failure == Never { | ||
|
||
/// ### Example of use | ||
/// store | ||
/// .$state | ||
/// .map { $0.exception } | ||
/// .receive(on: DispatchQueue.main) | ||
/// .assignNoRetain(to: \.exception, on: self) | ||
/// .store(in: &bag) | ||
/// | ||
public func assignNoRetain<Root>(to keyPath: ReferenceWritableKeyPath< Root, | ||
Self.Output >, on object: Root) -> AnyCancellable where Root: AnyObject { | ||
sink { [weak object] (value) in | ||
object?[keyPath: keyPath] = value | ||
} | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// | ||
// View+Navigation.swift | ||
// | ||
// | ||
// Created by Miguel Angel on 07-05-21. | ||
// | ||
|
||
import SwiftUI | ||
|
||
extension View { | ||
|
||
public func onNavigation(_ action: @escaping () -> Void) -> some View { | ||
let isActive = Binding( | ||
get: { false }, | ||
set: { newValue in | ||
if newValue { | ||
action() | ||
} | ||
} | ||
) | ||
return NavigationLink(destination: EmptyView(), isActive: isActive) { | ||
self | ||
} | ||
} | ||
|
||
/// ### Example of use | ||
/// struct ListingScene: View { | ||
/// @ObservedObject private(set) var viewModel: ListingViewModel | ||
/// | ||
/// @State private var destination: Destination? | ||
/// | ||
/// var body: some View { | ||
/// NavigationView { | ||
/// VStack { | ||
/// Button("Nav") { | ||
/// destination = .detail(id: "") | ||
/// }.navigation(item: $destination, destination: viewModel.router.route(to:)) | ||
/// } | ||
/// } | ||
/// .navigationViewStyle(StackNavigationViewStyle()) | ||
/// } | ||
/// } | ||
/// | ||
public func navigation<Item, Destination: View>(item: Binding<Item?>, @ViewBuilder destination: (Item) -> Destination) -> some View { | ||
let isActive = Binding( | ||
get: { item.wrappedValue != nil }, | ||
set: { value in | ||
if !value { | ||
item.wrappedValue = nil | ||
} | ||
} | ||
) | ||
return navigation(isActive: isActive) { | ||
item.wrappedValue.map(destination) | ||
} | ||
} | ||
|
||
public func navigation<Destination: View>(isActive: Binding<Bool>, @ViewBuilder destination: () -> Destination) -> some View { | ||
overlay( | ||
NavigationLink( | ||
destination: isActive.wrappedValue ? destination() : nil, | ||
isActive: isActive, | ||
label: { EmptyView() } | ||
) | ||
) | ||
} | ||
|
||
} | ||
|
||
extension NavigationLink { | ||
|
||
public init<T: Identifiable, D: View>(item: Binding<T?>, @ViewBuilder destination: @escaping (T) -> D, @ViewBuilder label: () -> Label) where Destination == D? { | ||
let isActive = Binding( | ||
get: { item.wrappedValue != nil }, | ||
set: { value in | ||
if !value { | ||
item.wrappedValue = nil | ||
} | ||
} | ||
) | ||
self.init(destination: item.wrappedValue.map(destination), isActive: isActive, 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
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
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
This file was deleted.
Oops, something went wrong.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// Toggleable.swift | ||
// | ||
// | ||
// Created by Miguel Angel on 12-05-21. | ||
// | ||
|
||
public enum Toggleable: Equatable { | ||
case on | ||
case off | ||
|
||
public var isOn: Bool { | ||
self == .on | ||
} | ||
|
||
public var isOff: Bool { | ||
self == .off | ||
} | ||
|
||
public mutating func toggle() { | ||
switch self { | ||
case .on: | ||
self = .off | ||
case .off: | ||
self = .on | ||
} | ||
} | ||
|
||
public var state: Bool { | ||
switch self { | ||
case .on: | ||
return true | ||
case .off: | ||
return false | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// RegexMatch.swift | ||
// | ||
// | ||
// Created by Miguel Angel on 19-05-21. | ||
// | ||
|
||
import Foundation | ||
|
||
public final class Regex { | ||
|
||
public static func matches(for regex: String, in text: String) -> [String] { | ||
do { | ||
let regex = try NSRegularExpression(pattern: regex) | ||
let results = regex.matches(in: text, range: NSRange(text.startIndex..., in: text)) | ||
return results.map { | ||
String(text[Range($0.range, in: text)!]) | ||
} | ||
} catch let error { | ||
print("Invalid Regex: \(error.localizedDescription)") | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// PopoverModifier.swift | ||
// | ||
// | ||
// Created by Miguel Angel on 07-05-21. | ||
// | ||
|
||
import SwiftUI | ||
|
||
public struct PopoverModifier<Item: Identifiable, Destination: View>: ViewModifier { | ||
|
||
// MARK: Stored Properties | ||
|
||
private let item: Binding<Item?> | ||
private let destination: (Item) -> Destination | ||
|
||
// MARK: Initialization | ||
|
||
public init(item: Binding<Item?>, @ViewBuilder content: @escaping (Item) -> Destination) { | ||
self.item = item | ||
self.destination = content | ||
} | ||
|
||
// MARK: Methods | ||
|
||
public func body(content: Content) -> some View { | ||
content.popover(item: item, content: destination) | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// SheetModifier.swift | ||
// | ||
// | ||
// Created by Miguel Angel on 07-05-21. | ||
// | ||
|
||
import SwiftUI | ||
|
||
public struct SheetModifier<Item: Identifiable, Destination: View>: ViewModifier { | ||
|
||
// MARK: Stored Properties | ||
|
||
private let item: Binding<Item?> | ||
private let destination: (Item) -> Destination | ||
|
||
// MARK: Initialization | ||
|
||
public init(item: Binding<Item?>, @ViewBuilder content: @escaping (Item) -> Destination) { | ||
self.item = item | ||
self.destination = content | ||
} | ||
|
||
// MARK: Methods | ||
|
||
public func body(content: Content) -> some View { | ||
content.sheet(item: item, content: destination) | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// LazyView.swift | ||
// | ||
// | ||
// Created by Miguel Angel on 07-05-21. | ||
// | ||
|
||
import SwiftUI | ||
|
||
public struct LazyView<Content: View>: View { | ||
let build: () -> Content | ||
|
||
public init(_ build: @autoclosure @escaping () -> Content) { | ||
self.build = build | ||
} | ||
|
||
public var body: Content { | ||
build() | ||
} | ||
|
||
} |
Oops, something went wrong.