twodayslate / claw

A lobste.rs Reader
https://apps.apple.com/us/app/id1531645542
Other
35 stars 1 forks source link

Allow swipe back for in-app safari #45

Closed twodayslate closed 3 years ago

twodayslate commented 3 years ago

Closes #44

For some reason when you swipe to go back when the story is in a sheet (similar testing to #22 and #26) the story disappears. If you use the close button it doesn't. If I print the onDismiss that also get's called twice (sounds like something similar to https://github.com/stleamist/BetterSafariView/issues/15 although I don't know the fix). If I try to put SafariView on ContentView I get similar bugs to #26. This could be #21 but I don't understand why it would be fine for the close button but not swipe.

Other research for this ticket:

twodayslate commented 3 years ago

Perhaps the story gets deallocated and the state changes - since the sheet doesn't have a reload button there is no way to refresh the page. Might need to check if the story is loaded at didAppear

edit: The story fetcher is getting deallocated

twodayslate commented 3 years ago

This could fix it?

https://stackoverflow.com/questions/60315404/why-is-it-in-swiftui-when-presenting-modal-view-with-sheet-init-is-called-t

twodayslate commented 3 years ago

It was actually an issue using ObservableObject. Switching to a StateObject did the trick.

The view hit the onAppear but then was reloaded so the load never fired on the new ObservableObject. StateObject fixes this cause it isn't refreshed.

See https://sarunw.com/posts/how-to-initialize-stateobject-with-parameters-in-swiftui/ and https://stackoverflow.com/a/66463103/193772