From 0db4595160c84c06573de7d4ea4ee0e2f5078a49 Mon Sep 17 00:00:00 2001 From: Fumiya Tanaka Date: Tue, 17 Oct 2023 21:25:29 +0900 Subject: [PATCH] feat: add tiny fix for Demo. Add `LoadingOpacityEdge` and change lowerBound opacity in loading state. Add new state `reloading` to `Status`. (#8) --- Example/Example/DefaultContentView.swift | 3 +- Example/Example/DownsampleContentView.swift | 3 +- Package.resolved | 4 +- .../AsyncDownSamplingImage.swift | 48 ++++++-- docs/index.html | 115 +++++++++++++++++- 5 files changed, 158 insertions(+), 15 deletions(-) diff --git a/Example/Example/DefaultContentView.swift b/Example/Example/DefaultContentView.swift index 56974ca..f2d90f3 100644 --- a/Example/Example/DefaultContentView.swift +++ b/Example/Example/DefaultContentView.swift @@ -2,11 +2,12 @@ import SwiftUI struct DefaultContentView: View { - @State private var url = URL(string: "https://via.placeholder.com/1000") + @State private var url = URL(string: "https://picsum.photos/1000") @State private var size: CGSize = .init(width: 160, height: 160) var body: some View { VStack { + Text("Default AsyncImage") ScrollView { LazyVGrid(columns: [.init(), .init()]) { ForEach(0..<1000, id: \.self) { _ in diff --git a/Example/Example/DownsampleContentView.swift b/Example/Example/DownsampleContentView.swift index 41deef7..2f0b66e 100644 --- a/Example/Example/DownsampleContentView.swift +++ b/Example/Example/DownsampleContentView.swift @@ -3,11 +3,12 @@ import AsyncDownSamplingImage struct DownsampleContentView: View { - @State private var url = URL(string: "https://via.placeholder.com/1000") + @State private var url = URL(string: "https://picsum.photos/1000") @State private var size: CGSize = .init(width: 160, height: 160) var body: some View { VStack { + Text("AsyncDownSamplingImage") ScrollView { LazyVGrid(columns: [.init(), .init()]) { ForEach(0..<1000, id: \.self) { _ in diff --git a/Package.resolved b/Package.resolved index 01b0e0a..e65252d 100644 --- a/Package.resolved +++ b/Package.resolved @@ -5,8 +5,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-docc-plugin", "state" : { - "revision" : "10bc670db657d11bdd561e07de30a9041311b2b1", - "version" : "1.1.0" + "revision" : "26ac5758409154cc448d7ab82389c520fa8a8247", + "version" : "1.3.0" } }, { diff --git a/Sources/AsyncDownSamplingImage/AsyncDownSamplingImage.swift b/Sources/AsyncDownSamplingImage/AsyncDownSamplingImage.swift index 7725a36..ee03595 100644 --- a/Sources/AsyncDownSamplingImage/AsyncDownSamplingImage.swift +++ b/Sources/AsyncDownSamplingImage/AsyncDownSamplingImage.swift @@ -1,12 +1,36 @@ import SwiftUI + +private enum LoadingOpacityEdge { + case upperBound + case lowerBound + + var value: Double { + switch self { + case .upperBound: + return 1 + case .lowerBound: + return 0.3 + } + } + + mutating func toggle() { + switch self { + case .upperBound: + self = .lowerBound + case .lowerBound: + self = .upperBound + } + } +} + /// AsyncDownSamplingImage is a Image View that can perform downsampling and use less memory use than `AsyncImage`. /// /// About generics type: /// -/// - Content: View which appears when state is Successful. -/// - Placeholder: View which appears when state is Loading. -/// - Fail: View which appears when state is Failed. +/// - Content: View which appears when state is Successful. +/// - Placeholder: View which appears when state is Loading. +/// - Fail: View which appears when state is Failed. public struct AsyncDownSamplingImage: View { /// resource URL where you would like to fetch an image. @@ -24,7 +48,7 @@ public struct AsyncDownSamplingImage Fail @State private var status: Status = .idle - @State private var loadingOpacity: CGFloat = 1.0 + @State private var loadingOpacity: LoadingOpacityEdge = .upperBound /// Standard initializer /// @@ -79,19 +103,18 @@ public struct AsyncDownSamplingImageDocumentation
\ No newline at end of file + + + + + + + + + + Documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +