Sha256: a06ea26c1d8421405fd02c6469fe54e9f7a6af4a499f1bdb68e088539dd01b6f

Contents?: true

Size: 1.86 KB

Versions: 13

Compression:

Stored size: 1.86 KB

Contents

motion_require '../table/table_delegate.rb'
module MotionPrime
  class FormDelegate < TableDelegate
    def textFieldShouldReturn(text_field)
      table_section.on_input_return(text_field)
    end
    def textFieldShouldBeginEditing(text_field)
      text_field.respond_to?(:readonly) ? !text_field.readonly : true
    end
    def textFieldDidBeginEditing(text_field)
      table_section.on_input_edit_begin(text_field)
    end
    def textFieldDidEndEditing(text_field)
      table_section.on_input_edit_end(text_field)
    end

    def textField(text_field, shouldChangeCharactersInRange:range, replacementString:string)
      limit = (table_section.class.text_field_limits || {}).find do |field_name, limit|
        table_section.view("#{field_name}:input") == text_field
      end.try(:last)
      return true unless limit
      table_section.allow_string_replacement?(text_field, limit, range, string)
    end


    def textViewDidBeginEditing(text_view)
      table_section.on_input_edit_begin(text_view)
    end
    def textViewDidEndEditing(text_view)
      table_section.on_input_edit_end(text_view)
    end
    def textViewDidChange(text_view) # bug in iOS 7 - cursor is out of textView bounds
      line = text_view.caretRectForPosition(text_view.selectedTextRange.start)
      overflow = line.origin.y + line.size.height -
        (text_view.contentOffset.y + text_view.bounds.size.height - text_view.contentInset.bottom - text_view.contentInset.top)
      if overflow > 0
        offset = text_view.contentOffset
        offset.y += overflow + text_view.textContainerInset.bottom
        UIView.animate(duration: 0.2) do
          text_view.setContentOffset(offset)
        end
      end
    end

    def textView(text_view, shouldChangeTextInRange:range, replacementText:string)
      textField(text_view, shouldChangeCharactersInRange:range, replacementString:string)
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
motion-prime-0.7.2 motion-prime/sections/form/form_delegate.rb
motion-prime-0.7.1 motion-prime/sections/form/form_delegate.rb
motion-prime-0.7.0 motion-prime/sections/form/form_delegate.rb
motion-prime-0.6.0 motion-prime/sections/form/form_delegate.rb
motion-prime-0.5.7 motion-prime/sections/form/form_delegate.rb
motion-prime-0.5.6 motion-prime/sections/form/form_delegate.rb
motion-prime-0.5.5 motion-prime/sections/form/form_delegate.rb
motion-prime-0.5.4 motion-prime/sections/form/form_delegate.rb
motion-prime-0.5.3 motion-prime/sections/form/form_delegate.rb
motion-prime-0.5.2 motion-prime/sections/form/form_delegate.rb
motion-prime-0.5.1 motion-prime/sections/form/form_delegate.rb
motion-prime-0.5.0 motion-prime/sections/form/form_delegate.rb
motion-prime-0.4.5 motion-prime/sections/form/form_delegate.rb