0

I am playing around with Zstack to show the list of images(stacked tinder like view) from the users iphone album. There are photos landscape and in portrait mode. When stacked if the 1st image seems to be landscape mode I still can see the background images.

Is there a way to hide the background images until they are brought to foreground through gestures?

struct ContentView: View {
    @StateObject var viewModel = MediaApiViewModel()
    var body: some View {
        VStack {
            ZStack{
                ForEach(viewModel.allPhotos, id: \.identifier) { photo in                    
                    GeometryReader { geometry in
                        photo.view { image in image.resizable().aspectRatio(contentMode: .fit) }
                                        .frame(maxWidth: geometry.size.width,
                                               maxHeight: geometry.size.height)
                            .clipped()
                                }

                }
            }
        }
    }
}

Note: Using a library MediaSwiftUI which gives me a view on the photo object.enter image description here

pawello2222
  • 46,897
  • 22
  • 145
  • 209
Appunu
  • 83
  • 4
  • Does this help? [Dynamically hiding view in SwiftUI](https://stackoverflow.com/q/56490250/7129318) – Yrb Dec 26 '20 at 02:32
  • I don't think that loading all photos at once into ZStack is a good approach, due to memory consumption your app might be killed. It is better to show photos *by-one*, so change code design, and as a result you will not have "to hide" problem. – Asperi Dec 26 '20 at 05:23
  • @Asperi thanks for your suggestions. I couldn't figure out a way to stream one photo at a time to the image view. Do you have any pointers? – Appunu Dec 28 '20 at 02:02

0 Answers0