globulus / swiftui-flow-layout

Flow layout / tag cloud / collection view in SwiftUI.
MIT License
243 stars 22 forks source link

FlowLayout Error in iOS 13.7 #5

Closed AhmedAmineZribi closed 2 years ago

AhmedAmineZribi commented 2 years ago

then I used package of FlowLayout in my project and I run the app with iOS 13.7, the app crash. Could you please make changes for < iOS 14 Thank you

FlowLayout 1 0 3
gordan-glavas-codecons commented 2 years ago

@AhmedAmineZribi I can run the code normally on a 13.7 emulator:

Screenshot 2021-11-11 at 10 13 07

and I do run it in live projects targeting iOS 13, so I'd guess that the issue is in the unfortunate combo of SwiftUI 1 and the rest of your codebase. I'd have to see the view that actually contains the FlowLayout to tell more, but iOS 13 is known for having issues with nested GeometryReaders.

AhmedAmineZribi commented 2 years ago

is that FlowLayout 1.0.0 or 1.0.3 ? in my side I used with 1.0.0 and I have error I think it related to GeometryReaders in this function : private func viewHeightReader(_ binding: Binding<CGFloat>) -> some View { return GeometryReader { geo -> Color in DispatchQueue.main.async { binding.wrappedValue = geo.frame(in: .local).size.height } return .clear } }

flow layout success 14.3 flow layout error 13.7
gordan-glavas-codecons commented 2 years ago

It's 1.0.3, always use the latest version as it contains bug fixes and additional improvements compared to previous ones.

AhmedAmineZribi commented 2 years ago

Hello @gordan-glavas-codecons, I update my package to 13.7 and still have the same issues in func viewHeightReader. The frame in geo . you can see Screen shot

follow layout

In my case I use flow layout not in all frame like you make, as you see in my last screen shot it was in a section .

The solution is :

binding.wrappedValue = geo.size.height

instead for this :

binding.wrappedValue = geo.frame(in: .local).size.height

Can you please make this changes ?

gordan-glavas-codecons commented 2 years ago

There is an important difference between the geo.size.height and geo.frame(in: .local).size.height, with the former being the expected size, and latter being the actually measured one, hence just using the former would be wrong for most use-cases.

The issue you're seeing is a result of stacked GeometryReaders not working on iOS 13 and is somewhat specific to your layout. I recommend creating a fork of this repo and making the change in it, since I can't make the change here without compromising stability.