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

DON-1029 Segmented control #2138

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

faurevid
Copy link
Contributor

Created new segmented control component
Added documentation, tests and screenshots

Jira ticket: DON-1029
Figma design: https://www.figma.com/design/irZ3YBx8vOm16ICkAr7mB3/Backpack-Components?m=auto&node-id=49086-3871&t=pQApQKbd31dMaLrK-1

Day Night
iPhone-swiftui_segmented-control___default_lm iPhone-swiftui_segmented-control___default_dm

Remember to include the following changes:

If you are curious about how we review, please read through the code review guidelines

Created new segmented control component
Added documentation, tests and screenshots
Copy link
Contributor

Snapshots were updated. Please verify the changes match the expected layout.

' D Backpack-SwiftUI/Tests/BannerAlert/Snapshots/BPKBannerAlertTests/test_multilineBannerAlert.dark-mode.png'%0A' D Backpack-SwiftUI/Tests/BannerAlert/Snapshots/BPKBannerAlertTests/test_multilineBannerAlert.light-mode.png'%0A' D Backpack-SwiftUI/Tests/BannerAlert/Snapshots/BPKBannerAlertTests/test_multilineBannerAlert.rtl.png'%0A' D Backpack-SwiftUI/Tests/NavigationTabGroup/Snapshots/BPKNavigationTabGroupTests/test_dark.dark-mode.png'%0A' D Backpack-SwiftUI/Tests/NavigationTabGroup/Snapshots/BPKNavigationTabGroupTests/test_dark.light-mode.png'%0A' D Backpack-SwiftUI/Tests/NavigationTabGroup/Snapshots/BPKNavigationTabGroupTests/test_dark.rtl.png'%0A' D Backpack-SwiftUI/Tests/NavigationTabGroup/Snapshots/BPKNavigationTabGroupTests/test_default.dark-mode.png'%0A' D Backpack-SwiftUI/Tests/NavigationTabGroup/Snapshots/BPKNavigationTabGroupTests/test_default.light-mode.png'%0A' D Backpack-SwiftUI/Tests/NavigationTabGroup/Snapshots/BPKNavigationTabGroupTests/test_default.rtl.png'%0A' D Backpack-SwiftUI/Tests/SearchInputSummary/Snapshots/BPKSearchInputSummaryTests/test_clearableField_withPrefixIcon.dark-mode.png'%0A' D Backpack-SwiftUI/Tests/SearchInputSummary/Snapshots/BPKSearchInputSummaryTests/test_clearableField_withPrefixIcon.light-mode.png'%0A' D Backpack-SwiftUI/Tests/SearchInputSummary/Snapshots/BPKSearchInputSummaryTests/test_clearableField_withPrefixIcon.rtl.png'%0A' D Backpack-SwiftUI/Tests/SearchInputSummary/Snapshots/BPKSearchInputSummaryTests/test_disabledField_withCustomPrefixText.dark-mode.png'%0A' D Backpack-SwiftUI/Tests/SearchInputSummary/Snapshots/BPKSearchInputSummaryTests/test_disabledField_withCustomPrefixText.light-mode.png'%0A' D Backpack-SwiftUI/Tests/SearchInputSummary/Snapshots/BPKSearchInputSummaryTests/test_disabledField_withCustomPrefixText.rtl.png'%0A' D Backpack-SwiftUI/Tests/SearchInputSummary/Snapshots/BPKSearchInputSummaryTests/test_disabledField_withPrefixIcon.dark-mode.png'%0A' D Backpack-SwiftUI/Tests/SearchInputSummary/Snapshots/BPKSearchInputSummaryTests/test_disabledField_withPrefixIcon.light-mode.png'%0A' D Backpack-SwiftUI/Tests/SearchInputSummary/Snapshots/BPKSearchInputSummaryTests/test_disabledField_withPrefixIcon.rtl.png'%0A' D Backpack-SwiftUI/Tests/SearchInputSummary/Snapshots/BPKSearchInputSummaryTests/test_errorField_withCustomPrefixText.dark-mode.png'%0A' D Backpack-SwiftUI/Tests/SearchInputSummary/Snapshots/BPKSearchInputSummaryTests/test_errorField_withCustomPrefixText.light-mode.png'%0A' D Backpack-SwiftUI/Tests/SearchInputSummary/Snapshots/BPKSearchInputSummaryTests/test_errorField_withCustomPrefixText.rtl.png'%0A' D Backpack-SwiftUI/Tests/SearchInputSummary/Snapshots/BPKSearchInputSummaryTests/test_errorField_withPrefixIcon.dark-mode.png'%0A' D Backpack-SwiftUI/Tests/SearchInputSummary/Snapshots/BPKSearchInputSummaryTests/test_errorField_withPrefixIcon.light-mode.png'%0A' D Backpack-SwiftUI/Tests/SearchInputSummary/Snapshots/BPKSearchInputSummaryTests/test_errorField_withPrefixIcon.rtl.png'%0A' D Backpack-SwiftUI/Tests/SearchInputSummary/Snapshots/BPKSearchInputSummaryTests/test_validField_withCustomPrefixText.dark-mode.png'%0A' D Backpack-SwiftUI/Tests/SearchInputSummary/Snapshots/BPKSearchInputSummaryTests/test_validField_withCustomPrefixText.light-mode.png'%0A' D Backpack-SwiftUI/Tests/SearchInputSummary/Snapshots/BPKSearchInputSummaryTests/test_validField_withCustomPrefixText.rtl.png'%0A' D Backpack-SwiftUI/Tests/SearchInputSummary/Snapshots/BPKSearchInputSummaryTests/test_validField_withPrefixIcon.dark-mode.png'%0A' D Backpack-SwiftUI/Tests/SearchInputSummary/Snapshots/BPKSearchInputSummaryTests/test_validField_withPrefixIcon.light-mode.png'%0A' D Backpack-SwiftUI/Tests/SearchInputSummary/Snapshots/BPKSearchInputSummaryTests/test_validField_withPrefixIcon.rtl.png'%0A' M Backpack-SwiftUI/Tests/SegmentedControl/Snapshots/BPKSegmentedControlTests/test_accessibility.a11y.png'%0A' M Backpack-SwiftUI/Tests/SegmentedControl/Snapshots/BPKSegmentedControlTests/test_firstSegmentSelected.dark-mode.png'%0A' M Backpack-SwiftUI/Tests/SegmentedControl/Snapshots/BPKSegmentedControlTests/test_firstSegmentSelected.light-mode.png'%0A' M Backpack-SwiftUI/Tests/SegmentedControl/Snapshots/BPKSegmentedControlTests/test_firstSegmentSelected.rtl.png'%0A' D Backpack-SwiftUI/Tests/TextField/Snapshots/BPKTextFieldTests/test_clearableField_withCustomPrefixText.dark-mode.png'%0A' D Backpack-SwiftUI/Tests/TextField/Snapshots/BPKTextFieldTests/test_clearableField_withCustomPrefixText.light-mode.png'%0A' D Backpack-SwiftUI/Tests/TextField/Snapshots/BPKTextFieldTests/test_clearableField_withCustomPrefixText.rtl.png'%0A' D Backpack-SwiftUI/Tests/TextField/Snapshots/BPKTextFieldTests/test_clearableField_withPrefixIcon.dark-mode.png'%0A' D Backpack-SwiftUI/Tests/TextField/Snapshots/BPKTextFieldTests/test_clearableField_withPrefixIcon.light-mode.png'%0A' D Backpack-SwiftUI/Tests/TextField/Snapshots/BPKTextFieldTests/test_clearableField_withPrefixIcon.rtl.png'%0A' D Backpack-SwiftUI/Tests/TextField/Snapshots/BPKTextFieldTests/test_defaultSettings_withCustomPrefixText.dark-mode.png'%0A' D Backpack-SwiftUI/Tests/TextField/Snapshots/BPKTextFieldTests/test_defaultSettings_withCustomPrefixText.light-mode.png'%0A' D Backpack-SwiftUI/Tests/TextField/Snapshots/BPKTextFieldTests/test_defaultSettings_withCustomPrefixText.rtl.png'%0A' D Backpack-SwiftUI/Tests/TextField/Snapshots/BPKTextFieldTests/test_defaultSettings_withPrefixIcon.dark-mode.png'%0A' D Backpack-SwiftUI/Tests/TextField/Snapshots/BPKTextFieldTests/test_defaultSettings_withPrefixIcon.light-mode.png'%0A' D Backpack-SwiftUI/Tests/TextField/Snapshots/BPKTextFieldTests/test_defaultSettings_withPrefixIcon.rtl.png'%0A' D Backpack-SwiftUI/Tests/TextField/Snapshots/BPKTextFieldTests/test_disabledField_withCustomPrefixText.dark-mode.png'%0A' D Backpack-SwiftUI/Tests/TextField/Snapshots/BPKTextFieldTests/test_disabledField_withCustomPrefixText.light-mode.png'%0A' D Backpack-SwiftUI/Tests/TextField/Snapshots/BPKTextFieldTests/test_disabledField_withCustomPrefixText.rtl.png'%0A' D Backpack-SwiftUI/Tests/TextField/Snapshots/BPKTextFieldTests/test_disabledField_withPrefixIcon.dark-mode.png'%0A' D Backpack-SwiftUI/Tests/TextField/Snapshots/BPKTextFieldTests/test_disabledField_withPrefixIcon.light-mode.png'%0A' D Backpack-SwiftUI/Tests/TextField/Snapshots/BPKTextFieldTests/test_disabledField_withPrefixIcon.rtl.png'%0A' D Backpack-SwiftUI/Tests/TextField/Snapshots/BPKTextFieldTests/test_emptyField_withCustomPrefixText.dark-mode.png'%0A' D Backpack-SwiftUI/Tests/TextField/Snapshots/BPKTextFieldTests/test_emptyField_withCustomPrefixText.light-mode.png'%0A' D Backpack-SwiftUI/Tests/TextField/Snapshots/BPKTextFieldTests/test_emptyField_withCustomPrefixText.rtl.png'%0A' D Backpack-SwiftUI/Tests/TextField/Snapshots/BPKTextFieldTests/test_emptyField_withPrefixIcon.dark-mode.png'%0A' D Backpack-SwiftUI/Tests/TextField/Snapshots/BPKTextFieldTests/test_emptyField_withPrefixIcon.light-mode.png'%0A' D Backpack-SwiftUI/Tests/TextField/Snapshots/BPKTextFieldTests/test_emptyField_withPrefixIcon.rtl.png'%0A' D Backpack-SwiftUI/Tests/TextField/Snapshots/BPKTextFieldTests/test_errorField_withCustomPrefixText.dark-mode.png'%0A' D Backpack-SwiftUI/Tests/TextField/Snapshots/BPKTextFieldTests/test_errorField_withCustomPrefixText.light-mode.png'%0A' D Backpack-SwiftUI/Tests/TextField/Snapshots/BPKTextFieldTests/test_errorField_withCustomPrefixText.rtl.png'%0A' D Backpack-SwiftUI/Tests/TextField/Snapshots/BPKTextFieldTests/test_errorField_withPrefixIcon.dark-mode.png'%0A' D Backpack-SwiftUI/Tests/TextField/Snapshots/BPKTextFieldTests/test_errorField_withPrefixIcon.light-mode.png'%0A' D Backpack-SwiftUI/Tests/TextField/Snapshots/BPKTextFieldTests/test_errorField_withPrefixIcon.rtl.png'%0A' D Backpack-SwiftUI/Tests/TextField/Snapshots/BPKTextFieldTests/test_validField_withCustomPrefixText.dark-mode.png'%0A' D Backpack-SwiftUI/Tests/TextField/Snapshots/BPKTextFieldTests/test_validField_withCustomPrefixText.light-mode.png'%0A' D Backpack-SwiftUI/Tests/TextField/Snapshots/BPKTextFieldTests/test_validField_withCustomPrefixText.rtl.png'%0A' D Backpack-SwiftUI/Tests/TextField/Snapshots/BPKTextFieldTests/test_validField_withPrefixIcon.dark-mode.png'%0A' D Backpack-SwiftUI/Tests/TextField/Snapshots/BPKTextFieldTests/test_validField_withPrefixIcon.light-mode.png'%0A' D Backpack-SwiftUI/Tests/TextField/Snapshots/BPKTextFieldTests/test_validField_withPrefixIcon.rtl.png'%0A' M Example/Backpack.xcodeproj/project.pbxproj'

}
}
_selectedIndex = selectedIndex
let appearance = UISegmentedControl.appearance()
Copy link
Contributor

Choose a reason for hiding this comment

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

Here we have 2 issues:
-(1) Changing the style by this approach would affect all instances of Segmented Control globally, not only this instance.
-(2) The style should be customisable by the consumer via a style struct passing as argument to the component, while we can have default style.

if let accessibilityLabel = accessibilityLabel {
self.itemsAccessibilityLabel = Array(repeating: "", count: items.count)
for index in items.indices {
self.itemsAccessibilityLabel[index] = "\(accessibilityLabel)_\(index)"
Copy link
Contributor

Choose a reason for hiding this comment

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

We do not need itemsAccessibilityLabel as stored property. Instead we can use a helper when we set the elements. (line 60).

Also in another note for index in items.indices has potential for out-of-range crash, and if we wanted to keep it we should have changed that to for index in self.items.indices

}
.pickerStyle(.segmented)
.padding(.horizontal, BPKSpacing.base)
.accessibilityIdentifier(accessibilityLabel ?? "")
Copy link
Contributor

Choose a reason for hiding this comment

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

We should use If modifier (defined in ConditionalModifier.swift) to avoid setting empty accessibility identifiers.

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

Successfully merging this pull request may close these issues.

2 participants