Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 14 Widgets: Widget not rendering when list is used [duplicate]

I'm experimenting with iOS 14 widgets and have a weird issue. My widget is not loading when I'm using a List in the widget view. If I'm using HStack, VStack etc. all works ok.

Here is some simple code for the sake of example:

struct WidgetView: View {

   var body: some View {
    
       List {
           Text("Test 1")
           Text("Test 2")
       }
   }
}

I'm seeing this image as a result: enter image description here

Again, it all works well with other elements, this is only happening with List.

like image 416
chnski Avatar asked Aug 02 '20 13:08

chnski


1 Answers

List has a scrolling function not supported on the widget, widgets only display static views, instead try using forEach.

For example:

struct SomeView: View {
    
    var body: some View {
        HStack {
            ForEach(1..<5) { index in
                otherView()
            }
        }
    }
}

You may use an HStack, or VStack depending on your needs and design.

like image 175
J Arango Avatar answered Oct 27 '22 12:10

J Arango