Saturday, September 24, 2022
HomeiOS Developmentios - Swift UI Listing View is resizing the "mounted" body of...

ios – Swift UI Listing View is resizing the “mounted” body of community Listing objects


I’m at present designing a Residence Display View the place one Listing object is representing the display screen dimension utilizing the GeometryReader. The construction given within the code beneath follows: HomeScreen -> HomeViewAsync -> KingfisherImage. As of now I set the body of the Listing Object VStack to .body(width: g.dimension.width, top: g.dimension.top) and the Listing component fills the display screen. Now I wish to adapt the Listing object dimension as a result of sure footage I load in KingfisherImage are smaller and depart a giant white area within the Listing object. Subsequently I would like the VStack Listing object to dynamically adapt to its contents, so I eliminated the body from the VStack. I seen that the photographs top is unbelievable small and don’t match the one set within the KingfisherImage. I assume it’s as a result of I’m loading them from the Net which causes this problem. My query is that if I can power the scale of the Picture to be like .body(width: g.dimension.width - 40, top:g.dimension.top)with out it being resized by the VStack ? I present two footage beneath. One with the body dimension of the VStack Listing object being set to most display screen dimension and the opposite one with no body of the VStack the place the photographs a squeezed within the top.

struct HomeScreen: View {
    GeometryReader{ g in
        Group{
                
                Listing(homeScreenVmgr.loadedPosts){ put up in
                    
                    VStack{
                        HomeViewAsync(expertise: put up, g: g)
                            }
                    }
                    .padding(.vertical)
                    .body(width: g.dimension.width, top: g.dimension.top)
                    .background(Shade.clear)
                    .listRowInsets(.init())
                    .listRowSeparator(.hidden)
                    .listRowBackground(Shade.clear)
                    
                }
     }
}

  struct HomeViewAsync: View {   
     @State var expertise: some Object
     @State var g: GeometryProxy

    
    init(expertise: LoadedPostAsyncImage, g: GeometryProxy){
        self._experience = State(initialValue: expertise)
        self._g = State(initialValue: g)
    }   
            TabView{
                ForEach(pictures, id: .self) {picture in
                    KingfisherImage(imageURL: picture, g: g)
                        .pinchToZoom()
                    }
            }
            .clipShape(RoundedRectangle(cornerRadius: 30, type: .steady))
            .tabViewStyle(PageTabViewStyle())
            .shadow(shade: Shade.black.opacity(0.3), radius: 10, x: 0, y: 5)

            .padding(.horizontal, 10)
                        HStack(alignment: .prime){
                Textual content("@"+username).font(.footnote.weight(.daring)).foregroundColor(.black)
                Textual content(caption)
                    .foregroundColor(.black)
                    .font(.footnote)
                    .padding(.main)
                Spacer()
            }
            .padding(.vertical)
            .padding(.main)
            .onTapGesture {
                withAnimation {
                    self.showBigCaption.toggle()
                }
            }
}

struct KingfisherImage: View{
    @State var imageURL: URL
    @State var g: GeometryProxy
    
    init(imageURL: URL, g: GeometryProxy){
        self._imageURL = State(initialValue: imageURL)
        self._g = State(initialValue: g)
    }

    var physique: some View{

        KFImage.url(imageURL)
            .loadDiskFileSynchronously()
            .cacheMemoryOnly()
            .fade(period: 0.25)
            .onProgress { receivedSize, totalSize in  }
            .onSuccess { end in  }
            .onFailure { error in }
            .resizable()
            .scaledToFit()
            .clipShape(RoundedRectangle(cornerRadius: 30, type: .steady))
            .body(width: g.dimension.width - 40, top:g.dimension.top)
    }
}

full display screen dimension

squeezed top with no body on VStack Listing Object

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular