motion-prime/elements/base_element.rb in motion-prime-0.8.1 vs motion-prime/elements/base_element.rb in motion-prime-0.8.2
- old
+ new
@@ -25,13 +25,23 @@
@view_class = options[:view_class] || 'UIView'
@name = options[:name]
@block = options[:block]
@view_name = self.class_name_without_kvo.demodulize.underscore.gsub(/(_draw)?_element/, '')
+
+ if Prime.env.development?
+ @_element_info = "#{@name} #{view_name} #{section.try(:name)} #{screen.class}"
+ @@_allocated_elements ||= []
+ @@_allocated_elements << @_element_info
+ end
end
def dealloc
+ if Prime.env.development?
+ index = @@_allocated_elements.index(@_element_info)
+ @@_allocated_elements.delete_at(index) if index
+ end
Prime.logger.dealloc_message :element, self, self.name
super
end
def add_target(target = nil, action = 'on_click:', event = :touch)
@@ -39,16 +49,16 @@
self.view.addTarget(target || section, action: action, forControlEvents: event.uicontrolevent)
end
def render(options = {}, &block)
run_callbacks :render do
- render!(&block)
+ render!(options, &block)
end
end
- def render!(&block)
- view = screen.add_view class_factory(view_class), computed_options do |view|
+ def render!(options = {}, &block)
+ view = screen.add_view class_factory(view_class), computed_options.merge(options) do |view|
@view = view
block.try(:call, view, self)
end
if computed_options.has_key?(:delegate) && computed_options[:delegate].respond_to?(:delegated_by)
@@ -70,15 +80,18 @@
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 reload!
+ compute_options!
+ end
+
def update_with_options(new_options = {})
options.merge!(new_options)
- compute_options!
+ reload!
view.try(:removeFromSuperview)
- @view = nil
render
end
def hide
view.hidden = true
@@ -105,43 +118,47 @@
section.send(:instance_exec, self, &@block) if @block
end
def compute_style_options(*style_sources)
has_errors = section.respond_to?(:observing_errors?) && observing_errors? && has_errors?
- is_cell_section = section.respond_to?(:cell_name)
+ is_cell_section = section.respond_to?(:cell_section_name)
@styles = []
if is_cell_section
@styles += compute_cell_style_options(style_sources, has_errors)
end
- # styles got from mixins option
- mixin_styles = style_sources.map do |source|
- normalize_object(source.delete(:mixins), section)
- end.flatten.map{ |m| :"_mixin_#{m}" }
- @styles += mixin_styles
+ mixins = []
+ custom_styles = []
+ style_sources.each do |source|
+ if source_mixins = source.delete(:mixins)
+ mixins += Array.wrap(normalize_object(source_mixins, section))
+ end
+ if source_styles = source.delete(:styles)
+ custom_styles += Array.wrap(normalize_object(source_styles, section))
+ end
+ end
+ # styles got from mixins option
+ @styles += mixins.map{ |m| :"_mixin_#{m}" }
# don't use present? here, it's slower, while this method should be very fast
if section && section.name && section.name != '' && name && name != ''
# using for base sections
@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
+ # custom style (from options or block options), using for TableViews as well
@styles += custom_styles
# puts @view_class.to_s + @styles.inspect, ''
@styles
end
def compute_cell_style_options(style_sources, has_errors)
base_styles = {common: [], specific: []}
suffixes = {common: [], specific: []}
all_styles = []
- # following example in Prime::TableSection#cell_styles
+ # following example in Prime::TableSection#cell_section_styles
# form element/cell: <base|user>_form_field, <base|user>_form_string_field, user_form_field_email
# table element/cell: <base|categories>_table_cell, categories_table_title
if section.section_styles
section.section_styles.each { |type, values| base_styles[type] += values }
end
\ No newline at end of file