motion-prime 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +8 -8
  2. data/CHANGELOG.md +6 -0
  3. data/Gemfile +1 -1
  4. data/Gemfile.lock +6 -9
  5. data/files/Gemfile +2 -2
  6. data/files/Rakefile +1 -1
  7. data/motion-prime.gemspec +0 -1
  8. data/motion-prime/elements/_content_padding_mixin.rb +1 -1
  9. data/motion-prime/elements/_content_text_mixin.rb +1 -1
  10. data/motion-prime/elements/base_element.rb +19 -16
  11. data/motion-prime/elements/button.rb +1 -1
  12. data/motion-prime/elements/draw.rb +12 -3
  13. data/motion-prime/elements/draw/_draw_background_mixin.rb +2 -4
  14. data/motion-prime/elements/draw/image.rb +5 -12
  15. data/motion-prime/elements/draw/label.rb +1 -1
  16. data/motion-prime/elements/table_view_cell.rb +1 -1
  17. data/motion-prime/elements/text_field.rb +1 -1
  18. data/motion-prime/elements/text_view.rb +1 -1
  19. data/motion-prime/helpers/has_class_factory.rb +33 -0
  20. data/motion-prime/helpers/has_style_chain_builder.rb +10 -1
  21. data/motion-prime/models/sync.rb +2 -2
  22. data/motion-prime/mp.rb +11 -0
  23. data/motion-prime/screens/_base_mixin.rb +1 -3
  24. data/motion-prime/screens/_navigation_mixin.rb +1 -1
  25. data/motion-prime/screens/base_screen.rb +8 -5
  26. data/motion-prime/screens/sidebar_container_screen.rb +2 -1
  27. data/motion-prime/sections/_cell_section_mixin.rb +11 -0
  28. data/motion-prime/sections/base_section.rb +3 -1
  29. data/motion-prime/sections/form.rb +2 -10
  30. data/motion-prime/sections/tabbed.rb +2 -2
  31. data/motion-prime/sections/table.rb +35 -22
  32. data/motion-prime/styles/_mixins.rb +6 -1
  33. data/motion-prime/styles/form.rb +1 -1
  34. data/motion-prime/support/{dm_button.rb → mp_button.rb} +1 -1
  35. data/motion-prime/support/{dm_cell_with_section.rb → mp_cell_with_section.rb} +1 -1
  36. data/motion-prime/support/{ui_search_bar_custom.rb → mp_search_bar_custom.rb} +1 -1
  37. data/motion-prime/support/{dm_text_field.rb → mp_text_field.rb} +2 -2
  38. data/motion-prime/support/{dm_text_view.rb → mp_text_view.rb} +1 -1
  39. data/motion-prime/support/{dm_view_controller.rb → mp_view_controller.rb} +1 -1
  40. data/motion-prime/support/{dm_view_with_section.rb → mp_view_with_section.rb} +1 -1
  41. data/motion-prime/support/tab_bar_controller.rb +0 -1
  42. data/motion-prime/version.rb +1 -1
  43. data/motion-prime/views/layout.rb +2 -2
  44. data/motion-prime/views/view_builder.rb +2 -1
  45. data/motion-prime/views/view_styler.rb +12 -9
  46. data/spec/screens/base_screen_spec.rb +2 -1
  47. metadata +10 -24
  48. data/motion-prime/support/navigation_controller.rb +0 -4
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MGY2Yjg2ZDEwNTBlN2FjNjNhNDM1YWRjMWZkMGNiMzYyOGMxYWYzZA==
4
+ ZWVmZmZjNDVhMTMxZGE4ZjMzMWQyMzM0OWU4NDMzZGUzMjdmZTNjMQ==
5
5
  data.tar.gz: !binary |-
6
- MmE0Nzg5ZjA2MmQ0OTVjYjQ3MjRmNGZjZmIzMDg3NDAyNWIxNmI1ZQ==
6
+ ZDBkMTNhODQzYjQyZGMwOTI1ZTEwYWM2NzUyNTFjZDJhYTBiODUyZg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZjM2NjNjMjBmNDcyN2ZkMGRmNzFlZDI4M2E0NWY0MmFiYjU1ZTJlMTk3NDM5
10
- MDZiMzQ0NDdjYmRkYmNjZDg3MDVjYjViYTNkMGM3MzMxZThlZmEwYjJjZGVl
11
- ZjQ1Y2I5YmNjYzNkZmU2ZDY1NTFiM2VmYWQ5ZWEyNzJkYzYwZDY=
9
+ NDJkY2JmMzAzMWFmY2QyODM0Yzg1ODllMjRmNDY2MWIzMTk5MDRlMDI5NWQ1
10
+ NTIwZmJmYWE5Y2U2NzZjNWM3NGUwMTVkNDM0YzAyYzNiZjNlMDVkYmUwZGEw
11
+ NTkxNWJlY2U5ODM4NTIyNWNhN2I2M2UzZTRiYmYyMDllYWM0NDc=
12
12
  data.tar.gz: !binary |-
13
- OWRmMjk4OTliN2U1OGZiMWNjOTc5NjFjNGMzYjkxZjYyMDM2MWI4MmY5YmI3
14
- NTU1MmZiMjAyYTlhY2Y3MzM1NzViMjI4YzA0YjY0OWFmZWVhNjVhMWJmMmRi
15
- NjVmM2Q1NTY3OTllNjFiODMzZTY1MzVhZGI4ZmYyYmM2NWMzNjk=
13
+ NTU5YzUwZmUwYWVhYWNiYzc0YWIzOGU4NzMxMDE4NGJkMjUyN2QxZjBkMGY3
14
+ ZWJjMmMwN2E4YmZkMGM0YWZkZWI0NTBlYzIzYmEyM2NmNjVmNTJiNWUyZjZh
15
+ M2Y0Yjk2MjYzNGI1NDkwZjU0NjNlYTMyNzUyMjY1YzQ4OTZkOTc=
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ === 0.4.3
2
+ * Speed improvements
3
+ * Rename dm_ views to mp_
4
+ * Upgrade sugarcube
5
+ * Render screen on appear instead of on load
6
+
1
7
  === 0.4.2
