This file contains hidden or 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
let options = URLImageOptions(identifier: "user-avatar") | |
URLImage(url: url, | |
options: options) { image in | |
image | |
.resizable() | |
.aspectRatio(contentMode: .fit) | |
} |
This file contains hidden or 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
URLImage(url: url, | |
empty: { | |
EmptyView() | |
}, | |
inProgress: { progress in | |
Image(systemName: "photo") | |
}, | |
failure: { error, retry in | |
Text("Failed") | |
}, |
This file contains hidden or 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
URLImage(url: url) { image in | |
image | |
.resizable() | |
.aspectRatio(contentMode: .fit) | |
} |
This file contains hidden or 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
// | |
// URLImageWidget.swift | |
// URLImageWidget | |
// | |
// Created by Dmytro Anokhin on 08/12/2020. | |
// | |
import WidgetKit | |
import SwiftUI | |
import Intents |
This file contains hidden or 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 DecodableRemoteContent where Decoder == JSONDecoder { | |
convenience init(urlSession: URLSession = .shared, url: URL, type: Value.Type) { | |
self.init(urlSession: urlSession, url: url, type: type, decoder: JSONDecoder()) | |
} | |
} |
This file contains hidden or 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 | |
import RemoteContentView | |
struct Post : Codable { | |
var id: Int | |
// ... | |
} |
This file contains hidden or 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 RemoteContentView where Empty == EmptyView, Progress == ActivityIndicator, Failure == Text { | |
init<R: RemoteContent>(remoteContent: R, | |
content: @escaping (_ value: Value) -> Content) where R.ObjectWillChangePublisher == ObservableObjectPublisher, | |
R.Value == Value | |
{ | |
self.init(remoteContent: remoteContent, | |
empty: { EmptyView() }, | |
progress: { ActivityIndicator() }, | |
failure: { error, _ in Text(error.localizedDescription) }, |
This file contains hidden or 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
final class DecodableRemoteContent<Value, Decoder> : RemoteContent where Value : Decodable, | |
Decoder : TopLevelDecoder, | |
Decoder.Input == Data | |
{ | |
unowned let urlSession: URLSession | |
let url: URL | |
let type: Value.Type | |
let decoder: Decoder | |
init(urlSession: URLSession = .shared, url: URL, type: Value.Type, decoder: Decoder) { |
This file contains hidden or 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
struct RemoteContentView<Value, Empty, Progress, Failure, Content> : View where Empty : View, | |
Progress : View, | |
Failure : View, | |
Content : View | |
{ | |
let empty: () -> Empty | |
let progress: () -> Progress | |
let failure: (_ error: Error, _ retry: @escaping () -> Void) -> Failure | |
let content: (_ value: Value) -> Content |
This file contains hidden or 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
final class AnyRemoteContent<Value> : RemoteContent { | |
init<R: RemoteContent>(_ remoteContent: R) where R.ObjectWillChangePublisher == ObjectWillChangePublisher, | |
R.Value == Value { | |
objectWillChangeClosure = { | |
remoteContent.objectWillChange | |
} | |
loadingStateClosure = { |