nalexn / ViewInspector

Runtime introspection and unit testing of SwiftUI views
MIT License
2.16k stars 148 forks source link

Alert documentation is confusing #244

Open waterskier2007 opened 1 year ago

waterskier2007 commented 1 year ago

The documentation at https://github.com/nalexn/ViewInspector/blob/master/guide_popups.md#alert is confusing. Specifically for alerts it states If you're using alert functions added in iOS 15 (those not marked as deprecated) - you're good to go. and then states that only if you are NOT using those functions you will need to add the shim code. However errors in unit tests direct back to the documentation even if the alert functions > iOS 15 are being used. I think this documentation could be clarified as to WHEN the shim code is needed and how a test should be written if the shim code is NOT needed.

lo1tuma commented 1 year ago

I’m also quite confused when reading the guide about popups. Why is alert different than the other popups like sheet? Why is it possible to use the iOS 15 alert functions without a shim but the sheet modifier still requires the shim?

nalexn commented 1 year ago

Alerts and sheets look similar from the public APIs, both in swiftUI and in view inspector (at least, I aim to align the APIs), but under the hood, there are sometimes dramatic differences in inner structure and workings. Apple's engineers have revamped the implementation of Alerts several times (they usually don't do that with the other swiftui views), if you look at the code in the library you'll see all the branching based on the OS versions. I will double check the docs for actuality though, thanks for the heads up

lo1tuma commented 1 year ago

@nalexn thanks for the explanation. I wasn’t aware of that, since also the SwiftUI of alert() and sheet() looks very similar. Maybe that would be also noteworthy in the documentation, to explain why some presentation modifiers need a shim and some don’t. I think especially the first sentence in the section about sheet is a bit confusing "Similarly to the Alert and ActionSheet" give the impression the non-shim solution could also work for sheet.