@@ -17,7 +17,8 @@ extension String : Identifiable {
17
17
}
18
18
}
19
19
20
- let imageURLs = [
20
+ struct ContentView : View {
21
+ @State var imageURLs = [
21
22
" http://assets.sbnation.com/assets/2512203/dogflops.gif " ,
22
23
" https://raw.githubusercontent.com/liyong03/YLGIFImage/master/YLGIFImageDemo/YLGIFImageDemo/joy.gif " ,
23
24
" http://apng.onevcat.com/assets/elephant.png " ,
@@ -30,8 +31,6 @@ let imageURLs = [
30
31
" https://nokiatech.github.io/heif/content/image_sequences/starfield_animation.heic " ,
31
32
" https://nr-platform.s3.amazonaws.com/uploads/platform/published_extension/branding_icon/275/AmazonS3.png " ,
32
33
" http://via.placeholder.com/200x200.jpg " ]
33
-
34
- struct ContentView : View {
35
34
@State var animated : Bool = true // You can change between WebImage/AnimatedImage
36
35
37
36
var body : some View {
@@ -73,30 +72,37 @@ struct ContentView: View {
73
72
}
74
73
75
74
func contentView( ) -> some View {
76
- List ( imageURLs) { url in
77
- NavigationLink ( destination: DetailView ( url: url, animated: self . animated) ) {
78
- HStack {
79
- #if os(iOS) || os(tvOS) || os(macOS)
80
- if self . animated {
81
- AnimatedImage ( url: URL ( string: url) )
82
- . resizable ( )
83
- . scaledToFit ( )
84
- . frame ( width: CGFloat ( 100 ) , height: CGFloat ( 100 ) , alignment: . center)
85
- } else {
75
+ List {
76
+ ForEach ( imageURLs) { url in
77
+ NavigationLink ( destination: DetailView ( url: url, animated: self . animated) ) {
78
+ HStack {
79
+ #if os(iOS) || os(tvOS) || os(macOS)
80
+ if self . animated {
81
+ AnimatedImage ( url: URL ( string: url) )
82
+ . resizable ( )
83
+ . scaledToFit ( )
84
+ . frame ( width: CGFloat ( 100 ) , height: CGFloat ( 100 ) , alignment: . center)
85
+ } else {
86
+ WebImage ( url: URL ( string: url) )
87
+ . resizable ( )
88
+ . scaledToFit ( )
89
+ . frame ( width: CGFloat ( 100 ) , height: CGFloat ( 100 ) , alignment: . center)
90
+ }
91
+ #else
86
92
WebImage ( url: URL ( string: url) )
87
93
. resizable ( )
88
94
. scaledToFit ( )
89
95
. frame ( width: CGFloat ( 100 ) , height: CGFloat ( 100 ) , alignment: . center)
96
+ #endif
97
+ Text ( ( url as NSString ) . lastPathComponent)
90
98
}
91
- #else
92
- WebImage ( url: URL ( string: url) )
93
- . resizable ( )
94
- . scaledToFit ( )
95
- . frame ( width: CGFloat ( 100 ) , height: CGFloat ( 100 ) , alignment: . center)
96
- #endif
97
- Text ( ( url as NSString ) . lastPathComponent)
98
99
}
99
100
}
101
+ . onDelete ( perform: { ( indexSet) in
102
+ indexSet. forEach { ( index) in
103
+ self . imageURLs. remove ( at: index)
104
+ }
105
+ } )
100
106
}
101
107
}
102
108
0 commit comments