2
8
  * Bug fixes
3
9
  * Added web view element support
data/Gemfile CHANGED
@@ -2,6 +2,6 @@ source 'http://rubygems.org'
2
2
 
3
3
  gem 'motion-cocoapods', '~> 1.4.0'
4
4
  gem 'motion-support', '~> 0.2.4'
5
- gem 'sugarcube', '~> 0.20.23'
5
+ gem 'sugarcube', '~> 1.3.7', require: 'sugarcube-classic'
6
6
  gem 'bubble-wrap', '~> 1.3.0'
7
7
  gemspec
data/Gemfile.lock CHANGED
@@ -1,20 +1,19 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- motion-prime (0.4.2)
4
+ motion-prime (0.4.3)
5
5
  bubble-wrap
6
6
  cocoapods
7
7
  methadone
8
8
  motion-cocoapods
9
9
  motion-require
10
10
  motion-support
11
- nano-store
12
11
  sugarcube
13
12
 
14
13
  GEM
15
14
  remote: http://rubygems.org/
16
15
  specs:
17
- activesupport (3.2.15)
16
+ activesupport (3.2.16)
18
17
  i18n (~> 0.6, >= 0.6.4)
19
18
  multi_json (~> 1.0)
20
19
  bubble-wrap (1.3.0)
@@ -38,7 +37,7 @@ GEM
38
37
  colored (1.2)
39
38
  escape (0.0.4)
40
39
  fuzzy_match (2.0.4)
41
- i18n (0.6.5)
40
+ i18n (0.6.9)
42
41
  json (1.8.1)
43
42
  json_pure (1.8.1)
44
43
  methadone (1.3.1)
@@ -51,12 +50,10 @@ GEM
51
50
  motion-support (0.2.5)
52
51
  motion-require (>= 0.0.6)
53
52
  multi_json (1.8.2)
54
- nano-store (0.6.3)
55
- motion-cocoapods (>= 1.2.1)
56
- nap (0.5.1)
53
+ nap (0.6.0)
57
54
  open4 (1.3.0)
58
55
  rake (10.1.0)
59
- sugarcube (0.20.25)
56
+ sugarcube (1.3.7)
60
57
  xcodeproj (0.14.1)
61
58
  activesupport (~> 3.0)
62
59
  colored (~> 1.2)
@@ -73,4 +70,4 @@ DEPENDENCIES
73
70
  motion-stump
74
71
  motion-support (~> 0.2.4)
75
72
  rake
76
- sugarcube (~> 0.20.23)
73
+ sugarcube (~> 1.3.7)
data/files/Gemfile CHANGED
@@ -2,7 +2,7 @@ source 'http://rubygems.org'
2
2
 
3
3
  gem 'motion-cocoapods', '~> 1.4.0'
4
4
  gem 'motion-support', '~> 0.2.4'
5
- gem 'sugarcube', '~> 0.20.23'
5
+ gem 'sugarcube', '~> 1.3.7', require: 'sugarcube-classic'
6
6
  gem 'bubble-wrap', '~> 1.3.0'
7
7
 
8
- gem 'motion-prime', '~> 0.3.1'
8
+ gem 'motion-prime', '~> 0.4.2'
data/files/Rakefile CHANGED
@@ -5,7 +5,7 @@ require "rubygems"
5
5
  require 'motion-cocoapods'
6
6
  require 'bundler'
7
7
  Bundler.require
8
- require 'sugarcube-568'
8
+ require 'sugarcube-common'
9
9
  require 'motion-prime'
10
10
 
11
11
  Motion::Project::App.setup do |app|
data/motion-prime.gemspec CHANGED
@@ -26,6 +26,5 @@ Gem::Specification.new do |spec|
26
26
  spec.add_dependency "motion-support"
27
27
  spec.add_dependency 'bubble-wrap'
28
28
  spec.add_dependency 'sugarcube'
29
- spec.add_dependency 'nano-store'
30
29
  spec.add_dependency("methadone")
31
30
  end
@@ -51,7 +51,7 @@ module MotionPrime
51
51
  end
52
52
 
53
53
  def default_padding_for(side)
54
- view_class.constantize.send(:"default_padding_#{side}")
54
+ class_factory(view_class).send(:"default_padding_#{side}")
55
55
  end
56
56
  end
57
57
  end
@@ -1,7 +1,7 @@
1
1
  module MotionPrime
2
2
  module ElementContentTextMixin
3
3
  def content_text
4
- (is_a?(ButtonElement) ? button_content_text : input_content_text).to_s
4
+ is_a?(ButtonElement) ? button_content_text : input_content_text
5
5
  end
6
6
 
7
7
  def content_font
@@ -1,5 +1,6 @@
1
1
  motion_require '../helpers/has_normalizer'
2
2
  motion_require '../helpers/has_style_chain_builder'
3
+ motion_require '../helpers/has_class_factory'
3
4
  module MotionPrime
4
5
  class BaseElement
5
6
  # MotionPrime::BaseElement is container for UIView class elements with options.
@@ -8,6 +9,8 @@ module MotionPrime
8
9
  include ::MotionSupport::Callbacks
9
10
  include HasNormalizer
10
11
  include HasStyleChainBuilder
12
+ include HasClassFactory
13
+ extend HasClassFactory
11
14
 
12
15
  attr_accessor :options, :section, :name,
13
16
  :view_class, :view, :view_name, :styles, :screen
@@ -20,7 +23,7 @@ module MotionPrime
20
23
  @section = options[:section]
21
24
  @name = options[:name]
22
25
  @block = options[:block]
23
- @view_class = options[:view_class] || "UIView"
26
+ @view_class = options[:view_class] || 'UIView'
24
27
  @view_name = self.class_name_without_kvo.demodulize.underscore.gsub(/(_draw)?_element/, '')
