List view showing data from middle position instead of top (offset=0) position of view

Hi There,

I am facing issue the list view has sections the view unable to show top position, list view only showing from middle position in swiftui.

I want to display list view from top of the view position.

I would be appreciated to help.

Hi @sivak

I’m sorry I’m a little bit puzzle with the layout you want to implement, can you share more details, and maybe the code of your project to give us more context on what you want to accomplish?

Thanks

Thanks for your reply.

Please find below code.

struct RequestView: View {

@ObservedObject var viewModel = ViewModel()

private var paginationView: some View {
    HStack {
        Spacer()
        PaginationView(offset: self.$viewModel.offset,
                       totalCount: self.viewModel.totalCount,
                       count: ViewModel.increment)
            .fixedSize()
        Spacer()
    }
}

var body: some View {
    List() {
        viewModel.requests.map { requests in
            ForEach(requests) { (request: Request) in
                Section(header: SectionHeader(request: request,
                                                                  destinationSegment: .approvals)) {
                    request.approvals.map { (approvals) in
                        ForEach(approvals) { (approval: Approval) in
                            NavigationLink(destination: DetailView(DetailViewModel(approval) )) {
                                ListItem(ListItemViewModel(approval))
                            }
                        }
                    }
                }
            }
        }
        
        if viewModel.totalCount >= ViewModel.increment {
            Section(footer: self.paginationView) {
                EmptyView()
            }
        }
    }
    .listStyle(GroupedListStyle())
    .navigationBarTitle(viewModel.navigationBarTitle)
    
}

}

You can see the section header line. Without section header often view showing from top position but same time if I give section header the view position showing from middle of the screen.
Please try to give me answer its need.