FUIObjectFloorplan
@MainActor
open class FUIObjectFloorplan<Entity> : UITableViewController, UICollectionViewDataSource, UICollectionViewDelegate where Entity : Hashable, Entity : Identifiable
A generic UITableViewController subclass for displaying different properties of a business object.
Floorplan Structure
- On the top of view is
FUIObjectHeader(optional) - Under the header, any number of
FUIObjectSectioncan be added. There are two types of sections are supported:FUIObjectListSection: A section to show a list ofUITableViewCellor its variants.FUIObjectCollectionSection: A section to show a collection ofUICollectionViewCellor its variants. Default collection view layout used isFUICollectionViewLayout.horizontalScroll. Developer can set their own layout object if needed.
Usage
Data Binding
// Closure for object header data binding
let objectHeaderBinding: ((Product, FUIObjectHeader) -> Void)? = { _, objectHeader in
objectHeader.headlineText = "Three Phase Pad Mounted Transformer (533423)"
objectHeader.subheadlineText = "Electric Asset 533423"
objectHeader.bodyText = "Three Phase Pad Mounted Transformer (533423)"
objectHeader.footnoteText = "Temperature sensor predicts overheating failure in 4 days"
objectHeader.statusText = "Available"
objectHeader.detailImage = #imageLiteral(resourceName: "attachment009.5")
}
// List section definition
class LocationSection: FUIObjectListSection {
lazy var cellProvider: ((AnyTableBasedFloorplan, IndexPath, AnyHashable) -> UITableViewCell)? = { floorplan, indexPath, element in
let cell = floorplan.base.tableView.dequeueReusableCell(withIdentifier: FUIObjectTableViewCell.reuseIdentifier, for: indexPath) as! FUIObjectTableViewCell
// set properties for object cell
return cell
}
var cellTypeAndReuseIdentifier: (AnyClass, String) {
return (FUIObjectTableViewCell.self, FUIObjectTableViewCell.reuseIdentifier)
}
}
// Collection section definition
class ProductComponentsSection: FUIObjectCollectionSection {
var elements: [AnyHashable]
lazy var cellProvider: ((AnyTableBasedFloorplan, UICollectionView, IndexPath, AnyHashable) -> UICollectionViewCell)? = { _, collectionView, indexPath, element in
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MyThumbnailCollectionViewCell.reuseIdentifier, for: indexPath) as! MyThumbnailCollectionViewCell
// set properties for MyThumbnailCollectionViewCell
return cell
}
lazy var headerProvider: ((AnyTableBasedFloorplan, Int) -> UITableViewHeaderFooterView)? = { [unowned self] floorplan, _ in
let header = floorplan.base.tableView.dequeueReusableHeaderFooterView(withIdentifier: FUITableViewHeaderFooterView.reuseIdentifier) as! FUITableViewHeaderFooterView
header.style = .title
header.titleLabel.text = "Subcomponents"
return header
}
var cellTypeAndReuseIdentifier: (AnyClass, String) {
return (MyThumbnailCollectionViewCell.self, MyThumbnailCollectionViewCell.reuseIdentifier)
}
init(components: [String]) {
self.elements = components
}
}
let objectFloorplan = FUIObjectFloorplan(object: Product(), style: .grouped, objectHeaderProvider: objectHeaderBinding)
objectFloorplan.sectionsProvider = { _ in
return [
LocationSection(),
ProductComponentsSection(components: components)
]
}
Tap action handling
Implement elementDidTapHandler to handle the tap action on section elements. For header and footer use sectionHeaderDidTapHandler and sectionFooterDidTapHandler.
Theming
Supported ObjectHeader class paths:
fdlFUIObjectFloorplan_objectHeader
Supported ObjectHeader attributes:
Refer to FUIObjectHeader documentation for more information.
-
The object header showing on top of the floorplan.
Declaration
Swift
@MainActor public private(set) var objectHeader: FUIObjectHeader { get } -
The business object that this floorplan represents.
Declaration
Swift
@Published @MainActor public var object: Entity { get set } -
The
FUICoordinatorobject that handles navigation when user performs certain actions. By default,FUIObjectStep.displaystep will be triggered if user taps on a section element. AndFUIObjectStep.editwill be triggered if user taps oneditbutton on top-right of screen.Declaration
Swift
@MainActor open var coordinator: FUICoordinator? -
An optional closure for setting up the object header.
Declaration
Swift
@MainActor open var objectHeaderProvider: ((Entity, FUIObjectHeader) -> Void)? -
An optoinal closure for configuring sections in the floorplan.
Declaration
Swift
@MainActor open var sectionsProvider: ((Entity) -> [FUIObjectSection])? -
An optional closure for handling edit button tap action.
Declaration
Swift
@MainActor open var editButtonDidTapHandler: ((Entity) -> Void)? -
An optional closure for handling section element tap action.
Declaration
Swift
@MainActor open var elementDidTapHandler: ((Any, IndexPath) -> Void)? -
An optional closure for handling section header tap action.
Declaration
Swift
@MainActor open var sectionHeaderDidTapHandler: ((UITableViewHeaderFooterView, Int) -> Void)? -
An optional closure for handling section footer tap action.
Declaration
Swift
@MainActor open var sectionFooterDidTapHandler: ((UITableViewHeaderFooterView, Int) -> Void)? -
Creates a object floorplan.
Declaration
Swift
@MainActor public init(object: Entity, style: UITableViewStyle = .grouped, objectHeaderProvider: ((Entity, FUIObjectHeader) -> Void)? = nil, sectionsProvider: ((Entity) -> [FUIObjectSection])? = nil)Parameters
objectThe business object that this floorplan represents.
styleTable view style of the floorplan. Default to
.grouped.objectHeaderProviderOptional closure for configuring object header in the floorplan.
sectionsProviderOptional closure for configuring sections in the floorplan.
-
Reload the whole floorplan. (Both object header and sections)
Declaration
Swift
@MainActor open func reloadData(animatingDifference: Bool = true)Parameters
animatingDifferenceWhether the difference after reloading should be animated.
-
Reload only the object header.
Declaration
Swift
@MainActor open func reloadHeader() -
Reload sections.
Declaration
Swift
@MainActor open func reloadSections(animatingDifference: Bool = true)Parameters
animatingDifferenceWhether the difference after reloading should be animated.
-
The section element at a specific indexPath.
Declaration
Swift
@MainActor public func element(at indexPath: IndexPath) -> Any?Parameters
indexPathThe indexPath at which the element is located.
Return Value
The element at indexPath.