@@ -17,7 +17,8 @@ extension String : Identifiable {
1717 }
1818}
1919
20- let imageURLs = [
20+ struct ContentView : View {
21+ @State var imageURLs = [
2122 " http://assets.sbnation.com/assets/2512203/dogflops.gif " ,
2223 " https://raw.githubusercontent.com/liyong03/YLGIFImage/master/YLGIFImageDemo/YLGIFImageDemo/joy.gif " ,
2324 " http://apng.onevcat.com/assets/elephant.png " ,
@@ -30,8 +31,6 @@ let imageURLs = [
3031 " https://nokiatech.github.io/heif/content/image_sequences/starfield_animation.heic " ,
3132 " https://nr-platform.s3.amazonaws.com/uploads/platform/published_extension/branding_icon/275/AmazonS3.png " ,
3233 " http://via.placeholder.com/200x200.jpg " ]
33-
34- struct ContentView : View {
3534 @State var animated : Bool = true // You can change between WebImage/AnimatedImage
3635
3736 var body : some View {
@@ -73,30 +72,37 @@ struct ContentView: View {
7372 }
7473
7574 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
8692 WebImage ( url: URL ( string: url) )
8793 . resizable ( )
8894 . scaledToFit ( )
8995 . frame ( width: CGFloat ( 100 ) , height: CGFloat ( 100 ) , alignment: . center)
96+ #endif
97+ Text ( ( url as NSString ) . lastPathComponent)
9098 }
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)
9899 }
99100 }
101+ . onDelete ( perform: { ( indexSet) in
102+ indexSet. forEach { ( index) in
103+ self . imageURLs. remove ( at: index)
104+ }
105+ } )
100106 }
101107 }
102108
0 commit comments