25
28
  end
26
29
 
@@ -31,7 +34,7 @@ module MotionPrime
31
34
  end
32
35
 
33
36
  def render!(&block)
34
- screen.add_view view_class.constantize, computed_options do |view|
37
+ screen.add_view class_factory(view_class), computed_options do |view|
35
38
  @view = view
36
39
  block.try(:call, view, self)
37
40
  end
@@ -97,14 +100,16 @@ module MotionPrime
97
100
  # following example in Prime::TableSection#cell_styles
98
101
  # form element/cell: <base|user>_form_field, <base|user>_form_string_field, user_form_field_email
99
102
  # table element/cell: <base|categories>_table_cell, categories_table_title
100
- section.section_styles.each { |type, values| base_styles[type] += values } if section.section_styles
101
- if %w[base table_view_cell].exclude?(@view_name.to_s)
103
+ if section.section_styles
104
+ section.section_styles.each { |type, values| base_styles[type] += values }
105
+ end
106
+ if %w[base table_view_cell].exclude?(@view_name)
102
107
  # form element: _input
103
108
  # table element: _image
104
109
  suffixes[:common] << @view_name.to_sym
105
110
  suffixes[:common] << :"#{@view_name}_with_errors" if has_errors
106
111
  end
107
- if name && name.to_s != @view_name.to_s
112
+ if name && name.to_s != @view_name
108
113
  # form element: _input
109
114
  # table element: _icon
110
115
  suffixes[:specific] << name.to_sym
@@ -118,7 +123,7 @@ module MotionPrime
118
123
  build_styles_chain(base_styles[:common], suffixes[:common])
119
124
  elsif suffixes[:specific].any?
120
125
  build_styles_chain(base_styles[:common], suffixes[:specific])
121
- elsif @view_name.to_s == 'table_view_cell'
126
+ elsif @view_name == 'table_view_cell'
122
127
  base_styles[:common]
123
128
  end
124
129
  @styles += Array.wrap(common_styles)
@@ -129,7 +134,7 @@ module MotionPrime
129
134
  # table element: categories_table_cell_image, categories_table_title_image
130
135
  specific_base_common_suffix_styles = if suffixes[:common].any?
131
136
  build_styles_chain(base_styles[:specific], suffixes[:common])
132
- elsif suffixes[:specific].empty? && @view_name.to_s == 'table_view_cell'
137
+ elsif suffixes[:specific].empty? && @view_name == 'table_view_cell'
133
138
  base_styles[:specific]
134
139
  end
135
140
  @styles += Array.wrap(specific_base_common_suffix_styles)
@@ -144,20 +149,18 @@ module MotionPrime
144
149
  # custom style (from options or block options), using for TableViews as well
145
150
  custom_styles = style_sources.map do |source|
146
151
  normalize_object(source.delete(:styles), section)
147
- end.compact.flatten
152
+ end.flatten
148
153
  @styles += custom_styles
149
- # puts @view_class.to_s + @styles.inspect, ''
154
+ #puts @view_class.to_s + @styles.inspect, ''
150
155
  end
151
156
 
152
157
  class << self
153
158
  def factory(type, options = {})
154
- class_name = "#{type.classify}Element"
155
- options.merge!({view_class: "UI#{type.classify}"})
156
- if MotionPrime.const_defined?(class_name)
157
- "MotionPrime::#{class_name}".constantize.new(options)
158
- else
159
- self.new(options)
160
- end
159
+ element_class = class_factory("#{type}_element", true) || self
160
+ view_class_name = camelize_factory("ui_#{type}")
161
+
162
+ options.merge!(view_class: view_class_name)
163
+ element_class.new(options)
161
164
  end
162
165
  def before_render(method_name)
163
166
  set_callback :render, :before, method_name
@@ -14,7 +14,7 @@ module MotionPrime
14
14
  end
15
15
 
16
16
  def view_class
17
- "DMButton"
17
+ "MPButton"
18
18
  end
19
19
 
20
20
  def text_value
@@ -51,6 +51,16 @@ module MotionPrime
51
51
  section.bind_gesture_on_container_for(self, action, receiver)
52
52
  end
53
53
 
54
+ def hide
55
+ computed_options[:hidden] = true
56
+ view.setNeedsDisplay
57
+ end
58
+
59
+ def show
60
+ computed_options[:hidden] = false
61
+ view.setNeedsDisplay
62
+ end
63
+
54
64
  private
55
65
  def reset_computed_values
56
66
  @computed_frame = nil
@@ -58,9 +68,8 @@ module MotionPrime
58
68
 
59
69
  class << self
60
70
  def factory(type, options = {})
61
- return unless %w[View Label Image].include?(type.classify)
62
- class_name = "#{type.classify}DrawElement"
63
- "MotionPrime::#{class_name}".constantize.new(options)
71
+ return unless %w[view label image].include?(type.to_s.downcase)
72
+ class_factory("#{type}_draw_element", true).new(options)
64
73
  end
65
74
  end
66
75
  end
@@ -1,16 +1,14 @@
1
1
  module MotionPrime
2
2
  module DrawBackgroundMixin
3
3
  def draw_background_in(draw_rect, options)
4
-
5
4
  bg_color = options[:background_color]
6
5
  border_radius = options[:layer].try(:[], :corner_radius)
7
6
  border_width = options[:layer].try(:[], :border_width).to_f
8
7
  border_color = options[:layer].try(:[], :border_color) || bg_color || :black
9
8
 
10
-
11
- inset = border_width > 0 ? (border_width - 1 )*0.5 : 0
12
- rect = CGRectInset(draw_rect, -inset, -inset)
13
9
  if bg_color || border_width > 0
10
+ inset = border_width > 0 ? (border_width - 1 )*0.5 : 0
11
+ rect = CGRectInset(draw_rect, -inset, -inset)
14
12
  if border_radius
15
13
  bezierPath = UIBezierPath.bezierPathWithRoundedRect rect, cornerRadius: border_radius
16
14
  if border_width > 0
@@ -52,26 +52,19 @@ module MotionPrime
52
52
  end
53
53
 
54
54
  def draw_with_layer(image, rect)
55
+ layer = CALayer.layer
56
+ layer.contents = image.CGImage
57
+ layer.frame = rect
58
+ layer.bounds = rect
55
59
  if computed_options[:layer]
56
- layer = CALayer.layer
57
- layer.frame = CGRectMake(0, 0, image.size.width, image.size.height)
58
- layer.contents = image.CGImage
59
-
60
60
  layer.masksToBounds = computed_options[:layer][:masks_to_bounds] || computed_options[:clips_to_bounds]
61
61
  if radius = computed_options[:layer][:corner_radius]
62
62
  k = image.size.width / rect.size.width
63
63
  radius = radius * k
64
64
  layer.cornerRadius = radius
65
65
  end
66
-
67
- UIGraphicsBeginImageContext(image.size)
68
- layer.renderInContext(UIGraphicsGetCurrentContext())
69
- image = UIGraphicsGetImageFromCurrentImageContext()
70
- UIGraphicsEndImageContext()
71
- image.drawInRect(rect)
72
- else
73
- image.drawInRect(rect)
74
66
  end
67
+ view.layer.addSublayer layer
75
68
  end
76
69
  end
77
70
  end
@@ -23,7 +23,7 @@ module MotionPrime
23
23
  color = (options[:text_color] || :black).uicolor
24
24
  font = (options[:font] || :system).uifont
25
25
  alignment = (options.has_key?(:text_alignment) ? options[:text_alignment] : :left).uitextalignment
26
- line_break_mode = (options.has_key?(:line_break_mode) ? options[:line_break_mode] : :tailtruncation).uilinebreakmode
26
+ line_break_mode = (options.has_key?(:line_break_mode) ? options[:line_break_mode] : :tail_truncation).uilinebreakmode
27
27
  label_text = options[:text].to_s.gsub(/^[\n\r]+/, '')
28
28
 
29
29
  top_left_corner = CGPointMake(computed_inner_left, computed_inner_top)
@@ -1,7 +1,7 @@
1
1
  module MotionPrime
2
2
  class TableViewCellElement < BaseElement
3
3
  def view_class
4
- "DMCellWithSection"
4
+ "MPCellWithSection"
5
5
  end
6
6
  end
7
7
  end
@@ -4,7 +4,7 @@ module MotionPrime
4
4
  include MotionPrime::ElementContentTextMixin
5
5
 
6
6
  def view_class
7
- "DMTextField"
7
+ "MPTextField"
8
8
  end
9
9
  end
10
10
  end
@@ -4,7 +4,7 @@ module MotionPrime
4
4
  include MotionPrime::ElementContentTextMixin
5
5
 
6
6
  def view_class
7
- "DMTextView"
7
+ "MPTextView"
8
8
  end
9
9
  end
10
10
  end
@@ -0,0 +1,33 @@
1
+ # These things required because camelize/constantize/classify methods are very slow
2
+ module MotionPrime
3
+ module HasClassFactory
4
+ def class_factory(name, is_mp_class = false)
5
+ if is_mp_class
6
+ value = Prime.class_factory_cache["motion_prime/#{name}"]
7
+ return value if value
8
+ class_name = camelize_factory(name)
9
+
10
+ return nil unless MotionPrime.const_defined?(class_name)
11
+ class_name = "MotionPrime::#{class_name}"
12
+ name = "motion_prime/#{name}"
13
+ else
14
+ value = Prime.class_factory_cache[name]
15
+ return value if value
16
+ class_name = camelize_factory(name)
17
+ end
18
+ Prime.class_factory_cache[name] = class_name.constantize
19
+ end
20
+
21
+ def camelize_factory(name)
22
+ value = Prime.camelize_factory_cache[name]
23
+ return value if value
24
+ Prime.camelize_factory_cache[name] = name.camelize
25
+ end
26
+
27
+ def low_camelize_factory(name)
28
+ value = Prime.low_camelize_factory_cache[name]
29
+ return value if value
30
+ Prime.low_camelize_factory_cache[name] = name.camelize(:lower)
31
+ end
32
+ end
33
+ end
@@ -1,7 +1,16 @@
1
1
  module MotionPrime
2
2
  module HasStyleChainBuilder
3
3
  def build_styles_chain(base_styles, suffixes)
4
- [*base_styles].compact.map(&:to_s).uniq.map { |base_style| [*suffixes].compact.map(&:to_s).uniq.map { |suffix| [base_style, suffix].join('_').to_sym } }.flatten
4
+ styles = []
5
+ [*base_styles].each do |base_style|
6
+ [*suffixes].each do |suffix|
7
+ components = []
8
+ components << base_style.to_s if base_style.present?
9
+ components << suffix.to_s if suffix.present?
10
+ styles << components.join('_').to_sym if components.present?
11
+ end
12
+ end
13
+ styles
5
14
  end
6
15
  end
7
16
  end
@@ -161,7 +161,7 @@ module MotionPrime
161
161
  data.each do |attributes|
162
162
  model = old_collection.detect{ |model| model.id == attributes[:id]}
163
163
  unless model
164
- model = key.singularize.to_s.classify.constantize.new
164
+ model = key.classify.constantize.new
165
165
  self.send(:"#{key}_bag") << model
166
166
  end
167
167
  model.fetch_with_attributes(attributes)
@@ -191,7 +191,7 @@ module MotionPrime
191
191
  if data.present?
192
192
  model = self.send(key)
193
193
  unless model
194
- model = key.singularize.to_s.classify.constantize.new
194
+ model = key.classify.constantize.new
195
195
  self.send(:"#{key}_bag") << model
196
196
  end
197
197
  model.fetch_with_attributes(data)
