FUIFilterFormCollectionViewCell
@MainActor
open class FUIFilterFormCollectionViewCell : FUIInlineValidationDrawingCollectionViewCell<FUIFilterFormView>, FUIFormCell
A UICollectionViewCell subclass that allows a user to read or enter a set of values using a grid of buttons. This is commonly used for composing filters.
The developer should set the following properties on the cell in their implementation of the UICollectionViewDataSource cellForItem(at:) function:
title: The title of the property.value: An array of the selected indexes in the control. Uses the same index as thevalueOptionsarray.- `valueOptions: A string array of titles for the buttons in the control
And an onChangeHandler:
onChangeHandler: a handler closure, which is invoked on changes to the value
Optionally, the developer may provide:
allowsMultipleSelection: Indicates whether multiple buttons may be selected simultaneously (true). Iffalse, the control behaves in “radio” mode. The default istrue.allowsEmptySelection: Indicates whether the control allows zero items to be selected (true). If false, then once a value has been selected by the developer or user, taps by the user on the last selected item will be ignored instead of deselecting the item. The default istrue.isEditable: Indicates whether the cell’s value may be modified. The default istrue.
The following is an example of usage in an application, UICollectionViewController:
// optionally, create an array of value option to localized string mappings
let buttonTitles: [[String: String]] = [["radius": "Distance"], ["price": "Price"], ["rating": "Ratings"], ["avail": "Availability"]]
// Register FUIFilterFormCollectionViewCell in viewDidLoad() method in the controller.
override func viewDidLoad() {
super.viewDidLoad()
self.collectionView.register(FUIFilterFormCollectionViewCell.self, forCellWithReuseIdentifier:
FUIFilterFormCollectionViewCell.reuseIdentifier)
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: FUIFilterFormCollectionViewCell.reuseIdentifier,
for: indexPath) as! FUIFilterFormCollectionViewCell
cell.valueOptions = buttonTitles.flatMap { $0.map { $0.value }}
cell.title = "Sort By"
cell.value = [1]
cell.allowsMultipleSelection = true
cell.allowsEmptySelection = false
// MARK: implement onChangeHandler
cell.onChangeHandler = { [weak self] newValue in
self.applyFilter(forDimensions: newValue) // here, the cell input is set to a filter function
}
return cell
}
## Theming Supported style classes:
fdlFUIFilterFormCollectionViewCell
fdlFUIFilterFormCollectionViewCell_title
fdlFUIFilterFormCollectionViewCell_item_contentView
fdlFUIFilterFormCollectionViewCell_item_titleLabel
fdlFUIFilterFormCollectionViewCell_item_contentView_selected
fdlFUIFilterFormCollectionViewCell_item_titleLabel_selected
-
Reuse identifier
Declaration
Swift
@MainActor open override class var reuseIdentifier: String { get } -
The key name of the cell.
Declaration
Swift
@MainActor public var keyName: String? { get set } -
The
FUIFilterValueViewin this view.Declaration
Swift
@MainActor public var filterValueView: FUIFilterValueView { get } -
The style of the cell. It can be configured as
.fixedfor same width, or.flexiblefor the dynamic width.Declaration
Swift
@MainActor public var buttonStyle: FUIFilterButtonSize { get set } -
Indicate whether the user can select an item or not. This is set to
trueby default.Declaration
Swift
@MainActor public var isEditable: Bool { get set } -
isEnabledandisEditableare in sync.Declaration
Swift
@MainActor public override var isEnabled: Bool { get set } -
Indicates whether the cell is a mandatory field.
The default value is
false.Declaration
Swift
@MainActor open var isRequired: Bool { get set } -
Indicates that the cell is a mandatory field.
The default value is
*.Declaration
Swift
@MainActor public var mandatoryIndicator: FUIText { get set } -
The type of the value.
Declaration
Swift
public typealias ValueType = [Int] -
The value of the cell.
Declaration
Swift
@MainActor public var value: [Int] { get set } -
Implementation of the change handler. This is invoked on changes to the
valueproperty.Declaration
Swift
@MainActor public var onChangeHandler: (([Int]) -> Void)? { get set } -
The array of the valid options.
Declaration
Swift
@objc @MainActor public var valueOptions: [String] { get set } -
Uses the
FUIFilterGroupto initialize theallowsMultipleSelection,allowsEmptySelection,valueOptions, andvalueproperties. ThevalueOptionswill be thetitleproperties of theFUIFilterItemobjects in the group. And thevalueproperty will be set based on theisActiveproperty of items.Note
TheisActiveproperty of the items will be updated according to the user actions. There is no need to update them in theonChangeHandler.Declaration
Swift
@MainActor public var filterGroup: FUIFilterGroup? { get set } -
Indicates whether the user may select multiple values. The default is
true.Declaration
Swift
@MainActor public var allowsMultipleSelection: Bool { get set } -
Indicates whether empty selection is allowed. The default is
true.Declaration
Swift
@MainActor public var allowsEmptySelection: Bool { get set } -
Indicates whether the control attempts to adjust segment widths based on their content widths. The default is
false.Declaration
Swift
@MainActor public var apportionsSegmentWidthsByContent: Bool { get set } -
Sets the button attributes for the specified control state in order to customize the button style. If this is not set, the default Fiori style attributes will be used.
Declaration
Swift
@MainActor public func setButtonAttributes(_ buttonAttributes: FUISegmentedControlButtonAttributes, for state: FUIControlState) -
Declaration
Swift
@MainActor open override func prepareForReuse()