DetailView.swift 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * This file is part of the SDWebImage package.
  3. * (c) DreamPiggy <lizhuoli1126@126.com>
  4. *
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. */
  8. import SwiftUI
  9. import SDWebImageSwiftUI
  10. struct DetailView: View {
  11. let url: String
  12. @State var animated: Bool = true // You can change between WebImage/AnimatedImage
  13. @State var isAnimating: Bool = true
  14. var body: some View {
  15. VStack {
  16. contentView()
  17. .navigationBarItems(trailing: Button(isAnimating ? "Stop" : "Start") {
  18. self.isAnimating.toggle()
  19. })
  20. }
  21. }
  22. func contentView() -> some View {
  23. HStack {
  24. if animated {
  25. AnimatedImage(url: URL(string:url), options: [.progressiveLoad, .delayPlaceholder], isAnimating: $isAnimating)
  26. .indicator(.progress)
  27. .resizable()
  28. .scaledToFit()
  29. } else {
  30. WebImage(url: URL(string:url), options: [.progressiveLoad, .delayPlaceholder], isAnimating: $isAnimating)
  31. .resizable()
  32. .indicator(.progress)
  33. .scaledToFit()
  34. }
  35. }
  36. }
  37. }
  38. #if DEBUG
  39. struct DetailView_Previews: PreviewProvider {
  40. static var previews: some View {
  41. DetailView(url: "https://nokiatech.github.io/heif/content/images/ski_jump_1440x960.heic", animated: false)
  42. }
  43. }
  44. #endif