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

Floor Filter uses non-standard close button #857

Open
rolson opened this issue Sep 5, 2024 · 1 comment
Open

Floor Filter uses non-standard close button #857

rolson opened this issue Sep 5, 2024 · 1 comment
Labels
bug Something isn't working Effort - small A low level of effort to complete good first issue Good for newcomers

Comments

@rolson
Copy link
Contributor

rolson commented Sep 5, 2024

The close button in the floor filter looks like this:

image

However, with Apple's own apps, I see it often like this:

File (3)

What I've found works well for that look is this code:

            Button {
                dismiss()
            } label: {
                Image(systemName: "xmark.circle.fill")
                    .resizable()
                    .symbolRenderingMode(.hierarchical)
                    .foregroundStyle(.secondary)
                    .frame(width: 28, height: 28)
            }
            .buttonStyle(.plain)

And actually, I think we are already using that in the world scale scene view's calibration view.

You can actually create a predefined dismiss button with something like this:

struct DismissButton: View {
    enum Kind {
        case image
        case text
    }
    
    @Environment(\.dismiss) private var dismiss
    let kind: Kind
    
    init(kind: Kind = .image) {
        self.kind = kind
    }
    
    var body: some View {
        switch kind {
        case .image:
            Button {
                dismiss()
            } label: {
                Image(systemName: "xmark.circle.fill")
                    .resizable()
                    .symbolRenderingMode(.hierarchical)
                    .foregroundStyle(.secondary)
                    .frame(width: 28, height: 28)
            }
            .buttonStyle(.plain)
        case .text:
            Button {
                dismiss()
            } label: {
                Text("Done")
            }
        }
    }
}
@rolson rolson added bug Something isn't working good first issue Good for newcomers Effort - small A low level of effort to complete labels Sep 5, 2024
@yo1995
Copy link
Contributor

yo1995 commented Sep 5, 2024

image

Another way is to add a private SwiftUI view to use the native close button in UIKit.

Field Maps uses it, and a condensed version looks like

struct CloseButton: UIViewRepresentable {
    private let action: () -> Void
    init(action: @escaping () -> Void) { self.action = action }
    func makeUIView(context: Context) -> UIButton {
        let button = UIButton(type: .close, primaryAction: UIAction { _ in action() })
        for axis in [NSLayoutConstraint.Axis.horizontal, .vertical] {
            button.setContentCompressionResistancePriority(.required, for: axis)
            button.setContentHuggingPriority(.required, for: axis)
        }
        return button
    }
    func updateUIView(_ uiView: UIButton, context: Context) {}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Effort - small A low level of effort to complete good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants