Class: MotionPrime::BaseElement
- Inherits:
-
Object
- Object
- MotionPrime::BaseElement
- Extended by:
- HasClassFactory
- Includes:
- HasClassFactory, HasNormalizer, HasStyleChainBuilder, MotionSupport::Callbacks
- Defined in:
- motion-prime/elements/base_element.rb
Direct Known Subclasses
ButtonElement, DrawElement, GoogleMapElement, ImageElement, LabelElement, MapElement, ProgressHudElement, SpinnerElement, TableViewCellElement, TableViewElement, TextFieldElement, TextViewElement, ViewWithSectionElement, WebViewElement
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#screen ⇒ Object
Returns the value of attribute screen.
-
#section ⇒ Object
Returns the value of attribute section.
-
#styles ⇒ Object
Returns the value of attribute styles.
-
#view ⇒ Object
Returns the value of attribute view.
-
#view_class ⇒ Object
Returns the value of attribute view_class.
-
#view_name ⇒ Object
Returns the value of attribute view_name.
Class Method Summary collapse
- .after_render(method_name) ⇒ Object
- .before_render(method_name) ⇒ Object
- .factory(type, options = {}) ⇒ Object
Instance Method Summary collapse
-
#add_target(target = nil, action = 'on_click:', event = :touch) ⇒ Object
def dealloc pp ‘Deallocating elemenet’, self.name, self.to_s, computed_options super end.
- #bind_gesture(action, receiver = nil) ⇒ Object
- #compute_options! ⇒ Object
-
#computed_options ⇒ Object
Lazy-computing options.
- #hide ⇒ Object
-
#initialize(options = {}) ⇒ BaseElement
constructor
A new instance of BaseElement.
- #render(options = {}, &block) ⇒ Object
- #render!(&block) ⇒ Object
- #show ⇒ Object
- #update_with_options(new_options = {}) ⇒ Object
Methods included from HasClassFactory
camelize_factory, class_factory, low_camelize_factory
Methods included from HasStyleChainBuilder
Methods included from HasNormalizer
#normalize_object, #normalize_options
Constructor Details
#initialize(options = {}) ⇒ BaseElement
Returns a new instance of BaseElement.
20 21 22 23 24 25 26 27 28 29 30 |
# File 'motion-prime/elements/base_element.rb', line 20 def initialize( = {}) [:screen] = [:screen].try(:weak_ref) @options = @screen = [:screen] @section = [:section] @view_class = [:view_class] || 'UIView' @name = [:name] @block = [:block] @view_name = self.class_name_without_kvo.demodulize.underscore.gsub(/(_draw)?_element/, '') end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
15 16 17 |
# File 'motion-prime/elements/base_element.rb', line 15 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
15 16 17 |
# File 'motion-prime/elements/base_element.rb', line 15 def @options end |
#screen ⇒ Object
Returns the value of attribute screen.
15 16 17 |
# File 'motion-prime/elements/base_element.rb', line 15 def screen @screen end |
#section ⇒ Object
Returns the value of attribute section.
15 16 17 |
# File 'motion-prime/elements/base_element.rb', line 15 def section @section end |
#styles ⇒ Object
Returns the value of attribute styles.
15 16 17 |
# File 'motion-prime/elements/base_element.rb', line 15 def styles @styles end |
#view ⇒ Object
Returns the value of attribute view.
15 16 17 |
# File 'motion-prime/elements/base_element.rb', line 15 def view @view end |
#view_class ⇒ Object
Returns the value of attribute view_class.
15 16 17 |
# File 'motion-prime/elements/base_element.rb', line 15 def view_class @view_class end |
#view_name ⇒ Object
Returns the value of attribute view_name.
15 16 17 |
# File 'motion-prime/elements/base_element.rb', line 15 def view_name @view_name end |
Class Method Details
.after_render(method_name) ⇒ Object
187 188 189 |
# File 'motion-prime/elements/base_element.rb', line 187 def after_render(method_name) set_callback :render, :after, method_name end |
.before_render(method_name) ⇒ Object
184 185 186 |
# File 'motion-prime/elements/base_element.rb', line 184 def before_render(method_name) set_callback :render, :before, method_name end |
.factory(type, options = {}) ⇒ Object
177 178 179 180 181 182 183 |
# File 'motion-prime/elements/base_element.rb', line 177 def factory(type, = {}) element_class = class_factory("#{type}_element", true) || self view_class_name = camelize_factory("ui_#{type}") .merge!(view_class: view_class_name) element_class.new() end |
Instance Method Details
#add_target(target = nil, action = 'on_click:', event = :touch) ⇒ Object
def dealloc
pp 'Deallocating elemenet', self.name, self.to_s, [:text]
super
end
37 38 39 40 |
# File 'motion-prime/elements/base_element.rb', line 37 def add_target(target = nil, action = 'on_click:', event = :touch) return false unless self.view self.view.addTarget(target || section, action: action, forControlEvents: event.uicontrolevent) end |
#bind_gesture(action, receiver = nil) ⇒ Object
91 92 93 94 95 96 |
# File 'motion-prime/elements/base_element.rb', line 91 def bind_gesture(action, receiver = nil) receiver ||= self single_tap = UITapGestureRecognizer.alloc.initWithTarget(receiver, action: action) view.addGestureRecognizer single_tap view.setUserInteractionEnabled true end |
#compute_options! ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'motion-prime/elements/base_element.rb', line 66 def = || {} = self..except(:screen, :name, :block, :view_class).merge() () = Styles.for(styles).merge() @computed_options = (@computed_options, section, %w[text placeholder font title_label padding padding_left padding_right min_width min_outer_width max_width max_outer_width width left right]) end |
#computed_options ⇒ Object
Lazy-computing options
61 62 63 64 |
# File 'motion-prime/elements/base_element.rb', line 61 def unless @computed_options @computed_options end |
#hide ⇒ Object
83 84 85 |
# File 'motion-prime/elements/base_element.rb', line 83 def hide view.hidden = true end |
#render(options = {}, &block) ⇒ Object
42 43 44 45 46 |
# File 'motion-prime/elements/base_element.rb', line 42 def render( = {}, &block) run_callbacks :render do render!(&block) end end |
#render!(&block) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'motion-prime/elements/base_element.rb', line 48 def render!(&block) view = screen.add_view class_factory(view_class), do |view| @view = view block.try(:call, view, self) end if .has_key?(:delegate) && [:delegate].respond_to?(:delegated_by) [:delegate].delegated_by(view) end view end |
#show ⇒ Object
87 88 89 |
# File 'motion-prime/elements/base_element.rb', line 87 def show view.hidden = false end |
#update_with_options(new_options = {}) ⇒ Object
75 76 77 78 79 80 81 |
# File 'motion-prime/elements/base_element.rb', line 75 def ( = {}) .merge!() view.try(:removeFromSuperview) @view = nil render end |