Skip to content

Commit

Permalink
Fix bug on url changes
Browse files Browse the repository at this point in the history
use @StateObject to reinit imageModel when url changes
  • Loading branch information
racechao committed Apr 4, 2024
1 parent 22423b0 commit 82c097d
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions SDWebImageSwiftUI/Classes/WebImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ public struct WebImage<Content> : View where Content: View {
/// True to start animation, false to stop animation.
@Binding public var isAnimating: Bool

/// A observed object to pass through the image model to manager
@ObservedObject var imageModel: WebImageModel

/// A observed object to pass through the image handler to manager
@ObservedObject var imageHandler = WebImageHandler()

Expand All @@ -102,6 +99,8 @@ public struct WebImage<Content> : View where Content: View {

@ObservedObject var indicatorStatus : IndicatorStatus

@StateObject var imageModel: WebImageModel

@StateObject var imagePlayer = ImagePlayer()

@StateObject var imageManager : ImageManager
Expand Down Expand Up @@ -140,7 +139,7 @@ public struct WebImage<Content> : View where Content: View {
imageModel.url = url
imageModel.options = options
imageModel.context = context
_imageModel = ObservedObject(wrappedValue: imageModel)
_imageModel = StateObject(wrappedValue: imageModel)
let imageManager = ImageManager()
_imageManager = StateObject(wrappedValue: imageManager)
_indicatorStatus = ObservedObject(wrappedValue: imageManager.indicatorStatus)
Expand Down

0 comments on commit 82c097d

Please sign in to comment.