UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: When List is embed in GeometryReader it has 0px height.

Forums > SwiftUI

Hi, I have a problem (not for the first time) with GeometryReader. When I have ForEach inside it it works fine - my elements have proper height and are displayed correctly. However when I wrap ForEach in List, elements are no longer displayed. What I found out is that List has 0 height (I need to add frame with height to see it - and I would prefer to have height calculated dynamically).

The following code works fine, but I would like to add "Delete" on swipe.

  GeometryReader { geo in
            ScrollView(.vertical, showsIndicators: false) {
                ForEach(alarmVM.alarms, id:\.id) { alarm in
                        AlarmItem(alarm: alarm)
                        } // FOREACH
                } // SCROLLVIEW
            } // GEOREADER
            .frame(maxWidth: 700, alignment: .center)

I need to wrap ForEach with List. But then List has 0px height - it's not set dynamically and in result not visible:

       GeometryReader { geo in
            ScrollView(.vertical, showsIndicators: false) {
                List {
                    ForEach(alarmVM.alarms, id:\.id) { alarm in
                            AlarmItem(alarm: alarm)
                            } // FOREACH
                            .onDelete(perform: { indexSet in
                                print(indexSet)
                        }) // ONDELETE
                    } // LIST
                } // SCROLL VIEW
            } // GEOREADER

Is any way to have height of List set dynamically?

EDIT: Looks like it has nothing to do with GeometryReader. When I removed GeometryReader the problem persists.

2      

Did you try skipping the ScrollView? a List (as far as I know) is scrollable once its content extends beyond the visible area of the screen.

Currently, the list is an item inside the scollview. Try just using list and see if the problem persists.

2      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.