Skip to content
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

FeatureFormView & PopupView - Add ._Title(_:) #839

Open
wants to merge 6 commits into
base: v.next
Choose a base branch
from

Conversation

dfeinzimer
Copy link
Collaborator

Closes #835

Adds modifiers to PopupView and FeatureFormView allowing developers to hide the titles.

@dfeinzimer dfeinzimer self-assigned this Aug 14, 2024
@@ -39,6 +41,6 @@ extension EnvironmentValues {
}

/// The validation error visibility configuration of a form.
private struct FormViewValidationErrorVisibility: EnvironmentKey {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing this to internal allows FeatureFormView to access the default value.

@@ -25,8 +25,10 @@ public extension FeatureFormView {

/// Specifies the visibility of validation errors in the form.
/// - Parameter visibility: The preferred visibility of validation errors in the form.
func validationErrors(_ visibility: ValidationErrorVisibility) -> some View {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needed to change to -> FeatureFormView so that the two FeatureFormView modifiers can be placed in any order.

/// Specifies the visibility of the popup title.
/// - Parameter visibility: The visibility of the popup title.
/// - Since: 200.6
public func popupTitle(_ visibility: TitleVisibility) -> Self {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not set on this modifier for one reason - the showCloseButton button modifier.

It seems disjoint that a developer can hide the title and simultaneously leave the close button visible.

PopupView(popup: popup!, isPresented: $showPopup)
    .popupTitle(.hidden)
    .showCloseButton(true)
Screenshot 2024-08-14 at 10 56 03 AM

Should we instead deprecate showCloseButton and add something like .popupHeader(_:) which would hide both?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The title and close button are not necessarily related, other than they have been occupying the same space. It may be that the client doesn't want the title in the popup/view but still requires the close button. So I'm OK having them both be distinct and put the onus on the client to figure out how they want it to display/behave.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with David that it is a bit disjoint. I'm not sure we should've had a simple boolean for the close button. Some people might prefer a "Done" button. There is no way to customize that (well I guess the library is open source so people could customize it).

The isPresented works if using the toolkit's FloatingPanel. And I guess it works with .sheet as well, but it's actually unnecessary with .sheet because we could have used the DismissAction environment value:

@Environment(\.dismiss) private var dismiss

I think, for the most part, our components should not assume their container.

Since title text is sometimes (often) on the "same line" as some buttons (done, cancel, menu), we might do better with a constructor like this that enables the PopupView to build a header for situations where they want to add a close button, but the title isn't displayed in a navigation toolbar:

struct PopupView<HeaderContent: View>: View {
    let popup: Popup
    let headerContent: ((String) -> HeaderContent)?

    ...
    
    /// Creates a PopupView...
    /// - Parameters:
    ///   - popup: The Popup to display
    ///   - headerContent: A closure that builds the header for a given title
    init(popup: Popup, @ViewBuilder headerContent: @escaping (String) -> HeaderContent) {
        self.popup = popup
        self.headerContent = headerContent
    }

This would allow somebody to add their own title, buttons, etc.

That would solve the close button thing. Then I guess there could be some modifier for header(_ visibility:).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mhdostal Any preference on the individual title and close button controls vs. Ryan's suggestion?

Copy link
Member

@mhdostal mhdostal Sep 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm OK with @rolson 's suggestion. That does solve the issue with the "close" button and allows clients to set it up how they want. It's a good point that our components should not assume their container. We could be better trying different containers to verify that.

@dfeinzimer dfeinzimer marked this pull request as ready for review August 14, 2024 17:58
/// Specifies the visibility of the popup title.
/// - Parameter visibility: The visibility of the popup title.
/// - Since: 200.6
public func popupTitle(_ visibility: TitleVisibility) -> Self {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The title and close button are not necessarily related, other than they have been occupying the same space. It may be that the client doesn't want the title in the popup/view but still requires the close button. So I'm OK having them both be distinct and put the onus on the client to figure out how they want it to display/behave.

Comment on lines +20 to +25
enum TitleVisibility: Sendable {
/// The form title is hidden.
case hidden
/// The form title is visible.
case visible
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why an enum instead of a Bool? shouldShowTitle, or something similar?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants