motion-prime 0.3.3 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. checksums.yaml +8 -8
  2. data/CHANGELOG.md +4 -0
  3. data/Gemfile.lock +1 -1
  4. data/ROADMAP.md +3 -3
  5. data/doc/code/getting_started.rb +6 -5
  6. data/files/app/screens/sidebar_screen.rb +2 -2
  7. data/files/app/sections/sidebar/action.rb +1 -1
  8. data/motion-prime/api_client.rb +1 -1
  9. data/motion-prime/core_ext/kernel.rb +4 -0
  10. data/motion-prime/elements/_content_padding_mixin.rb +12 -4
  11. data/motion-prime/elements/_content_text_mixin.rb +10 -2
  12. data/motion-prime/elements/{base.rb → base_element.rb} +16 -7
  13. data/motion-prime/elements/button.rb +1 -1
  14. data/motion-prime/elements/draw/_draw_background_mixin.rb +20 -9
  15. data/motion-prime/elements/draw/image.rb +2 -2
  16. data/motion-prime/elements/draw/label.rb +7 -6
  17. data/motion-prime/elements/draw.rb +8 -3
  18. data/motion-prime/elements/label.rb +2 -2
  19. data/motion-prime/elements/table_view_cell.rb +7 -0
  20. data/motion-prime/helpers/has_search_bar.rb +1 -1
  21. data/motion-prime/helpers/has_styles.rb +7 -7
  22. data/motion-prime/models/model.rb +1 -1
  23. data/motion-prime/models/sync.rb +10 -10
  24. data/motion-prime/screens/_navigation_mixin.rb +1 -1
  25. data/motion-prime/sections/_draw_mixin.rb +74 -0
  26. data/motion-prime/sections/{base.rb → base_section.rb} +104 -55
  27. data/motion-prime/sections/form/base_field_section.rb +6 -6
  28. data/motion-prime/sections/form/base_header_section.rb +2 -3
  29. data/motion-prime/sections/form.rb +38 -17
  30. data/motion-prime/sections/tabbed.rb +3 -3
  31. data/motion-prime/sections/table.rb +172 -80
  32. data/motion-prime/services/table_data_indexes.rb +51 -0
  33. data/motion-prime/styles/_mixins.rb +8 -0
  34. data/motion-prime/support/dm_cell_with_section.rb +1 -1
  35. data/motion-prime/support/dm_text_field.rb +17 -12
  36. data/motion-prime/support/dm_text_view.rb +10 -23
  37. data/motion-prime/version.rb +1 -1
  38. data/motion-prime/views/layout.rb +4 -2
  39. data/motion-prime/views/styles.rb +2 -0
  40. data/motion-prime/views/view_builder.rb +8 -2
  41. data/motion-prime/views/view_styler.rb +6 -2
  42. metadata +8 -9
  43. data/motion-prime/helpers/cell_section.rb +0 -9
  44. data/motion-prime/sections/draw.rb +0 -93
  45. data/motion-prime/sections/form/text_with_button_field_section.rb +0 -23
  46. data/motion-prime/sections/table/base_cell_section.rb +0 -5
  47. data/motion-prime/sections/table/draw_cell_section.rb +0 -5
@@ -1,93 +0,0 @@
1
- module MotionPrime
2
- class DrawSection < BaseSection
3
- # MotionPrime::DrawSection is container for Elements.
4
- # Unlike BaseSection, DrawSection renders elements using drawRect, instead of creating subviews
5
- # NOTE: only image and label elements are supported at this moment
6
-
7
- # == Basic Sample
8
- # class MySection < MotionPrime::DrawSection
9
- # element :title, text: "Hello World"
10
- # element :avatar, type: :image, image: 'defaults/avatar.jpg'
11
- # end
12
- #
13
- include HasStyles
14
-
15
- attr_accessor :container_view
16
-
17
- def create_elements
18
- self.elements = {}
19
- (self.class.elements_options || {}).each do |key, opts|
20
- # we should clone options to prevent overriding options
21
- # in next element with same name in another class
22
- options = opts.clone
23
- options[:section] = self
24
- self.elements[key] = MotionPrime::DrawElement.factory(options.delete(:type), options)
25
- end
26
- end
27
-
28
- def render!
29
- options = view_style_options
30
- options.merge!(section: WeakRef.new(self), background_color: :clear)
31
-
32
- if container_options[:as].to_s == 'cell'
33
- @container_view = screen.add_view DMCellWithSection, options.merge({
34
- reuse_identifier: container_options[:reuse_identifier],
35
- parent_view: (table if respond_to?(:table))
36
- })
37
- else
38
- @container_view = screen.add_view DMViewWithSection, options.merge({
39
- width: container_options[:width] || 320, # TODO: remove these options (use styles)
40
- height: container_options[:height] || 100,
41
- top: container_options[:top] || 0,
42
- left: container_options[:left] || 0
43
- })
44
- end
45
- end
46
-
47
- def hide
48
- container_view.hidden = true
49
- end
50
-
51
- def show
52
- container_view.hidden = false
53
- end
54
-
55
- # @container_view (DMViewWithSection) will call this method on draw
56
- def draw_in(rect)
57
- draw_background(rect)
58
- draw_elements(rect)
59
- end
60
-
61
- def draw_elements(rect)
62
- elements.each do |key, element|
63
- element.draw_in(rect)
64
- end
65
- end
66
-
67
- def view_style_options
68
- @view_style_options ||= begin
69
- options = Styles.for(container_options[:styles])
70
- normalize_options(options)
71
- options
72
- end
73
- end
74
-
75
- def draw_background(rect)
76
- if gradient_options = view_style_options[:gradient]
77
- start_point = CGPointMake(CGRectGetMidX(rect), CGRectGetMinY(rect))
78
- end_point = CGPointMake(CGRectGetMidX(rect), CGRectGetMaxY(rect))
79
-
80
- context = UIGraphicsGetCurrentContext()
81
- # CGContextSaveGState(context)
82
- CGContextAddRect(context, rect)
83
- CGContextClip(context)
84
- gradient = prepare_gradient(gradient_options)
85
- CGContextDrawLinearGradient(context, gradient, start_point, end_point, 0)
86
- # CGContextRestoreGState(context)
87
- elsif background_color = (container_options[:background_color] || view_style_options[:background_color])
88
- background_color.uicolor.setFill
89
- UIRectFill(rect)
90
- end
91
- end
92
- end
93
- end
@@ -1,23 +0,0 @@
1
- module MotionPrime
2
- class TextWithButtonFieldSection < BaseFieldSection
3
- element :label, type: :label do
4
- options[:label] || {}
5
- end
6
- element :input, type: :text_view do
7
- {editable: true}.merge(options[:input] || {})
8
- end
9
- element :button, type: :button do
10
- (options[:button] || {}).except(:action)
11
- end
12
- element :error_message, type: :error_message, text: proc { observing_errors? and all_errors.join("\n") }
13
-
14
- after_render :bind_text_input
15
- after_render :bind_button_action
16
-
17
- def bind_button_action
18
- view(:button).on :touch do
19
- form.send(options[:button][:action])
20
- end if options[:button].try(:[], :action)
21
- end
22
- end
23
- end
@@ -1,5 +0,0 @@
1
- module MotionPrime
2
- class BaseCellSection < BaseSection
3
- include CellSectionMixin
4
- end
5
- end
@@ -1,5 +0,0 @@
1
- module MotionPrime
2
- class DrawCellSection < DrawSection
3
- include CellSectionMixin
4
- end
5
- end