From 2161583d5da5ee9340122509b36acc9f73b26f67 Mon Sep 17 00:00:00 2001 From: bullinnyc Date: Sat, 20 Jan 2024 17:12:55 +0700 Subject: [PATCH] Delete OnChange. --- .../CachedAsyncImage/Modifiers/OnChange.swift | 57 ------------------- .../Views/CachedAsyncImage.swift | 2 +- 2 files changed, 1 insertion(+), 58 deletions(-) delete mode 100644 Sources/CachedAsyncImage/Modifiers/OnChange.swift diff --git a/Sources/CachedAsyncImage/Modifiers/OnChange.swift b/Sources/CachedAsyncImage/Modifiers/OnChange.swift deleted file mode 100644 index d7e6bcc..0000000 --- a/Sources/CachedAsyncImage/Modifiers/OnChange.swift +++ /dev/null @@ -1,57 +0,0 @@ -// -// OnChange.swift -// CachedAsyncImage -// -// Created by Dmitry Kononchuk on 23.11.2023. -// Copyright © 2023 Dmitry Kononchuk. All rights reserved. -// - -import SwiftUI - -struct OnChange: ViewModifier where Value: Equatable { - // MARK: - Public Properties - - let value: Value - let isInitial: Bool - let action: (_ oldValue: Value?, _ newValue: Value) -> Void - - // MARK: - Body Method - - func body(content: Content) -> some View { - if #available(iOS 17.0, macOS 14.0, *) { - content - .onChange(of: value, initial: isInitial) { oldValue, newValue in - action(oldValue, newValue) - } - } else { - content - .onChange(of: value) { newValue in - action(nil, newValue) - } - } - } -} - -// MARK: - Ext. View - -extension View { - /// Method overloading – onChange(of:initial:_:). - /// Adds a modifier for this view that fires an action when a specific value changes. - /// - /// - Parameters: - /// - value: The value to check against when determining whether to run the closure. - /// - isInitial: Whether the action should be run when this view initially appears. - /// - action: A closure to run when the value changes. - /// - oldValue: The old value that failed the comparisoncheck - /// (or the initial value when requested). - /// - newValue: The new value that failed the comparison check. - /// - /// - Returns: A view that fires an action when the specified value changes. - func onChange( - of value: Value, - isInitial: Bool = false, - action: @escaping (_ oldValue: Value?, _ newValue: Value) -> Void - ) -> some View where Value: Equatable { - modifier(OnChange(value: value, isInitial: isInitial, action: action)) - } -} diff --git a/Sources/CachedAsyncImage/Views/CachedAsyncImage.swift b/Sources/CachedAsyncImage/Views/CachedAsyncImage.swift index 1e9cc63..f66bf18 100644 --- a/Sources/CachedAsyncImage/Views/CachedAsyncImage.swift +++ b/Sources/CachedAsyncImage/Views/CachedAsyncImage.swift @@ -78,7 +78,7 @@ public struct CachedAsyncImage: View { AnyView(self.image(image)) } } - .onChange(of: url) { _, newValue in + .onChange(of: url) { newValue in imageLoader.fetchImage(from: newValue) } }