FUIObjectFloorplan
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
FUIObjectSection
can be added. There are two types of sections are supported:FUIObjectListSection
: A section to show a list ofUITableViewCell
or its variants.FUIObjectCollectionSection
: A section to show a collection ofUICollectionViewCell
or its variants. Default collection view layout used isFUICollectionViewLayout.horizontalScrollDynamicSize
. 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
public private(set) var objectHeader: FUIObjectHeader { get }
-
The business object that this floorplan represents.
Declaration
Swift
@Published public var object: Entity { get set }
-
The
FUICoordinator
object that handles navigation when user performs certain actions. By default,FUIObjectStep.display
step will be triggered if user taps on a section element. AndFUIObjectStep.edit
will be triggered if user taps onedit
button on top-right of screen.Declaration
Swift
open var coordinator: FUICoordinator?
-
An optional closure for setting up the object header.
Declaration
Swift
open var objectHeaderProvider: ((Entity, FUIObjectHeader) -> Void)?
-
An optoinal closure for configuring sections in the floorplan.
Declaration
Swift
open var sectionsProvider: ((Entity) -> [FUIObjectSection])?
-
An optional closure for handling edit button tap action.
Declaration
Swift
open var editButtonDidTapHandler: ((Entity) -> Void)?
-
An optional closure for handling section element tap action.
Declaration
Swift
open var elementDidTapHandler: ((Any, IndexPath) -> Void)?
-
An optional closure for handling section header tap action.
Declaration
Swift
open var sectionHeaderDidTapHandler: ((UITableViewHeaderFooterView, Int) -> Void)?
-
An optional closure for handling section footer tap action.
Declaration
Swift
open var sectionFooterDidTapHandler: ((UITableViewHeaderFooterView, Int) -> Void)?
-
Creates a object floorplan.
Declaration
Swift
public init(object: Entity, style: UITableViewStyle = .grouped, objectHeaderProvider: ((Entity, FUIObjectHeader) -> Void)? = nil, sectionsProvider: ((Entity) -> [FUIObjectSection])? = nil)
Parameters
object
The business object that this floorplan represents.
style
Table view style of the floorplan. Default to
.grouped
.objectHeaderProvider
Optional closure for configuring object header in the floorplan.
sectionsProvider
Optional closure for configuring sections in the floorplan.
-
Reload the whole floorplan. (Both object header and sections)
Declaration
Swift
open func reloadData(animatingDifference: Bool = true)
Parameters
animatingDifference
Whether the difference after reloading should be animated.
-
Reload only the object header.
Declaration
Swift
open func reloadHeader()
-
Reload sections.
Declaration
Swift
open func reloadSections(animatingDifference: Bool = true)
Parameters
animatingDifference
Whether the difference after reloading should be animated.
-
The section element at a specific indexPath.
Declaration
Swift
public func element(at indexPath: IndexPath) -> Any?
Parameters
indexPath
The indexPath at which the element is located.
Return Value
The element at indexPath.