data/motion-prime/mp.rb CHANGED
@@ -1,4 +1,15 @@
1
1
  module MotionPrime
2
+ def self.class_factory_cache
3
+ @class_factory_cache ||= {}
4
+ end
5
+
6
+ def self.camelize_factory_cache
7
+ @camelize_factory_cache ||= {}
8
+ end
9
+
10
+ def self.low_camelize_factory_cache
11
+ @camelize_factory_cache ||= {}
12
+ end
2
13
  end
3
14
  ::MP = MotionPrime unless defined?(::MP)
4
15
  ::Prime = MotionPrime unless defined?(::Prime)
@@ -35,7 +35,7 @@ module MotionPrime
35
35
  end
36
36
  end
37
37
 
38
- # Setup the screen, will be called when you run DMViewController.new
38
+ # Setup the screen, will be called when you run MPViewController.new
39
39
  # @param options [hash] Options passed to setup
40
40
  # @return [MotionPrime::BaseScreen] Ready to use screen
41
41
  def on_create(options = {})
@@ -48,8 +48,6 @@ module MotionPrime
48
48
  options.each do |k, v|
49
49
  self.send("#{k}=", v) if self.respond_to?("#{k}=")
50
50
  end
51
-
52
- self.on_init if respond_to?(:on_init)
53
51
  self
54
52
  end
55
53
 
@@ -107,7 +107,7 @@ module MotionPrime
107
107
  end
108
108
 
109
109
  def wrap_in_navigation!
110
- self.navigation_controller = NavigationController.alloc.initWithRootViewController(self)
110
+ self.navigation_controller = UINavigationController.alloc.initWithRootViewController(self)
111
111
  end
112
112
  end
113
113
  end
@@ -1,4 +1,4 @@
1
- motion_require '../support/dm_view_controller.rb'
1
+ motion_require '../support/mp_view_controller.rb'
2
2
  motion_require '../views/layout.rb'
3
3
  motion_require '../screens/_base_mixin.rb'
4
4
  motion_require './extensions/_indicators_mixin'
@@ -6,7 +6,7 @@ motion_require './extensions/_navigation_bar_mixin'
6
6
  motion_require '../helpers/has_authorization'
7
7
  motion_require '../helpers/has_search_bar'
8
8
  module MotionPrime
9
- class BaseScreen < DMViewController
9
+ class BaseScreen < MPViewController
10
10
  include Layout
11
11
  include ScreenBaseMixin
12
12
 
@@ -25,10 +25,13 @@ module MotionPrime
25
25
  [:base_screen, self.class_name_without_kvo.underscore.to_sym]
26
26
  end
27
27
 
28
- def on_load
29
- setup view, styles: default_styles do
30
- render
28
+ def will_appear
29
+ unless @on_appear_happened
30
+ setup view, styles: default_styles do
31
+ render
32
+ end
31
33
  end
34
+ @on_appear_happened = true
32
35
  end
33
36
  end
34
37
  end
@@ -5,6 +5,7 @@ module MotionPrime
5
5
  def self.new(menu, content, options={})
6
6
  screen = self.alloc.initWithContentViewController(nil, menuViewController: nil)
7
7
  screen.backgroundImage = MotionPrime::Config.sidebar.background_image
8
+ screen.parallaxEnabled = false
8
9
 
9
10
  full_width = UIScreen.mainScreen.bounds.size.width
10
11
 
@@ -58,7 +59,7 @@ module MotionPrime
58
59
  private
59
60
 
60
61
  def should_reinit_content?(new_controller)
61
- content_controller.nil? ||
62
+ content_controller.nil? ||
62
63
  content_controller.is_a?(TabBarController) ||
63
64
  new_controller.is_a?(TabBarController)
64
65
  end
@@ -23,5 +23,16 @@ module MotionPrime
23
23
  name.gsub("#{table_name}_", '')
24
24
  end
25
25
  end
26
+
27
+ def load_container_element(options = {})
28
+ @container_element ||= begin
29
+ options.merge!({
30
+ screen: screen,
31
+ section: self,
32
+ has_drawn_content: true
33
+ })
34
+ MotionPrime::BaseElement.factory(:table_view_cell, options)
35
+ end
36
+ end
26
37
  end
27
38
  end
@@ -17,6 +17,7 @@ module MotionPrime
17
17
  include ::MotionSupport::Callbacks
18
18
  include HasAuthorization
19
19
  include HasNormalizer
20
+ include HasClassFactory
20
21
  include DrawMixin
21
22
 
22
23
  attr_accessor :screen, :model, :name, :options, :elements, :section_styles
@@ -88,6 +89,7 @@ module MotionPrime
88
89
 
89
90
  def load_elements
90
91
  self.elements.values.each do |element|
92
+ element.size_to_fit_if_needed if element.is_a?(LabelDrawElement)
91
93
  element.computed_options if element.respond_to?(:computed_options)
92
94
  end
93
95
  end
@@ -198,7 +200,7 @@ module MotionPrime
198
200
  views = Array.wrap(keyboard_close_bindings_options[:views])
199
201
 
200
202
  elements.each { |el| views << el.view if %w[text_field text_view].include?(el.view_name) && el.view }
201
- (views + Array.wrap(keyboard_close_bindings_options[:views])).compact.each(&:resignFirstResponder)
203
+ views.compact.each(&:resignFirstResponder)
202
204
  end
203
205
 
204
206
  protected
@@ -54,14 +54,6 @@ module MotionPrime
54
54
  self.table_element = screen.table_view(options)
55
55
  end
56
56
 
57
- def render_cell(index, table)
58
- field = rows_for_section(index.section)[index.row]
59
- screen.table_view_cell section: field, reuse_identifier: cell_name(table, index), parent_view: table_view do |container_view, container_element|
60
- field.container_element = container_element
61
- field.render
62
- end
63
- end
64
-
65
57
  def reload_cell(section)
66
58
  field = section.name.to_sym
67
59
  index = field_indexes[field].split('_').map(&:to_i)
