Improve and fix crash for standard Cast views #246
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes a crash with
CastPlayerViewview and improves support for tallerCastMiniPlayerViews.These issues were reported by @clementbeffa.
Remark
Another issue was reported by @clementbeffa, namely that locally overriding the locale via the SwiftUI environment:
does not work for all strings in
CastPlayerViewandCastMiniPlayerView, and that some results are inconsistent. This locale overriding trick has inherent flaws, though, since it is limited to SwiftUI. Strings fetched usingString(localized:bundle:comment:), for example, are not affected by locale overrides (and even if there is an initializer that supports a locale, this locale is only used for formatting, not for actually fetching the string itself). Same for error messages, for example.Several attempts were made to improve compatibility of Cast views with this mechanism, but there will always be blind spots and attempting to cover all cases requires unnatural API changes (e.g. returning SwiftUI
Texts instead ofStrings to convey whether a string is localized or not, or returning a type that would convey such information but would introduce friction when used).For these reasons this PR only partially improves support for locale overrides by using
LocalizedStringResourcewhere appropriate, but is not an attempt at fully supporting such overrides, as they cannot be fully supported anyway.Changes made
Castusage, leading to crashes if not injected.GroupwithZStack.Checklist