Skip to content

Commit

Permalink
Merge pull request #11 from bullinnyc/add-url-request-parameter
Browse files Browse the repository at this point in the history
Add url request parameter.
  • Loading branch information
bullinnyc authored Apr 21, 2024
2 parents 6babc1e + dcdcd55 commit cb253e1
Show file tree
Hide file tree
Showing 11 changed files with 265 additions and 245 deletions.

This file was deleted.

This file was deleted.

26 changes: 9 additions & 17 deletions Examples/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import SwiftUI
import CachedAsyncImage

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, visionOS 1.0, *)
struct ContentView: View {
// MARK: - Private Properties

Expand All @@ -20,7 +19,7 @@ struct ContentView: View {
"https://image.tmdb.org/t/p/original/arw2vcBveWOVZr6pxd9XTd1TdQa.jpg"
]

private static let standartPadding: CGFloat = 20
private static let standartPadding: CGFloat = 16

// MARK: - Initializers

Expand All @@ -36,14 +35,14 @@ struct ContentView: View {

var body: some View {
ZStack {
Color(RM.snow)
Color.white
.ignoresSafeArea()

GeometryReader { geometry in
let size = geometry.size

ScrollView {
VStack(spacing: 20) {
VStack(spacing: 16) {
ForEach(posters, id: \.self) { url in
CachedAsyncImage(
url: url,
Expand Down Expand Up @@ -97,9 +96,8 @@ struct ContentView: View {

// MARK: - Ext. Configure views

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, visionOS 1.0, *)
extension ContentView {
func placeholder(_ progress: String) -> some View {
private func placeholder(_ progress: String) -> some View {
ZStack {
Color.yellow

Expand All @@ -113,7 +111,10 @@ extension ContentView {
}
}

func error(_ error: String, action: (() -> Void)? = nil) -> some View {
private func error(
_ error: String,
action: (() -> Void)? = nil
) -> some View {
ZStack {
Color.yellow

Expand All @@ -135,7 +136,7 @@ extension ContentView {
}
}

func retry(action: (() -> Void)?) -> some View {
private func retry(action: (() -> Void)?) -> some View {
Button(
action: { action?() },
label: {
Expand All @@ -146,12 +147,3 @@ extension ContentView {
)
}
}

// MARK: - Preview Provider

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, visionOS 1.0, *)
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
9 changes: 0 additions & 9 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ let package = Package(
.library(
name: "CachedAsyncImage",
targets: ["CachedAsyncImage"]
),
.library(
name: "ExampleCachedAsyncImage",
targets: ["Examples"]
)
],
targets: [
Expand All @@ -30,11 +26,6 @@ let package = Package(
.target(
name: "CachedAsyncImage"
),
.target(
name: "Examples",
dependencies: ["CachedAsyncImage"],
path: "Examples"
),
.testTarget(
name: "CachedAsyncImageTests",
dependencies: ["CachedAsyncImage"]
Expand Down
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,28 @@ init() {
}
```

### You can also read this value from within a view to access the image cache management
### Get cached image, remove cached image or image cache if needed.

```swift
struct MyView: View {
@ImageCache private var imageCache

// ...

// Get cached image.
private func getCachedImage(for url: URL) -> UIImage? {
imageCache[url]
}

// Remove cached image.
private func removeCachedImage(for url: URL) {
imageCache[url] = nil
}

// Remove image cache.
private func removeImageCache() {
imageCache.removeCache()
}
}
```

Expand Down
16 changes: 8 additions & 8 deletions Sources/CachedAsyncImage/Resources/ResourcesManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import SwiftUI
#endif

/// Resources manager typealias.
public typealias RM = ResourcesManager
typealias RM = ResourcesManager

/// Resources manager.
public final class ResourcesManager {
final class ResourcesManager {
// MARK: - Public Properties

/// An object that stores color data.
public static let snow = getColor(with: "snow")
static let snow = getColor(with: "snow")

// MARK: - Public Methods

Expand All @@ -30,7 +30,7 @@ public final class ResourcesManager {
/// - Parameter name: Image name.
///
/// - Returns: An initialized image object or `nil` if the object was not found in the resources.
public static func image(_ name: String) -> UIImage? {
static func image(_ name: String) -> UIImage? {
UIImage(named: name, in: Bundle.module, with: nil)
}

Expand All @@ -52,14 +52,14 @@ public final class ResourcesManager {
import AppKit

/// Resources manager typealias.
public typealias RM = ResourcesManager
typealias RM = ResourcesManager

/// Resources manager.
public final class ResourcesManager {
final class ResourcesManager {
// MARK: - Public Properties

/// An object that stores color data.
public static let snow = NSColor(
static let snow = NSColor(
named: NSColor.Name("snow"),
bundle: Bundle.module
) ?? NSColor()
Expand All @@ -71,7 +71,7 @@ public final class ResourcesManager {
/// - Parameter name: Image name.
///
/// - Returns: An initialized image object or `nil` if the object was not found in the resources.
public static func image(_ name: String) -> NSImage? {
static func image(_ name: String) -> NSImage? {
Bundle.module.image(forResource: NSImage.Name(name))
}
}
Expand Down
Loading

0 comments on commit cb253e1

Please sign in to comment.