@@ -218,8 +210,8 @@ module MotionPrime
218
210
  end
219
211
 
220
212
  def load_field(field)
221
- klass = "MotionPrime::#{field[:type].classify}FieldSection".constantize
222
- klass.new(field.merge(screen: screen, table: self))
213
+ field_class = class_factory("#{field[:type]}_field_section", true)
214
+ field_class.new(field.merge(screen: screen, table: self))
223
215
  end
224
216
 
225
217
  def render_field?(name, options)
@@ -103,8 +103,8 @@ module MotionPrime
103
103
  self.tab_pages = []
104
104
  index = 0
105
105
  tab_options.each do |key, options|
106
- section_class = options[:page_section].classify
107
- page = "::#{section_class}Section".constantize.new(screen: screen, model: model)
106
+ page_class = class_factory("/#{options[:page_section]}_section")
107
+ page = page_class.new(screen: screen, model: model)
108
108
  page.render
109
109
  page.hide if index != tab_default
110
110
  self.tab_pages << page
@@ -117,13 +117,18 @@ module MotionPrime
117
117
  end
118
118
 
119
119
  def render_cell(index, table)
120
- item = row_by_index(index)
121
- screen.table_view_cell section: item, reuse_identifier: cell_name(table, index), parent_view: table_view, has_drawn_content: true do |container_view, container_element|
122
- # DrawSection allows as to draw inside the cell view, so we can setup
123
- # to use cell view as container
124
- item.container_element = container_element
125
- item.render
120
+ section = rows_for_section(index.section)[index.row]
121
+ cell_element = container_element_for(index)
122
+ cell_view = cell_element.render do
123
+ section.render
126
124
  end
125
+
126
+ @rendered_cells[index.section][index.row] = cell_view
127
+ on_row_render(cell_view, index)
128
+
129
+ preload_sections_for(index)
130
+
131
+ cell_view
127
132
  end
128
133
 
129
134
  def on_row_render(cell, index); end
@@ -148,12 +153,7 @@ module MotionPrime
148
153
  @rendered_cells ||= []
149
154
  @rendered_cells[index.section] ||= []
150
155
 
151
- cell = cached_cell(index, table) || render_cell(index, table).tap do |cell|
152
- @rendered_cells[index.section][index.row] = cell
153
- on_row_render(cell, index)
154
-
155
- preload_sections_for(index)
156
- end
156
+ cell = cached_cell(index, table) || render_cell(index, table)
157
157
 
158
158
  # run table view is appeared callback if needed
159
159
  if !@did_appear && index.row == rows_for_section(index.section).size - 1
@@ -203,6 +203,16 @@ module MotionPrime
203
203
  def on_async_data_loaded; end
204
204
  def on_async_data_preloaded(loaded_index); end
205
205
 
206
+ def cell_name(table, index)
207
+ record = row_by_index(index)
208
+ if record && record.model &&
209
+ record.model.respond_to?(:id) && record.model.id.present?
210
+ "cell_#{record.model.id}_#{data_stamp_for("#{index.section}_#{index.row}")}"
211
+ else
212
+ "cell_#{index.section}_#{index.row}_#{data_stamp_for("#{index.section}_#{index.row}")}"
213
+ end
214
+ end
215
+
206
216
  private
207
217
  def set_table_data
208
218
  cells = async_data? ? load_sections_async : table_data
@@ -225,16 +235,6 @@ module MotionPrime
225
235
  end
226
236
  end
227
237
 
228
- def cell_name(table, index)
229
- record = row_by_index(index)
230
- if record && record.model &&
231
- record.model.respond_to?(:id) && record.model.id.present?
232
- "cell_#{record.model.id}_#{data_stamp_for("#{index.section}_#{index.row}")}"
233
- else
234
- "cell_#{index.section}_#{index.row}_#{data_stamp_for("#{index.section}_#{index.row}")}"
235
- end
236
- end
237
-
238
238
  def cached_cell(index, table = nil)
239
239
  table ||= self.table_view
240
240
  table.dequeueReusableCellWithIdentifier(cell_name(table, index))
@@ -252,6 +252,19 @@ module MotionPrime
252
252
  cell = rows_for_section(index.section)[index.row]
253
253
  return unless cell.load_section # return if already loaded
254
254
  cell.load_elements
255
+ if async_data?
256
+ container_element = container_element_for(index)
257
+ container_element.computed_options # compute options
258
+ end
259
+ end
260
+
261
+ def container_element_for(index)
262
+ cell = rows_for_section(index.section)[index.row]
263
+ options = {
264
+ reuse_identifier: cell_name(table_view, index),
265
+ parent_view: table_view
266
+ }
267
+ cell.load_container_element(options)
255
268
  end
256
269
 
257
270
  def data_stamp_for(id)
@@ -1,8 +1,13 @@
1
1
  motion_require '../views/styles.rb'
2
2
  MotionPrime::Styles.define :_mixin do
3
+ style :label_reset,
4
+ top: nil, left: nil, height: nil, right: nil, bottom: nil, top: nil,
5
+ padding: nil, padding_top: nil, padding_left: nil, padding_right: nil, padding_bottom: nil,
6
+ size_to_fit: false
7
+
3
8
  style :multiline,
4
9
  size_to_fit: true,
5
10
  number_of_lines: 0,
6
- line_break_mode: :wordwrap,
11
+ line_break_mode: :word_wrap,
7
12
  line_spacing: 2
8
13
  end
@@ -38,7 +38,7 @@ MotionPrime::Styles.define :base_form do
38
38
  top: nil,
39
39
  bottom: 0,
40
40
  width: 300,
41
- line_break_mode: :wordwrap,
41
+ line_break_mode: :word_wrap,
42
42
  number_of_lines: 0,
43
43
  size_to_fit: true,
44
44
  text_color: proc { MotionPrime::Config.color.error },
@@ -1,4 +1,4 @@
1
- class DMButton < UIButton
1
+ class MPButton < UIButton
2
2
  include MotionPrime::SupportKeyValueStore
