-
Notifications
You must be signed in to change notification settings - Fork 57
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
feat: 🎸 [JIRA:IOSSDKBUG-434] filterFeedBack list mutil selections shown in section(cherrypick) #869
Merged
dyongxu
merged 1 commit into
SAP:rel-4.2
from
restaurantt:rel-4.2-filterFeedback-mutilSelection
Nov 7, 2024
+153
−45
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,54 +12,67 @@ public extension SearchListPickerItem { | |
/// - onTap: The closure when tap on item. | ||
/// - selectAll: The closure when click 'Select All' button. | ||
/// - updateSearchListPickerHeight: The closure to update the parent view. | ||
init(value: Binding<[Int]>, valueOptions: [String] = [], hint: String? = nil, allowsMultipleSelection: Bool, allowsEmptySelection: Bool, isSearchBarHidden: Bool = false, onTap: ((_ index: Int) -> Void)? = nil, selectAll: ((_ isAll: Bool) -> Void)? = nil, updateSearchListPickerHeight: ((CGFloat) -> Void)? = nil) { | ||
/// - disableListEntriesSection: A boolean value to indicate to disable entries section or not. | ||
init(value: Binding<[Int]>, valueOptions: [String] = [], hint: String? = nil, allowsMultipleSelection: Bool, allowsEmptySelection: Bool, isSearchBarHidden: Bool = false, disableListEntriesSection: Bool, onTap: ((_ index: Int) -> Void)? = nil, selectAll: ((_ isAll: Bool) -> Void)? = nil, updateSearchListPickerHeight: ((CGFloat) -> Void)? = nil) { | ||
self.init(value: value, valueOptions: valueOptions, hint: hint, onTap: onTap) | ||
|
||
self.allowsMultipleSelection = allowsMultipleSelection | ||
self.allowsEmptySelection = allowsEmptySelection | ||
self.isSearchBarHidden = isSearchBarHidden | ||
self.selectAll = selectAll | ||
self.updateSearchListPickerHeight = updateSearchListPickerHeight | ||
self.disableListEntriesSection = disableListEntriesSection | ||
} | ||
} | ||
|
||
extension SearchListPickerItem: View { | ||
public var body: some View { | ||
VStack(spacing: 0) { | ||
if allowsMultipleSelection { | ||
if _value.count != _valueOptions.count || allowsEmptySelection { | ||
self.selectAllView() | ||
} | ||
} else if _value.count == _valueOptions.count { | ||
self.selectAllView() | ||
} | ||
|
||
Divider().edgesIgnoringSafeArea(.all) | ||
List { | ||
ForEach(_valueOptions.filter { _searchText.isEmpty || $0.localizedStandardContains(_searchText) }, id: \.self) { item in | ||
let isSelected = self.isItemSelected(item) | ||
HStack { | ||
Text(item) | ||
.lineLimit(1) | ||
.foregroundStyle(Color.preferredColor(.primaryLabel)) | ||
.font(.fiori(forTextStyle: .body, weight: .regular)) | ||
Spacer() | ||
if isSelected { | ||
Image(systemName: "checkmark") | ||
#if !os(visionOS) | ||
.foregroundStyle(Color.preferredColor(.tintColor)) | ||
#else | ||
.foregroundStyle(Color.preferredColor(.primaryLabel)) | ||
#endif | ||
if !disableListEntriesSection, _value.count > 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Empty Count Violation: Prefer checking |
||
self.selectionHeader() | ||
|
||
Section { | ||
let selectedOptions = _value.wrappedValue.map { _valueOptions[$0] } | ||
ForEach(selectedOptions.filter { _searchText.isEmpty || $0.localizedStandardContains(_searchText) }, id: \.self) { item in | ||
self.rowView(value: item, isSelected: true) | ||
.padding(0) | ||
.contentShape(Rectangle()) | ||
.onTapGesture { | ||
guard let index = findIndex(of: item) else { | ||
return | ||
} | ||
_onTap?(index) | ||
} | ||
} | ||
|
||
Rectangle().fill(Color.preferredColor(.primaryGroupedBackground)) | ||
.frame(height: 30) | ||
.listRowInsets(EdgeInsets()) | ||
} | ||
.padding(0) | ||
.contentShape(Rectangle()) | ||
.onTapGesture { | ||
guard let index = findIndex(of: item) else { | ||
return | ||
} | ||
|
||
Section { | ||
if allowsMultipleSelection { | ||
if _value.count != _valueOptions.count || allowsEmptySelection { | ||
self.selectAllView() | ||
} | ||
_onTap?(index) | ||
} else if _value.count == _valueOptions.count { | ||
self.selectAllView() | ||
} else { | ||
EmptyView() | ||
} | ||
ForEach(_valueOptions.filter { _searchText.isEmpty || $0.localizedStandardContains(_searchText) }, id: \.self) { item in | ||
let isSelected = self.isItemSelected(item) | ||
self.rowView(value: item, isSelected: isSelected) | ||
.padding(0) | ||
.contentShape(Rectangle()) | ||
.onTapGesture { | ||
guard let index = findIndex(of: item) else { | ||
return | ||
} | ||
_onTap?(index) | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -69,10 +82,10 @@ extension SearchListPickerItem: View { | |
} | ||
DispatchQueue.main.async { | ||
let popverHeight = Screen.bounds.size.height - StatusBar.height | ||
let totalSpacing: CGFloat = (UIDevice.current.userInterfaceIdiom == .pad ? 8 : 16) * 2 | ||
let totalPadding: CGFloat = (UIDevice.current.userInterfaceIdiom == .pad ? 13 : 16) * 2 | ||
let totalSpacing: CGFloat = (UIDevice.current.userInterfaceIdiom != .phone ? 8 : 16) * 2 | ||
let totalPadding: CGFloat = (UIDevice.current.userInterfaceIdiom != .phone ? 13 : 16) * 2 | ||
let safeAreaInset = self.getSafeAreaInsets() | ||
var maxScrollViewHeight = popverHeight - totalSpacing - totalPadding - (self.isSearchBarHidden ? 0 : 52) - 56 - safeAreaInset.top - safeAreaInset.bottom - (UIDevice.current.userInterfaceIdiom == .pad ? 250 : 30) | ||
var maxScrollViewHeight = popverHeight - totalSpacing - totalPadding - (self.isSearchBarHidden ? 0 : 52) - 56 - safeAreaInset.top - safeAreaInset.bottom - (UIDevice.current.userInterfaceIdiom != .phone ? 250 : 30) | ||
maxScrollViewHeight -= self._keyboardHeight | ||
self._height = min(scrollView.contentSize.height, maxScrollViewHeight) | ||
var isSelectAllViewShow = false | ||
|
@@ -90,8 +103,10 @@ extension SearchListPickerItem: View { | |
.frame(minWidth: UIDevice.current.userInterfaceIdiom != .phone ? popoverWidth : nil) | ||
.scrollContentBackground(.hidden) | ||
.padding(0) | ||
.environment(\.defaultMinListRowHeight, 0) | ||
.environment(\.defaultMinListHeaderHeight, 0) | ||
.ifApply(!isSearchBarHidden, content: { v in | ||
v.searchable(text: $_searchText, placement: .automatic) | ||
v.searchable(text: $_searchText, placement: .navigationBarDrawer(displayMode: .always)) | ||
.onReceive(NotificationCenter.default.publisher(for: UIApplication.keyboardDidShowNotification)) { notif in | ||
let rect = (notif.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect) ?? .zero | ||
self._keyboardHeight = rect.height | ||
|
@@ -103,6 +118,43 @@ extension SearchListPickerItem: View { | |
} | ||
} | ||
|
||
private func rowView(value: String, isSelected: Bool) -> some View { | ||
HStack { | ||
Text(value) | ||
.lineLimit(1) | ||
.foregroundStyle(Color.preferredColor(.primaryLabel)) | ||
.font(.fiori(forTextStyle: .body, weight: .regular)) | ||
Spacer() | ||
if isSelected { | ||
Image(systemName: "checkmark") | ||
#if !os(visionOS) | ||
.foregroundStyle(Color.preferredColor(.tintColor)) | ||
#else | ||
.foregroundStyle(Color.preferredColor(.primaryLabel)) | ||
#endif | ||
} | ||
} | ||
} | ||
|
||
private func selectionHeader() -> some View { | ||
HStack { | ||
Text(NSLocalizedString("Selected", tableName: "FioriSwiftUICore", bundle: Bundle.accessor, comment: "")) | ||
.foregroundStyle(Color.preferredColor(.secondaryLabel)) | ||
.font(.fiori(forTextStyle: .subheadline, weight: .regular)) | ||
Spacer() | ||
} | ||
.padding([.leading, .trailing], UIDevice.current.userInterfaceIdiom != .phone ? 13 : 16) | ||
.padding([.top, .bottom], 8) | ||
.background(Color.preferredColor(.secondaryGroupedBackground)) | ||
.listRowInsets(EdgeInsets()) | ||
.alignmentGuide(.listRowSeparatorLeading) { dimensions in | ||
dimensions[.leading] | ||
} | ||
.alignmentGuide(.listRowSeparatorTrailing) { dimensions in | ||
dimensions[.trailing] | ||
} | ||
} | ||
|
||
private func selectAllView() -> some View { | ||
HStack { | ||
Text(NSLocalizedString("All", tableName: "FioriSwiftUICore", bundle: Bundle.accessor, comment: "")) | ||
|
@@ -113,10 +165,20 @@ extension SearchListPickerItem: View { | |
selectAll?(_value.count != _valueOptions.count) | ||
}) { | ||
Text(_value.count == _valueOptions.count ? NSLocalizedString("Deselect All", tableName: "FioriSwiftUICore", bundle: Bundle.accessor, comment: "") : NSLocalizedString("Select All", tableName: "FioriSwiftUICore", bundle: Bundle.accessor, comment: "")) | ||
} | ||
.foregroundStyle(Color.preferredColor(.tintColor)) | ||
.font(.fiori(forTextStyle: .subheadline, weight: .regular)) | ||
}.buttonStyle(PlainButtonStyle()) | ||
} | ||
.padding([.leading, .trailing], UIDevice.current.userInterfaceIdiom == .pad ? 13 : 16) | ||
.padding([.leading, .trailing], UIDevice.current.userInterfaceIdiom != .phone ? 13 : 16) | ||
.padding([.top, .bottom], 8) | ||
.background(Color.preferredColor(.secondaryGroupedBackground)) | ||
.listRowInsets(EdgeInsets()) | ||
.alignmentGuide(.listRowSeparatorLeading) { dimensions in | ||
dimensions[.leading] | ||
} | ||
.alignmentGuide(.listRowSeparatorTrailing) { dimensions in | ||
dimensions[.trailing] | ||
} | ||
} | ||
|
||
private func isItemSelected(_ item: String) -> Bool { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nesting Violation: Types should be nested at most 1 level deep (nesting)