Skip to content

Commit

Permalink
Merge pull request #121 from SchweizerischeBundesbahnen/feature/modal…
Browse files Browse the repository at this point in the history
…-view-cancel-button

Feature/modal view cancel button
  • Loading branch information
oliatsbb authored May 3, 2024
2 parents 1b29154 + c3c8426 commit d00bbb0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
4 changes: 2 additions & 2 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Release Notes SBBDesignSystemMobileSwiftUI for iOS & SwiftUI

## v1.2.0 - TBD
## v1.2.0 - 3 May 2024
### Features
* New components:
* SBBFooterBox to display a footer
* SBBHeaderBox to display a footer

### Improvements
* New icons
* added the option to hide the Cancel Button in the ModalView

### Bugfix
* SBBNotification and SBBPromotionBox: elements are now correctly read by VoiceOver.


## v1.1.3 - 2 February 2024
### Improvements
* SBBNotification: icon can be hidden
Expand Down
37 changes: 28 additions & 9 deletions SBBDesignSystemMobileSwiftUI/Views/SBBModalView/SBBModalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public struct SBBModalView<Content>: View where Content: View {
private let closeButtonAccessibilityText: Text
private let hideCloseButtonAccessibility: Bool
private var showBackButton: Bool
private let showCancelButton: Bool
private let actionOnBackButtonTouched: (() -> ())?
private let content: Content

Expand All @@ -88,17 +89,19 @@ public struct SBBModalView<Content>: View where Content: View {
- title: The Text to display as title.
- style: The style of the SBBModalView depending on how it is presented.
- showBackButton: An optional flag, controlling if a back button should be displayed at the top-trailing edge. Allowing navigation inside a SBBModalView.
- showCancelButton: An optional flag, controlling if the Cancel button on the top right should appear.
- actionOnBackButtonTouched: An optional action to be performed open touch events on the back button.
- content: A custom VIew to be shown underneath the title.
*/
public init(title: Text, style: Style = .full, titleAlignment: SBBModalViewTitleAlignment = .leading, isPresented: Binding<Bool>, closeButtonAccessibilityText: Text? = nil, hideCloseButtonAccessibility: Bool = false, showBackButton: Bool = false, actionOnBackButtonTouched: (() -> ())? = nil, @ViewBuilder content: @escaping () -> Content) {
public init(title: Text, style: Style = .full, titleAlignment: SBBModalViewTitleAlignment = .leading, isPresented: Binding<Bool>, closeButtonAccessibilityText: Text? = nil, hideCloseButtonAccessibility: Bool = false, showBackButton: Bool = false, showCancelButton: Bool = true, actionOnBackButtonTouched: (() -> ())? = nil, @ViewBuilder content: @escaping () -> Content) {
self.title = title
self.style = style
self.titleAlignment = titleAlignment
self._isPresented = isPresented
self.closeButtonAccessibilityText = closeButtonAccessibilityText ?? Text("close".localized)
self.hideCloseButtonAccessibility = hideCloseButtonAccessibility
self.showBackButton = showBackButton
self.showCancelButton = showCancelButton
self.actionOnBackButtonTouched = actionOnBackButtonTouched
self.content = content()
}
Expand Down Expand Up @@ -129,19 +132,22 @@ public struct SBBModalView<Content>: View where Content: View {
}
title
.padding(.top, 7)
.padding(.leading, 16)
.sbbFont(.large_light)
.accessibility(addTraits: .isHeader)
.accessibilitySortPriority(2)
Spacer()
Button(action: {
self.isPresented = false
}) {
Image(sbbIcon: .cross_small)
.accessibility(hidden: hideCloseButtonAccessibility)
.accessibility(label: closeButtonAccessibilityText)
.accessibilitySortPriority(2)
if (showCancelButton) {
Button(action: {
self.isPresented = false
}) {
Image(sbbIcon: .cross_small)
.accessibility(hidden: hideCloseButtonAccessibility)
.accessibility(label: closeButtonAccessibilityText)
.accessibilitySortPriority(2)
}
.buttonStyle(SBBIconButtonStyle(size: .small))
}
.buttonStyle(SBBIconButtonStyle(size: .small))
}
.sbbScreenPadding()
.padding(.horizontal, 8)
Expand Down Expand Up @@ -186,6 +192,10 @@ struct SBBModalView_Previews: PreviewProvider {
Text("Custom content")
}
.previewDisplayName("Popup, light, Back Button")
SBBModalView(title: Text("Modal View"), style: .popup, titleAlignment: .center, isPresented: .constant(true), showBackButton: true, showCancelButton: false) {
Text("Custom content")
}
.previewDisplayName("Popup, light, Back Button, No Cancel Button")
}
Group {
SBBModalView(title: Text("Modal View"), style: .bottom, isPresented: .constant(true)) {
Expand All @@ -205,6 +215,10 @@ struct SBBModalView_Previews: PreviewProvider {
Text("Custom content")
}
.previewDisplayName("Sheet, light, Back Button")
SBBModalView(title: Text("Modal View"), style: .bottom, titleAlignment: .center, isPresented: .constant(true), showBackButton: true, showCancelButton: false) {
Text("Custom content")
}
.previewDisplayName("Sheet, light, Back Button, No Cancel Button")
}
.previewLayout(.fixed(width: 400, height: 200))
Group {
Expand All @@ -225,6 +239,11 @@ struct SBBModalView_Previews: PreviewProvider {
Text("Custom content")
}
.previewDisplayName("Full, light, Back Button")
SBBModalView(title: Text("Modal View"), style: .full, titleAlignment: .center, isPresented: .constant(true), showBackButton: true, showCancelButton: false) {
Text("Custom content")
}
.previewDisplayName("Full, light, Back Button, No Cancel Button")

}
}
.previewLayout(.sizeThatFits)
Expand Down

0 comments on commit d00bbb0

Please sign in to comment.