motion-prime/views/view_styler.rb in motion-prime-1.0.3 vs motion-prime/views/view_styler.rb in motion-prime-1.0.4

- old
+ new

@@ -2,14 +2,15 @@ class ViewStyler include FrameCalculatorMixin include HasStyles include HasClassFactory include ElementTextMixin + include HasStyleOptions ORDER = %w[ frame - font placeholder_font text title_label title + font text title_label title minimum_value maximum_value value ] attr_reader :view, :options @@ -55,17 +56,16 @@ options[:number_of_lines] ||= 0 if view.is_a?(UILabel) end if options.slice(:html, :line_spacing, :line_height, :underline, :fragment_color).any? text_options = extract_attributed_text_options(options) - html = text_options.delete(:html) text_options[:text] = html if html options[:attributed_text] = html ? html_string(text_options) : attributed_string(text_options) # ios 7 bug fix when text is invisible - if text_options.slice(:line_height, :line_spacing, :text_alignment, :line_break_mode).any? && options.fetch(:number_of_lines, 1) == 1 + if view.is_a?(UILabel) && text_options.slice(:line_height, :line_spacing, :text_alignment, :line_break_mode).any? && options.fetch(:number_of_lines, 1) == 1 options[:number_of_lines] = 0 end end # Fix issue overriding background color if options[:background_image].present? @@ -77,36 +77,33 @@ @options = Hash[options.sort_by {|k,v| ORDER.index(k.to_s) || ORDER.count }] end def extract_font_options(options, prefix = nil) key = [prefix, 'font'].compact.join('_').to_sym - name_key = [prefix, 'font_name'].compact.join('_').to_sym - size_key = [prefix, 'font_size'].compact.join('_').to_sym - if options.slice(size_key, name_key).any? - font_name = options.delete(name_key) || :system - font_size = options.delete(size_key) || 14 - options[key] ||= font_name.uifont(font_size) - end + options[key] = extract_font_from(options, prefix) end def extract_attributed_text_options(options) text_attributes = [ :text, :html, :line_spacing, :line_height, :underline, :fragment_color, - :text_alignment, :font, :line_break_mode, :number_of_lines + :text_alignment, :font, :font_name, :font_size, :line_break_mode, :number_of_lines, :text_color ] attributed_text_options = options.slice(*text_attributes) + exclude_attributes = text_attributes if view.is_a?(UIButton) + attributed_text_options[:text_color] ||= options[:title_color] attributed_text_options[:text] ||= options[:title] + exclude_attributes.delete(:line_break_mode) end - options.except!(*text_attributes) + options.except!(*exclude_attributes) attributed_text_options end def set_option(key, value) # return if value.nil? # ignore options - return if ignore_option?(key) + return if ignore_option?(key) || value.nil? # apply options result ||= set_color_options(key, value) result ||= set_image_options(key, value) result ||= set_text_options(key, value) @@ -218,18 +215,21 @@ corner_consts = {top_left: UIRectCornerTopLeft, bottom_left: UIRectCornerBottomLeft, bottom_right: UIRectCornerBottomRight, top_right: UIRectCornerTopRight} corners = value[:corners].inject(0) { |result, corner| result|corner_consts[corner] } mask_path = UIBezierPath.bezierPathWithRoundedRect(layer_bounds, byRoundingCorners: corners, cornerRadii: CGSizeMake(radius, radius)) mask_layer = CAShapeLayer.layer - mask_layer.frame = layer_bounds mask_layer.path = mask_path.CGPath view.mask = mask_layer if value[:border_color] && value[:border_width] stroke_layer = CAShapeLayer.layer - stroke_layer.path = mask_path.CGPath + unless value[:sides] + stroke_layer.path = mask_path.CGPath + else # suuport sides + stroke_layer.path = mask_path.CGPath + end stroke_layer.fillColor = :clear.uicolor.cgcolor stroke_layer.strokeColor = value[:border_color].uicolor.cgcolor stroke_layer.lineWidth = value[:border_width].to_f*2 # another half is hidden by the mask stroke_layer.lineDashPattern = value[:dashes] if value[:dashes].present? @@ -275,9 +275,10 @@ %w[ styles has_drawn_content value_type height_to_fit container parent_frame width height top right bottom left max_width max_outer_width min_width min_outer_width max_height max_outer_height min_height min_outer_width + font_name font_size placeholder_font_name placeholder_font_size placeholder_font bounds ].include?(key.to_s) end def bounds