motion-prime/elements/base_element.rb in motion-prime-0.9.9 vs motion-prime/elements/base_element.rb in motion-prime-0.9.9.1
- old
+ new
@@ -83,11 +83,11 @@
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.try(:elements_eval_object), %w[
- text placeholder font title_label
+ font text placeholder title_label
padding padding_left padding_right padding_top padding_bottom
left right min_width min_outer_width max_width max_outer_width width
top bottom min_height min_outer_height max_height max_outer_height height])
end
@@ -132,10 +132,18 @@
single_tap = UITapGestureRecognizer.alloc.initWithTarget(receiver, action: action)
view.addGestureRecognizer single_tap
view.setUserInteractionEnabled true
end
+ def cell_section?
+ section.respond_to?(:cell_section_name)
+ end
+
+ def cell_element?
+ @view_class == 'UICollectionViewCell' || @view_class == 'UITableViewCell'
+ end
+
protected
def reset_computed_values
@content_height = nil
@content_width = nil
end
@@ -148,14 +156,13 @@
normalize_value(@block, section) 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_section_name)
@styles = []
- if is_cell_section
+ if cell_section?
@styles += compute_cell_style_options(style_sources, has_errors)
end
mixins = []
custom_styles = []
@@ -176,11 +183,11 @@
@styles << [section.name, name].join('_').to_sym
end
# custom style (from options or block options), using for TableViews as well
@styles += custom_styles
- # puts @view_class.to_s + @styles.inspect, ''
+ # pp @view_class.to_s + @styles.inspect; puts()
@styles
end
def compute_cell_style_options(style_sources, has_errors)
base_styles = {common: [], specific: []}
@@ -191,11 +198,11 @@
# 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
- if @view_name != 'base' && @view_name != 'table_view_cell'
+ if @view_name != 'base' && !cell_element?
# form element: _input
# table element: _image
suffixes[:common] << @view_name.to_sym
suffixes[:common] << :"#{@view_name}_with_errors" if has_errors
end
@@ -211,20 +218,20 @@
# table element: base_table_cell_image
common_styles = if suffixes[:common].any?
build_styles_chain(base_styles[:common], suffixes.values.flatten)
elsif suffixes[:specific].any?
build_styles_chain(base_styles[:common], suffixes[:specific])
- elsif @view_name == 'table_view_cell'
+ elsif cell_element?
base_styles[:common]
end
all_styles += Array.wrap(common_styles)
# form cell: user_form_field, user_form_string_field, user_form_field_email
# form element: user_form_field_text_field, user_form_string_field_text_field, user_form_field_email_text_field
# table cell: categories_table_cell, categories_table_title
# table element: categories_table_cell_image, categories_table_title_image
specific_base_common_suffix_styles = if suffixes[:common].any?
build_styles_chain(base_styles[:specific], suffixes[:common])
- elsif suffixes[:specific].empty? && @view_name == 'table_view_cell'
+ elsif suffixes[:specific].empty? && cell_element?
base_styles[:specific]
end
all_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
\ No newline at end of file