3
3
  include MotionPrime::SupportPaddingAttribute
4
4
  attr_accessor :sizeToFit
@@ -1,4 +1,4 @@
1
- class DMCellWithSection < UITableViewCell
1
+ class MPCellWithSection < UITableViewCell
2
2
  attr_accessor :section
3
3
 
4
4
  def setSection(section)
@@ -1,5 +1,5 @@
1
1
  # Search bar with background and no padding
2
- class UISearchBarCustom < UISearchBar
2
+ class MPSearchBarCustom < UISearchBar
3
3
  def layoutSubviews
4
4
  super
5
5
  text_field = subviews.objectAtIndex(0).subviews.detect do |view|
@@ -1,7 +1,7 @@
1
1
  # This class have some modifications for UITextField:
2
2
  # * support padding, padding_left, padding_right options
3
3
  # * support placeholder_color, placeholder_font options
4
- class DMTextField < UITextField
4
+ class MPTextField < UITextField
5
5
  include MotionPrime::SupportKeyValueStore
6
6
  include MotionPrime::SupportPaddingAttribute
7
7
  attr_accessor :placeholderColor, :placeholderFont, :readonly, :placeholderAlignment
@@ -30,7 +30,7 @@ class DMTextField < UITextField
30
30
  color.setFill
31
31
  font = self.placeholderFont || self.font || :system.uifont(16)
32
32
 
33
- truncation = :tailtruncation.uilinebreakmode
33
+ truncation = :tail_truncation.uilinebreakmode
34
34
  alignment = (placeholderAlignment || :left)
35
35
  alignment = alignment.uitextalignment if alignment.is_a?(Symbol)
36
36
  self.placeholder.drawInRect(rect, withFont: font, lineBreakMode: truncation, alignment: alignment)
@@ -1,7 +1,7 @@
1
1
  # This class have some modifications for UITextView:
2
2
  # * support padding, padding_left, padding_right options
3
3
  # * support placeholder, placeholder_color, placeholder_font options
4
- class DMTextView < UITextView
4
+ class MPTextView < UITextView
5
5
  include MotionPrime::SupportKeyValueStore
6
6
  include MotionPrime::SupportPaddingAttribute
7
7
  attr_accessor :placeholderColor, :placeholderFont, :placeholder
@@ -1,4 +1,4 @@
1
- class DMViewController < UIViewController
1
+ class MPViewController < UIViewController
2
2
  def self.new(args = {})
3
3
  self.alloc.initWithNibName(nil, bundle: nil).tap do |screen|
4
4
  screen.on_create(args) if screen.respond_to?(:on_create)
@@ -1,4 +1,4 @@
1
- class DMViewWithSection < UIView
1
+ class MPViewWithSection < UIView
2
2
  attr_accessor :section
3
3
 
4
4
  def setSection(section)
@@ -1,6 +1,5 @@
1
1
  module MotionPrime
2
2
  class TabBarController < UITabBarController
3
-
4
3
  def self.new(screens)
5
4
  controller = alloc.init
6
5
 
@@ -1,3 +1,3 @@
1
1
  module MotionPrime
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
@@ -1,5 +1,5 @@
1
1
  # TODO: make it part of Sections
2
- motion_require '../support/dm_cell_with_section'
2
+ motion_require '../support/mp_cell_with_section'
3
3
  module MotionPrime
4
4
  module Layout
5
5
  def add_view(klass, options = {}, &block)
@@ -39,7 +39,7 @@ module MotionPrime
39
39
  [::UIActionSheet, ::UIActivityIndicatorView, ::UIButton, ::UIDatePicker, ::UIImageView, ::UILabel,
40
40
  ::UIPageControl, ::UIPickerView, ::UIProgressView, ::UIScrollView, ::UISearchBar, ::UISegmentedControl,
41
41
  ::UISlider, ::UIStepper, ::UISwitch, ::UITabBar, ::UITableView, ::UITableViewCell, ::UITextField, ::UITextView,
42
- ::UIToolbar, ::UIWebView, ::UINavigationBar, ::DMCellWithSection, ::MBProgressHUD].each do |klass|
42
+ ::UIToolbar, ::UIWebView, ::UINavigationBar, ::MPCellWithSection, ::MBProgressHUD].each do |klass|
43
43
 
44
44
  shorthand = "#{klass}"[2..-1].underscore.to_sym
45
45
 
@@ -107,10 +107,11 @@ module MotionPrime
107
107
  options[:background_color] = :clear
108
108
  options.delete(:gradient)
109
109
  end
110
+
110
111
  klass.alloc.initWithStyle style, reuseIdentifier: options.delete(:reuse_identifier)
111
112
  },
