1

I'm looking for the equivalent of a html inline-block in swiftui. I basically want it to work exactly like list - but just wrap if it's going to exceed the line - eg

WrappingList( items ) {
    Text( "item.name") 
}

but I'm finding it way harder than I thought. I really want the things list brings to the table - ie incremental updates and scrolling, but I can't find a way of mapping it into the swift declarative style. In languages where you added controls procedurally, it's trivial:

current_x = 0
current_y = 0
foreach (var item in items ) 
{
    control = create_control_for( item )
    biggest_y = max( current_y + control.height, biggest_y)
    if (control.width + current_x > width) 
    {
        current_x=0;
        current_y = biggest_y;
    }
    control.position = (current_x, current_y)
}

but swift seems to want to do things in hstacks or vstacks and I don't really know how do that and still keep the properties of a list - particularly without knowing the size of things in advance - ie I don't want a fixed grid.

Does such functionality already exist? If not, is there a way of mapping the above code line into SwiftUI?

pkamb
  • 33,281
  • 23
  • 160
  • 191
Darren Oakey
  • 2,894
  • 3
  • 29
  • 55
  • 1
    Does this answer your question https://stackoverflow.com/a/58876712/12299030? – Asperi Aug 21 '20 at 12:26
  • I think so - I'm going to play with it - I was hoping to use a list because of the reusing cell pattern - but what you've done is quite clever - I didn't know about ZStack, and was having problems having a variable I could adjust - didn't think about putting the loop itself in a function - thanks – Darren Oakey Aug 21 '20 at 21:15

1 Answers1

0

just so there's an answer here - the comment above from asperi worked great - linking to this stack overflow article

Darren Oakey
  • 2,894
  • 3
  • 29
  • 55
  • 2
    Please edit your Answer to be more than just a comment - at the very least a link to the other Answer and maybe a pull-quote from it. – pkamb Sep 15 '20 at 01:24