Skip to content

Commit

Permalink
Rename model
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Feb 18, 2023
1 parent 8bac493 commit baccf1b
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions Sources/NukeUI/LazyImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public typealias ImageContainer = Nuke.ImageContainer
@MainActor
@available(iOS 14.0, tvOS 14.0, watchOS 7.0, macOS 10.16, *)
public struct LazyImage<Content: View>: View {
@StateObject private var model = FetchImage()
@StateObject private var viewModel = FetchImage()

private let request: HashableRequest?

Expand Down Expand Up @@ -161,7 +161,7 @@ public struct LazyImage<Content: View>: View {
}

@ViewBuilder private var content: some View {
let state = LazyImageState(viewModel: model)
let state = LazyImageState(viewModel: viewModel)
if let makeContent = makeContent {
makeContent(state)
} else {
Expand All @@ -178,25 +178,23 @@ public struct LazyImage<Content: View>: View {
}

private func onAppear() {
// Unfortunately, you can't modify @State directly in the properties
// that set these options.
model.animation = animation
if let processors = processors { model.processors = processors }
if let priority = priority { model.priority = priority }
model.pipeline = pipeline

load(request)
}

private func load(_ request: HashableRequest?) {
model.load(request?.request)
viewModel.animation = animation
viewModel.processors = processors ?? []
viewModel.priority = priority
viewModel.pipeline = pipeline

viewModel.load(request?.request)
}

private func onDisappear() {
guard let behavior = onDisappearBehavior else { return }
switch behavior {
case .cancel: model.cancel()
case .lowerPriority: model.priority = .veryLow
case .cancel: viewModel.cancel()
case .lowerPriority: viewModel.priority = .veryLow
}
}

Expand Down

0 comments on commit baccf1b

Please sign in to comment.