|
| 1 | +// |
| 2 | +// LoadingFailureDemo.swift |
| 3 | +// Kingfisher |
| 4 | +// |
| 5 | +// Created by onevcat on 2025/06/29. |
| 6 | +// |
| 7 | +// Copyright (c) 2025 Wei Wang <onevcat@gmail.com> |
| 8 | +// |
| 9 | +// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 10 | +// of this software and associated documentation files (the "Software"), to deal |
| 11 | +// in the Software without restriction, including without limitation the rights |
| 12 | +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 13 | +// copies of the Software, and to permit persons to whom the Software is |
| 14 | +// furnished to do so, subject to the following conditions: |
| 15 | +// |
| 16 | +// The above copyright notice and this permission notice shall be included in |
| 17 | +// all copies or substantial portions of the Software. |
| 18 | +// |
| 19 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 20 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 21 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 22 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 23 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 24 | +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 25 | +// THE SOFTWARE. |
| 26 | + |
| 27 | +import SwiftUI |
| 28 | +import Kingfisher |
| 29 | + |
| 30 | +@available(iOS 14.0, *) |
| 31 | +struct LoadingFailureDemo: View { |
| 32 | + |
| 33 | + var url: URL { |
| 34 | + URL(string: "https://example.com")! |
| 35 | + } |
| 36 | + |
| 37 | + var warningImage: UIImage { |
| 38 | + let config = UIImage.SymbolConfiguration(pointSize: 50) |
| 39 | + return UIImage( |
| 40 | + systemName: "wrongwaysign", |
| 41 | + withConfiguration: config |
| 42 | + )! |
| 43 | + } |
| 44 | + |
| 45 | + var body: some View { |
| 46 | + VStack { |
| 47 | + KFImage(url) |
| 48 | + .onFailureImage(warningImage) // onFailureImage should not work |
| 49 | + .onFailureView { |
| 50 | + ZStack { |
| 51 | + RoundedRectangle(cornerRadius: 20) |
| 52 | + .fill(Color.red.opacity(0.5)) |
| 53 | + Image(systemName: "exclamationmark.triangle.fill") |
| 54 | + .resizable() |
| 55 | + .frame(width: 50, height: 47) |
| 56 | + .foregroundColor(.yellow) |
| 57 | + } |
| 58 | + } |
| 59 | + .frame(width: 200, height: 200) |
| 60 | + Text("onFailureView") |
| 61 | + Spacer().frame(height: 20) |
| 62 | + |
| 63 | + KFImage(url) |
| 64 | + .onFailureImage(warningImage) |
| 65 | + .frame(width: 200, height: 200) |
| 66 | + .background( |
| 67 | + RoundedRectangle(cornerRadius: 20) |
| 68 | + .fill(Color.red.opacity(0.5)) |
| 69 | + ) |
| 70 | + Text("onFailureImage") |
| 71 | + } |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +@available(iOS 14.0, *) |
| 76 | +struct LoadingFailureDemo_Previews: PreviewProvider { |
| 77 | + static var previews: some View { |
| 78 | + LoadingFailureDemo() |
| 79 | + } |
| 80 | +} |
0 commit comments