Skip to content

Commit 1d49652

Browse files
author
Christian Elies
committed
docs(readme): added missing documentation about the newly added customization options
1 parent 7de2045 commit 1d49652

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,49 @@ RemoteImage(type: .phAsset(localIdentifier: "541D4013-D51C-463C-AD85-0A1E4EA838F
5555
})
5656
```
5757

58+
## Custom `RemoteImageService`
59+
60+
If you want complete control over the service responsible for managing the state of the view and for fetching the image you could pass an object conforming to the `RemoteImageService` to the related initializer:
61+
62+
```swift
63+
let url = URL(string: "https://images.unsplash.com/photo-1524419986249-348e8fa6ad4a?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1950&q=80")!
64+
65+
RemoteImage(type: .url(url), service: yourCustomService, errorView: { error in
66+
Text(error.localizedDescription)
67+
}, imageView: { image in
68+
image
69+
.resizable()
70+
.aspectRatio(contentMode: .fit)
71+
}, loadingView: {
72+
Text("Loading ...")
73+
})
74+
```
75+
76+
## Custom `RemoteImageURLDataPublisher`
77+
78+
Under the hood by default the `URLSession.shared` is used as the `RemoteImageURLDataPublisher` to fetch the image at the specified URL.
79+
You can specify a custom publisher through the`remoteImageURLDataPublisher` parameter.
80+
As an example that's how you could add support for low data mode to the `RemoteImage` view.
81+
82+
```swift
83+
let url = URL(string: "https://images.unsplash.com/photo-1524419986249-348e8fa6ad4a?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1950&q=80")!
84+
85+
RemoteImage(type: .url(url), remoteImageURLDataPublisher: {
86+
let configuration = URLSessionConfiguration.default
87+
// Enable low data mode support
88+
configuration.allowsConstrainedNetworkAccess = false
89+
return URLSession(configuration: configuration)
90+
}(), errorView: { error in
91+
Text(error.localizedDescription)
92+
}, imageView: { image in
93+
image
94+
.resizable()
95+
.aspectRatio(contentMode: .fit)
96+
}, loadingView: {
97+
Text("Loading ...")
98+
})
99+
```
100+
58101
## Custom cache
59102

60103
The `RemoteImageService` uses a default cache. To use a custom one just conform to the protocol `RemoteImageCache` and set it on the type `RemoteImageService`.

0 commit comments

Comments
 (0)