-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add navigationTitle (Binding) support #366
Conversation
@available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *) | ||
func setNavigationTitle(_ value: String) throws { | ||
try navigationTitleBinding().wrappedValue = value | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm hesitant to add the setter, as this is a side effect naturally not available in the UI. For example, the library exposes setMapRect
on Map
view, which is a side effect the user can cause from the UI (manually adjusting the map), so I can see a use case when this is used in tests. With the navigation title, by keeping the setter unavailable, the developer would be encouraged to change it programmatically from view's state, which would contribute to their app correctness
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case yeah, it's the user causing the state change that you otherwise cannot imitate. I would also do the same as for the getter, that is rethrow a meaningful error about API limitation
|
||
@available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *) | ||
func navigationTitle() throws -> String { | ||
return try navigationTitleBinding().wrappedValue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend when navigationTitleBinding
throws here (when the navigationTitle is set up in any other way but Binding), we capture the error and rethrow a InspectionError.notSupported
and explain in the error that only the variant with Binding
is supported
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like a good idea. I'll try to implement that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! A couple of minor tweaks requested
@nalexn Let me know if that's acceptable. The system does provide UI automatically for editing a bound navigation title, and I updated the error to indicate only the binding overload is currently supported. |
While
navigationTitle(String | Text | LocalizedStringKey)
is a bit difficult to pin down for inspection, we can get the binding fromnavigationTitle(Binding<String>)
fairly simply. This PR addsnavigationTitle() -> String
, andsetNavigationTitle(String)
methods.I would hope the same
navigationTitle() -> String
VI method eventually is extended to handle the SwiftUInavigationTitle(String | Text | LocalizedStringKey)
cases too.