motion-prime/elements/base_element.rb in motion-prime-0.4.3 vs motion-prime/elements/base_element.rb in motion-prime-0.4.4

- old
+ new

@@ -19,16 +19,21 @@ def initialize(options = {}) @options = options @screen = options[:screen] @section = options[:section] + @view_class = options[:view_class] || 'UIView' @name = options[:name] @block = options[:block] - @view_class = options[:view_class] || 'UIView' @view_name = self.class_name_without_kvo.demodulize.underscore.gsub(/(_draw)?_element/, '') end + def dealloc + pp 'deallocating elemenet', self.name + super + end + def render(options = {}, &block) run_callbacks :render do render!(&block) end end @@ -44,10 +49,19 @@ def computed_options compute_options! unless @computed_options @computed_options end + def compute_options! + block_options = compute_block_options || {} + raw_options = self.options.except(:screen, :name, :block, :view_class).merge(block_options) + compute_style_options(raw_options) + raw_options = Styles.for(styles).merge(raw_options) + @computed_options = raw_options + normalize_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 + def update_with_options(new_options = {}) options.merge!(new_options) compute_options! view.try(:removeFromSuperview) @view = nil @@ -68,20 +82,11 @@ view.addGestureRecognizer single_tap view.setUserInteractionEnabled true end protected - def compute_options! - block_options = compute_block_options || {} - raw_options = self.options.except(:screen, :name, :block, :view_class).merge(block_options) - compute_style_options(raw_options) - raw_options = Styles.for(styles).merge(raw_options) - @computed_options = raw_options - normalize_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 - # Compute options sent inside block, e.g. # element :button do # {name: model.name} # end def compute_block_options @@ -140,26 +145,26 @@ @styles += Array.wrap(specific_base_common_suffix_styles) # form element: user_form_field_input, user_form_string_field_input, user_form_field_email_input # table element: categories_table_cell_icon, categories_table_title_icon @styles += build_styles_chain(base_styles[:specific], suffixes[:specific]) end - if section + if section && section.name.present? && name.present? # using for base sections - @styles << [section.name, name].compact.join('_').to_sym + @styles << [section.name, name].join('_').to_sym end # custom style (from options or block options), using for TableViews as well custom_styles = style_sources.map do |source| normalize_object(source.delete(:styles), section) end.flatten @styles += custom_styles - #puts @view_class.to_s + @styles.inspect, '' + # puts @view_class.to_s + @styles.inspect, '' end class << self def factory(type, options = {}) element_class = class_factory("#{type}_element", true) || self view_class_name = camelize_factory("ui_#{type}") - + options.merge!(view_class: view_class_name) element_class.new(options) end def before_render(method_name) set_callback :render, :before, method_name \ No newline at end of file