class MotionForm::Base

Attributes

keyboard_avoiding_delegate[R]

Public Instance Methods

build_section(title) click to toggle source
# File lib/project/form/base.rb, line 66
def build_section(title)
  MotionForm::Section.new(title).tap do |section|
    sections << section
  end
end
did_begin_editing(notification) click to toggle source
# File lib/project/form/base.rb, line 40
def did_begin_editing(notification)
  unless window.nil?
    keyboard_avoiding_delegate.textFieldDidBeginEditing(notification.userInfo[:text_field])
  end
end
did_end_editing(notification) click to toggle source
# File lib/project/form/base.rb, line 46
def did_end_editing(notification)
  unless window.nil?
    keyboard_avoiding_delegate.textFieldDidEndEditing(notification.userInfo[:text_field])
  end
end
init() click to toggle source
# File lib/project/form/base.rb, line 9
def init
  initWithFrame(frame, style: UITableViewStylePlain).tap do |f|
    f.register_cells
    f.translatesAutoresizingMaskIntoConstraints = false

    f.dataSource = self
    f.delegate   = self

    f.addGestureRecognizer(tap_recognizer)

    @keyboard_avoiding_delegate = Motion::KeyboardAvoiding.new(f)

    listen
  end
end
listen() click to toggle source
# File lib/project/form/base.rb, line 35
def listen
  observers << notification_center.addObserver(self, selector: 'did_begin_editing:', name: 'FormCellDidBeginEditing', object: nil)
  observers << notification_center.addObserver(self, selector: 'did_end_editing:', name: 'FormCellDidEndEditing', object: nil)
end
notification_center() click to toggle source
# File lib/project/form/base.rb, line 56
def notification_center
  NSNotificationCenter.defaultCenter
end
numberOfSectionsInTableView(table_view) click to toggle source
# File lib/project/form/base.rb, line 82
def numberOfSectionsInTableView(table_view)
  sections.count
end
observers() click to toggle source
# File lib/project/form/base.rb, line 52
def observers
  @observers ||= []
end
register_cells() click to toggle source
# File lib/project/form/base.rb, line 76
def register_cells
  MotionForm.registered_cells.each do |klass|
    registerClass(klass, forCellReuseIdentifier: klass::IDENTIFIER)
  end
end
render() click to toggle source
# File lib/project/form/base.rb, line 141
def render
  notification_center.postNotificationName('FormWillRender', object: self, userInfo: nil)

  Hash[render_values]
end
render_values() click to toggle source
# File lib/project/form/base.rb, line 147
def render_values
  value_rows.map { |row| [row.key, row.value] }
end
rows() click to toggle source
# File lib/project/form/base.rb, line 122
def rows
  sections.map(&:rows).flatten
end
section(title = '') { |section| ... } click to toggle source
# File lib/project/form/base.rb, line 60
def section(title = '')
  build_section(title).tap do |section|
    yield section
  end
end
sections() click to toggle source
# File lib/project/form/base.rb, line 72
def sections
  @sections ||= []
end
tableView(table_view, numberOfRowsInSection: section_index) click to toggle source
# File lib/project/form/base.rb, line 86
def tableView(table_view, numberOfRowsInSection: section_index)
  sections[section_index].rows.count
end
tap_recognizer() click to toggle source
# File lib/project/form/base.rb, line 25
def tap_recognizer
  @tap_recognizer ||= UITapGestureRecognizer.alloc.init.tap do |recognizer|
    recognizer.addTarget(self, action: 'tapped:')
  end
end
tapped(recognizer) click to toggle source
# File lib/project/form/base.rb, line 31
def tapped(recognizer)
  endEditing(true)
end
valid?() click to toggle source
# File lib/project/form/base.rb, line 126
def valid?
  notification_center.postNotificationName('FormWillValidate', object: self, userInfo: nil)

  rows.select { |row| row.is_a? TextInputRow }.all? { |row| row.valid? }
end
value_rows() click to toggle source
# File lib/project/form/base.rb, line 151
def value_rows
  rows.select { |row| row.has_value? }
end