iOS/Sources/Shared/DesignSystem/Components/ModalCloseButton.swift
Bruno Pantaleão Gonçalves 5f9dd2b16c
Increase empty state delay and tweak close buttons on modal presentations (#3805)
<!-- Thank you for submitting a Pull Request and helping to improve Home
Assistant. Please complete the following sections to help the processing
and review of your changes. Please do not delete anything from this
template. -->

## Summary
<!-- Provide a brief summary of the changes you have made and most
importantly what they aim to achieve -->

## Screenshots
<!-- If this is a user-facing change not in the frontend, please include
screenshots in light and dark mode. -->

## Link to pull request in Documentation repository
<!-- Pull requests that add, change or remove functionality must have a
corresponding pull request in the Companion App Documentation repository
(https://github.com/home-assistant/companion.home-assistant). Please add
the number of this pull request after the "#" -->
Documentation: home-assistant/companion.home-assistant#

## Any other notes
<!-- If there is any other information of note, like if this Pull
Request is part of a bigger change, please include it here. -->

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-09-10 10:40:23 -03:00

39 lines
957 B
Swift

#if !os(watchOS)
import SwiftUI
public struct ModalCloseButton: View {
@Environment(\.dismiss) private var dismiss
private let alternativeAction: (() -> Void)?
private let tint: Color
/// When alternative action is set, the button will execute this action instead of dismissing the view.
public init(
tint: Color = Color.secondary,
alternativeAction: (() -> Void)? = nil
) {
self.alternativeAction = alternativeAction
self.tint = tint
}
public var body: some View {
Button(action: {
tapAction()
}, label: {
Image(systemSymbol: .xmark)
.resizable()
.frame(width: 16, height: 16)
})
.buttonStyle(.plain)
.foregroundStyle(tint)
}
private func tapAction() {
if let alternativeAction {
alternativeAction()
} else {
dismiss()
}
}
}
#endif