112
113
  'UISearchBar' => Proc.new{|klass, options|
113
- klass = options[:search_field_background_image] ? UISearchBarCustom : UISearchBar
114
+ klass = options[:search_field_background_image] ? MPSearchBarCustom : UISearchBar
114
115
  search_bar = klass.alloc.init
115
116
  search_bar.autoresizingMask = UIViewAutoresizingFlexibleWidth
116
117
  search_bar
@@ -2,6 +2,7 @@ module MotionPrime
2
2
  class ViewStyler
3
3
  include FrameCalculatorMixin
4
4
  include HasStyles
5
+ include HasClassFactory
5
6
 
6
7
  attr_reader :view, :options
7
8
 
@@ -13,7 +14,9 @@ module MotionPrime
13
14
 
14
15
  def apply
15
16
  converted_options = convert_primitives_to_objects(options)
16
- setValuesForKeysWithDictionary(converted_options)
17
+ converted_options.each do |key, value|
18
+ set_option(key.to_s, value)
19
+ end
17
20
  end
18
21
 
19
22
  def convert_primitives_to_objects(options)
@@ -39,7 +42,7 @@ module MotionPrime
39
42
  end
40
43
  end
41
44
 
42
- def setValue(value, forUndefinedKey: key)
45
+ def set_option(key, value)
43
46
  # return if value.nil?
44
47
  # ignore options
45
48
  return if key == 'section' && !view.respond_to?(:section=)
@@ -56,15 +59,15 @@ module MotionPrime
56
59
  if key.end_with?('title_color')
57
60
  view.setTitleColor value.uicolor, forState: UIControlStateNormal
58
61
  elsif key.end_with?('alignment') && value.is_a?(Symbol)
59
- view.setValue value.uitextalignment, forKey: key.camelize
62
+ view.setValue value.uitextalignment, forKey: camelize_factory(key)
60
63
  elsif key.end_with?('line_break_mode') && value.is_a?(Symbol)
61
- view.setValue value.uilinebreakmode, forKey: key.camelize
64
+ view.setValue value.uilinebreakmode, forKey: camelize_factory(key)
62
65
  elsif key.end_with?('title_shadow_color')
63
66
  view.setTitleShadowColor value.uicolor, forState: UIControlStateNormal
64
67
  elsif key.end_with?('color')
65
68
  color = value.try(:uicolor)
66
69
  color = color.cgcolor if view.is_a?(CALayer)
67
- view.send :"#{key.camelize(:lower)}=", color
70
+ view.send :"#{low_camelize_factory(key)}=", color
68
71
  elsif key.end_with?('background_image')
69
72
  if view.is_a?(UIButton)
70
73
  view.setBackgroundImage value.uiimage, forState: UIControlStateNormal
@@ -79,10 +82,10 @@ module MotionPrime
79
82
  bg_view.backgroundColor = value[:color].uicolor
80
83
  view.backgroundView = bg_view
81
84
  else
82
- view.setValue value, forKey: key.camelize(:lower)
85
+ view.setValue value, forKey: low_camelize_factory(key)
83
86
  end
84
87
  elsif key.end_with?('image')
85
- view.setValue value.uiimage, forKey: key.camelize
88
+ view.setValue value.uiimage, forKey: camelize_factory(key)
86
89
  elsif key.end_with?('_content_inset')
87
90
  current_inset = view.contentInset
88
91
  current_inset.send("#{key.partition('_').first}=", value)
@@ -144,9 +147,9 @@ module MotionPrime
144
147
  view.separatorInset = UIEdgeInsetsMake(0, value.first, 0, value.last)
145
148
  end
146
149
  elsif value.is_a?(Hash)
147
- self.class.new(view.send(key.camelize(:lower).to_sym), nil, value.merge(parent_frame: options[:frame] || options[:parent_frame])).apply
150
+ self.class.new(view.send(low_camelize_factory(key).to_sym), nil, value.merge(parent_frame: options[:frame] || options[:parent_frame])).apply
148
151
  else
149
- view.setValue value, forKey: key.camelize(:lower)
152
+ view.setValue value, forKey: low_camelize_factory(key)
150
153
  end
151
154
  end
152
155
 
@@ -3,9 +3,10 @@ describe "BaseScreen" do
3
3
  before do
4
4
  @screen = BaseScreen.new()
5
5
  @screen.on_load
6
+ @screen.will_appear
6
7
  end
7
8
 
8
- it "should render screen on load" do
9
+ it "should render screen on appear" do
9
10
  @screen.was_rendered.should == true
10
11
  end
11
12
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion-prime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Iskander Haziev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-12 00:00:00.000000000 Z
11
+ date: 2013-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -136,20 +136,6 @@ dependencies:
136
136
  - - ! '>='
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
- - !ruby/object:Gem::Dependency
140
- name: nano-store
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - ! '>='
144
- - !ruby/object:Gem::Version
145
- version: '0'
146
- type: :runtime
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - ! '>='
151
- - !ruby/object:Gem::Version
152
- version: '0'
153
139
  - !ruby/object:Gem::Dependency
154
140
  name: methadone
155
141
  requirement: !ruby/object:Gem::Requirement
@@ -242,6 +228,7 @@ files:
242
228
  - motion-prime/elements/text_field.rb
243
229
  - motion-prime/elements/text_view.rb
244
230
  - motion-prime/helpers/has_authorization.rb
231
+ - motion-prime/helpers/has_class_factory.rb
245
232
  - motion-prime/helpers/has_normalizer.rb
246
233
  - motion-prime/helpers/has_search_bar.rb
247
234
  - motion-prime/helpers/has_style_chain_builder.rb
@@ -289,16 +276,15 @@ files:
289
276
  - motion-prime/styles/form.rb
290
277
  - motion-prime/support/_key_value_store.rb
291
278
  - motion-prime/support/_padding_attribute.rb
292
- - motion-prime/support/dm_button.rb
293
- - motion-prime/support/dm_cell_with_section.rb
294
- - motion-prime/support/dm_text_field.rb
295
- - motion-prime/support/dm_text_view.rb
296
- - motion-prime/support/dm_view_controller.rb
297
- - motion-prime/support/dm_view_with_section.rb
279
+ - motion-prime/support/mp_button.rb
280
+ - motion-prime/support/mp_cell_with_section.rb
298
281
  - motion-prime/support/mp_label.rb
299
- - motion-prime/support/navigation_controller.rb
282
+ - motion-prime/support/mp_search_bar_custom.rb
283
+ - motion-prime/support/mp_text_field.rb
284
+ - motion-prime/support/mp_text_view.rb
285
+ - motion-prime/support/mp_view_controller.rb
286
+ - motion-prime/support/mp_view_with_section.rb
300
287
  - motion-prime/support/tab_bar_controller.rb
301
- - motion-prime/support/ui_search_bar_custom.rb
302
288
  - motion-prime/support/ui_view.rb
303
289
  - motion-prime/version.rb
304
290
  - motion-prime/views/_frame_calculator_mixin.rb
@@ -1,4 +0,0 @@
1
- module MotionPrime
2
- class NavigationController < UINavigationController
3
- end
4
- end