We've tried to make Formotion as extensible as possible so you can create new row types. If you think others could use it, feel free to submit a pull request.
Add a subclass of RowType::Base
to the Formotion::RowType
module and conform your class name to the form ____Row
.
Example:
module Formotion
module RowType
class MyNewRow < Base
end
end
end
RowType.for
looks for classes inside the module with match that name form (see row_type.rb
). This allows you to refer to your new type in the Formotion hashes as an underscored version of your class name:
Formotion::Form.new({
sections: [{
rows: [{
title: "MyNewRow Example",
type: :my_new
}]
}]
})
The flow of using RowType
is:
row.make_cell
is called, which calls...Formotion::RowCellBuilder.make_cell(row)
, which calls...row.object.build_cell(cell)
This is where you come inYourRowType#build_cell(<#UITableViewCell>)
should setup the cell however you need to.build_cell
should return an instance of UITextField if necessary. SeeStringRow#build_cell
for an example.- Lastly,
YourRowType#after_build(#<UITableViewCell>)
is called when therow
object is entirely setup and right before it's passed back to the table view for drawing.
So the meat of your overrides should happen in build_cell.
Ex:
module Formotion
module RowType
class MyNewRow < Base
def build_cell(cell)
blue_box = UIView.alloc.initWithFrame [[10, 10], [30, 30]]
blux_box.backgroundColor = UIColor.blueColor
cell.addSubview = blue_box
# return nil because no UITextField added.
nil
end
end
end
end
Your subclass can override these methods:
#on_select(tableView, tableViewDelegate)
- Called when the row is tapped by the user.
#cell_style
- The UITableViewCellStyle
for the row type. By default is UITableViewCellStyleSubtitle