ruby_motion_query 1.2.0 → 1.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 076402a0a8e41d928b775cb8319a0f0ba942c7a9
4
- data.tar.gz: 3a41cd46bdc0deb04b462372d1390e41f4868621
3
+ metadata.gz: f07e29c003088b2fdb825513424edf07e8673300
4
+ data.tar.gz: 17091f33590d403601b76abcb6053b101cde9bdb
5
5
  SHA512:
6
- metadata.gz: fbfa05daa2ca2013f0402ec58ecc6ef0a9e4d0e3a7e656a43aaf8e3e75f74fd587a8d1fb31d3e8291f1a09bf03a150224abdf3ea3d08d3dce20bdebf382820db
7
- data.tar.gz: 9eb821d64590ef1670c3dc4b97b0beb49ade5aecd765e8a75baee54953f1142a5cb93019eca3587f305b105dc7f7778f7d4574a7027dd20319b11ee3b58a67e6
6
+ metadata.gz: f08414538bd10286c20ee97834216cc562de28b5bf348d0443143b773469c1ca9e087c20b3dae73c969845f9fc81edf9d362e90993d9fa38d46c8e4b2336642b
7
+ data.tar.gz: 7f21906b0acc652fe1221f9b957c07139a5fb6785f0b6624e656e3229b7bca59d6e470e916ab8e578cffb1bb4601deb24bf33248754dbf35669c2e126c598f9f
data/motion/ext.rb CHANGED
@@ -53,3 +53,54 @@ class UIViewController
53
53
  @_rmq_data ||= RubyMotionQuery::ControllerData.new
54
54
  end
55
55
  end
56
+
57
+ if RUBYMOTION_ENV == "development"
58
+ module Kernel
59
+ def rmq_live_stylesheets(interval = 0.5, debug=false)
60
+ @live_reload_debug = debug
61
+ if interval == false
62
+ @live_reload_timer.invalidate if @live_reload_timer
63
+ @live_reload_timer = nil
64
+ "Live reloading of RMQ stylesheets is now off."
65
+ else
66
+ enable_rmq_live_stylesheets(interval)
67
+ end
68
+ end
69
+
70
+ private
71
+
72
+ def enable_rmq_live_stylesheets(interval)
73
+ # Get list of stylesheet files
74
+ root_path = File.dirname(__FILE__).gsub(/motion$/,"")
75
+ path_query = "#{root_path}app/stylesheets/*.rb"
76
+ stylesheet_file_paths = Dir.glob(path_query)
77
+ stylesheet_file_paths.delete_if{|stylesheet| stylesheet =~ /application_stylesheet\.rb$/}
78
+
79
+ stylesheets = stylesheet_file_paths.inject({}) do |out, stylesheet_path_file|
80
+ klassname = File.basename(stylesheet_path_file, '.rb')
81
+ klassname.gsub!("_", " ").gsub!(/\b(?<!['’`])[a-z]/){ $&.capitalize }.gsub!(/\s/, "")
82
+ out[klassname] = {
83
+ path: stylesheet_path_file,
84
+ modified: File.mtime(stylesheet_path_file)
85
+ }
86
+ out
87
+ end
88
+
89
+ @live_reload_timer = RubyMotionQuery::App.every(interval) do
90
+ vc_rmq = rmq.view_controller.rmq
91
+ klass_name = vc_rmq.stylesheet.class.name
92
+ if stylesheet = stylesheets[klass_name]
93
+ if File.mtime(stylesheet[:path]) > stylesheet[:modified]
94
+ code = File.read(stylesheet[:path])
95
+ puts "Reloaded #{klass_name}." if @live_reload_debug
96
+ eval(code)
97
+ vc_rmq.all.reapply_styles
98
+ stylesheets[klass_name][:modified] = File.mtime(stylesheet[:path])
99
+ end
100
+ end
101
+ end
102
+
103
+ "Live reloading of RMQ stylesheets is now on."
104
+ end
105
+ end
106
+ end
@@ -37,6 +37,7 @@ module RubyMotionQuery
37
37
  when UITextField then view.text = new_data
38
38
  #when UINavigationBar then
39
39
  #when UIScrollView then
40
+ when UIProgressView then view.setProgress(new_data, animated: true)
40
41
 
41
42
  # TODO, finish
42
43
  end
@@ -63,6 +64,7 @@ module RubyMotionQuery
63
64
  when UITextField then view.text
64
65
  #when UINavigationBar then
65
66
  #when UIScrollView then
67
+ when UIProgressView then view.progress
66
68
 
67
69
  # TODO, finish
68
70
  end
@@ -32,6 +32,20 @@ module RubyMotionQuery
32
32
  UIApplication.sharedApplication.delegate
33
33
  end
34
34
 
35
+ # @return [UIApplication]
36
+ def get
37
+ UIApplication.sharedApplication
38
+ end
39
+
40
+ # Returns boolean of success of hiding
41
+ # Tested in the example app!
42
+ # @return [Boolean]
43
+ def hide_keyboard
44
+ self.get.sendAction(:resignFirstResponder, to:nil, from:nil, forEvent:nil)
45
+ end
46
+ alias :resign_responders :hide_keyboard
47
+ alias :end_editing :hide_keyboard
48
+
35
49
  # @return [Symbol] Environment the app is running it
36
50
  def environment
37
51
  @_environment ||= RUBYMOTION_ENV.to_sym
@@ -104,7 +118,7 @@ module RubyMotionQuery
104
118
  if root_view_controller || ((window = RMQ.app.window) && (root_view_controller = window.rootViewController))
105
119
  case root_view_controller
106
120
  when UINavigationController
107
- root_view_controller.visibleViewController
121
+ current_view_controller(root_view_controller.visibleViewController)
108
122
  when UITabBarController
109
123
  current_view_controller(root_view_controller.selectedViewController)
110
124
  else
@@ -29,6 +29,13 @@ module RubyMotionQuery
29
29
  end
30
30
 
31
31
  def handle_gesture_or_event
32
+ # Handle debounce logic
33
+ if @debounce_length
34
+ return if (@debounce_stamp + @debounce_length > Time.now)
35
+ # update timestamp
36
+ @debounce_stamp = Time.now
37
+ end
38
+
32
39
  case @block.arity
33
40
  when 2
34
41
  @block.call(@sender, self)
@@ -40,6 +47,11 @@ module RubyMotionQuery
40
47
  end
41
48
 
42
49
  def set_options(opts)
50
+ if opts[:debounce]
51
+ @debounce_length = opts[:debounce]
52
+ @debounce_stamp = Time.now
53
+ end
54
+
43
55
  if gesture?
44
56
  @recognizer.tap do |o|
45
57
  o.cancelsTouchesInView = opts[:cancels_touches_in_view] if opts.include?(:cancels_touches_in_view)
@@ -67,7 +79,7 @@ module RubyMotionQuery
67
79
  end
68
80
  end
69
81
  end
70
- end
82
+ end #set_options
71
83
 
72
84
  def gesture?
73
85
  @gesture
@@ -17,7 +17,14 @@ module RubyMotionQuery
17
17
 
18
18
  # @return [UIImage]
19
19
  def resource_for_device(file_base_name, opts = {})
20
- resource( RMQ.device.four_inch? ? "#{file_base_name}-568h" : file_base_name, opts)
20
+ ext = if RMQ.device.five_point_five_inch?
21
+ "-736h"
22
+ elsif RMQ.device.four_point_seven_inch?
23
+ "-667h"
24
+ elsif RMQ.device.four_inch?
25
+ "-568h"
26
+ end
27
+ resource("#{file_base_name}#{ext}")
21
28
  end
22
29
 
23
30
  # @return [UIImage]
@@ -6,7 +6,14 @@ module RubyMotionQuery
6
6
  @view.setTitle(value, forState: UIControlStateNormal)
7
7
  end
8
8
  def text
9
- @view.title
9
+ @view.titleForState(UIControlStateNormal)
10
+ end
11
+
12
+ def attributed_text=(value)
13
+ @view.setAttributedTitle(value, forState: UIControlStateNormal)
14
+ end
15
+ def attributed_text
16
+ @view.attributedTitleForState(UIControlStateNormal)
10
17
  end
11
18
 
12
19
  def font=(value) ; @view.titleLabel.font = value ; end
@@ -16,14 +23,14 @@ module RubyMotionQuery
16
23
  @view.setTitleColor(value, forState: UIControlStateNormal)
17
24
  end
18
25
  def color
19
- @view.titleColor
26
+ @view.titleColorForState(UIControlStateNormal)
20
27
  end
21
28
 
22
29
  def color_highlighted=(value)
23
30
  @view.setTitleColor(value, forState: UIControlStateHighlighted)
24
31
  end
25
32
  def color_highlighted
26
- @view.titleColorforState(UIControlStateHighlighted)
33
+ @view.titleColorForState(UIControlStateHighlighted)
27
34
  end
28
35
 
29
36
  def tint_color=(value)
@@ -33,27 +40,43 @@ module RubyMotionQuery
33
40
  @view.tintColor
34
41
  end
35
42
 
36
- def image=(value)
37
- self.image_normal = value
38
- end
39
43
  def image_normal=(value)
40
44
  @view.setImage value, forState: UIControlStateNormal
41
45
  end
46
+ def image_normal
47
+ @view.imageForState(UIControlStateNormal)
48
+ end
49
+ alias :image :image_normal
50
+ alias :image= :image_normal=
42
51
 
43
52
  def image_highlighted=(value)
44
- @view.setImage value, forState: UIControlStateHighlighted
53
+ @view.setImage(value, forState: UIControlStateHighlighted)
54
+ end
55
+ def image_highlighted
56
+ @view.imageForState(UIControlStateHighlighted)
45
57
  end
46
58
 
47
59
  def background_image_normal=(value)
48
- @view.setBackgroundImage value, forState: UIControlStateNormal
60
+ @view.setBackgroundImage(value, forState: UIControlStateNormal)
49
61
  end
62
+ def background_image_normal
63
+ @view.backgroundImageForState(UIControlStateNormal)
64
+ end
65
+ alias :background_image :background_image_normal
66
+ alias :background_image= :background_image_normal=
50
67
 
51
68
  def background_image_highlighted=(value)
52
- @view.setBackgroundImage value, forState: UIControlStateHighlighted
69
+ @view.setBackgroundImage(value, forState: UIControlStateHighlighted)
70
+ end
71
+ def background_image_highlighted
72
+ @view.backgroundImageForState(UIControlStateHighlighted)
53
73
  end
54
74
 
55
75
  def background_image_selected=(value)
56
- @view.setBackgroundImage value, forState: UIControlStateSelected
76
+ @view.setBackgroundImage(value, forState: UIControlStateSelected)
77
+ end
78
+ def background_image_selected
79
+ @view.backgroundImageForState(UIControlStateSelected)
57
80
  end
58
81
 
59
82
  def adjust_image_when_highlighted=(value)
@@ -98,12 +121,18 @@ module RubyMotionQuery
98
121
  @view.imageEdgeInsets
99
122
  end
100
123
 
101
- def text_highlighted value
124
+ def text_highlighted=(value)
102
125
  @view.setTitle(value, forState:UIControlStateHighlighted)
103
126
  end
127
+ def text_highlighted
128
+ @view.titleForState(UIControlStateHighlighted)
129
+ end
104
130
 
105
- def text_highlighted= value
106
- @view.setTitle(value, forState:UIControlStateHighlighted)
131
+ def attributed_text_highlighted=(value)
132
+ @view.setAttributedTitle(value, forState: UIControlStateHighlighted)
133
+ end
134
+ def attributed_text_highlighted
135
+ @view.attributedTitleForState(UIControlStateHighlighted)
107
136
  end
108
137
 
109
138
  end
@@ -1,8 +1,25 @@
1
1
  module RubyMotionQuery
2
2
  module Stylers
3
3
 
4
- class UIDatePickerStyler < UIControlStyler
4
+ class UIDatePickerStyler < UIControlStyler
5
+
6
+ DATE_PICKER_MODES = {
7
+ time: UIDatePickerModeTime,
8
+ date: UIDatePickerModeDate,
9
+ date_and_time: UIDatePickerModeDateAndTime,
10
+ date_time: UIDatePickerModeDateAndTime,
11
+ count_down: UIDatePickerModeCountDownTimer,
12
+ count_down_timer: UIDatePickerModeCountDownTimer,
13
+ }
14
+
15
+ def date_picker_mode=(value)
16
+ @view.datePickerMode = DATE_PICKER_MODES[value] || value
17
+ end
18
+
19
+ def date_picker_mode
20
+ @view.datePickerMode
21
+ end
5
22
  end
6
23
 
7
24
  end
8
- end
25
+ end
@@ -33,6 +33,11 @@ module RubyMotionQuery
33
33
  end
34
34
  end
35
35
 
36
+ def background_color=(value)
37
+ @view.backgroundView = nil if @view.backgroundView
38
+ @view.setBackgroundColor value
39
+ end
40
+
36
41
  SEPARATOR_STYLES = {
37
42
  none: UITableViewCellSeparatorStyleNone,
38
43
  single: UITableViewCellSeparatorStyleSingleLine,
@@ -392,6 +392,12 @@ module RubyMotionQuery
392
392
  end
393
393
  def shadow_path ; @view.layer.shadowPath ; end
394
394
 
395
+ def user_interaction_enabled=(value)
396
+ @view.setUserInteractionEnabled(!!value)
397
+ end
398
+ def user_interaction_enabled
399
+ @view.isUserInteractionEnabled
400
+ end
395
401
 
396
402
  # @deprecated - use frame hashs
397
403
  def left=(value)
@@ -145,7 +145,7 @@ module RubyMotionQuery
145
145
  view.rmq_style_applied
146
146
  rescue NoMethodError => e
147
147
  if e.message =~ /.*#{style_name.to_s}.*/
148
- puts "\n[RMQ ERROR] style_name :#{style_name} doesn't exist for a #{view.class.name}. Add 'def #{style_name}(st)' to #{stylesheet.class.name} class\n\n"
148
+ $stderr.puts "\n[RMQ ERROR] style_name :#{style_name} doesn't exist for a #{view.class.name}. Add 'def #{style_name}(st)' to #{stylesheet.class.name} class\n\n"
149
149
  else
150
150
  raise e
151
151
  end
@@ -19,7 +19,6 @@ module RubyMotionQuery
19
19
  # @return [RMQ]
20
20
  def add_subview(view_or_constant, opts={})
21
21
  subviews_added = []
22
- style = opts[:style]
23
22
 
24
23
  selected.each do |selected_view|
25
24
  created = false
@@ -63,11 +62,14 @@ module RubyMotionQuery
63
62
  new_view.rmq_appended if appended
64
63
 
65
64
  if self.stylesheet
66
- apply_style_to_view(new_view, style) if style
65
+ apply_style_to_view(new_view, opts[:style]) if opts[:style]
67
66
  end
68
67
  end
69
68
 
70
- RMQ.create_with_array_and_selectors(subviews_added, selectors, @context, self)
69
+ view = RMQ.create_with_array_and_selectors(subviews_added, selectors, @context, self)
70
+ opts[:block].call view if opts[:block]
71
+ opts[:raw_block].call view.get if opts[:raw_block]
72
+ view
71
73
  end
72
74
  alias :insert :add_subview
73
75
 
@@ -93,8 +95,9 @@ module RubyMotionQuery
93
95
  # rmq.append(UIImageView)
94
96
  #
95
97
  # @return [RMQ]
96
- def append(view_or_constant, style=nil, opts = {})
98
+ def append(view_or_constant, style=nil, opts = {}, &block)
97
99
  opts[:style] = style
100
+ opts[:block] = block if block
98
101
  add_subview(view_or_constant, opts)
99
102
  end
100
103
 
@@ -103,16 +106,42 @@ module RubyMotionQuery
103
106
  # @example
104
107
  # @my_button = rmq.append! UIButton
105
108
  # @my_label = rmq.append!(UILabel, :my_label)
106
- def append!(view_or_constant, style=nil, opts = {})
109
+ def append!(view_or_constant, style=nil, opts = {}, &block)
110
+ opts[:raw_block] = block if block
107
111
  append(view_or_constant, style, opts).get
108
112
  end
109
113
 
114
+ # Same as append, but will look for a view with the same name and reapply styles
115
+ # to it if it finds one. If it doesn't, it'll append as normal.
116
+ #
117
+ # @example
118
+ # @my_button = rmq.find_or_append(UIButton, :my_button)
119
+ # @my_button = rmq.find_or_append(UIButton, :my_button) # Only one created
120
+ def find_or_append(view_or_constant, style=nil, opts = {}, &block)
121
+ if style && (q = self.find(style)) && q.length > 0
122
+ view_or_constant = q.get
123
+ end
124
+
125
+ append(view_or_constant, style, opts, &block)
126
+ end
127
+
128
+ # Same as append!, but will look for a view with the same name and reapply styles
129
+ # to it if it finds one. If it doesn't, it'll append! as normal.
130
+ #
131
+ # @example
132
+ # @my_button = rmq.find_or_append!(UIButton, :my_button)
133
+ # @my_button = rmq.find_or_append!(UIButton, :my_button) # Only one created
134
+ def find_or_append!(view_or_constant, style=nil, opts = {}, &block)
135
+ find_or_append(view_or_constant, style, opts, &block).get
136
+ end
137
+
110
138
  # Just like append, but inserts the view at index 0 of the subview array
111
139
  #
112
140
  # @return [RMQ]
113
- def unshift(view_or_constant, style=nil, opts = {})
141
+ def unshift(view_or_constant, style=nil, opts = {}, &block)
114
142
  opts[:at_index] = 0
115
143
  opts[:style] = style
144
+ opts[:block] = block if block
116
145
  add_subview view_or_constant, opts
117
146
  end
118
147
  alias :prepend :unshift
@@ -122,7 +151,8 @@ module RubyMotionQuery
122
151
  # @example
123
152
  # @my_button = rmq.prepend! UIButton
124
153
  # @my_label = rmq.prepend!(UILabel, :my_label)
125
- def unshift!(view_or_constant, style=nil, opts = {})
154
+ def unshift!(view_or_constant, style=nil, opts = {}, &block)
155
+ opts[:raw_block] = block if block
126
156
  unshift(view_or_constant, style, opts).get
127
157
  end
128
158
  alias :prepend! :unshift!
@@ -147,10 +177,11 @@ module RubyMotionQuery
147
177
  # end
148
178
  # end
149
179
  #
150
- def create(view_or_constant, style = nil, opts = {})
180
+ def create(view_or_constant, style = nil, opts = {}, &block)
151
181
  # TODO, refactor so that add_subview uses create, not backwards like it is now
152
182
  opts[:do_not_add] = true
153
183
  opts[:style] = style
184
+ opts[:block] = block if block
154
185
  add_subview view_or_constant, opts
155
186
  end
156
187
 
@@ -158,7 +189,8 @@ module RubyMotionQuery
158
189
  #
159
190
  # @example
160
191
  # @my_button = rmq.create! UIButton
161
- def create!(view_or_constant, style=nil, opts = {})
192
+ def create!(view_or_constant, style=nil, opts = {}, &block)
193
+ opts[:raw_block] = block if block
162
194
  create(view_or_constant, style, opts).get
163
195
  end
164
196
 
@@ -174,9 +206,10 @@ module RubyMotionQuery
174
206
  # def rmq_build
175
207
  # rmq.append(UIView, :foo)
176
208
  # end
177
- def build(view, style = nil, opts = {})
209
+ def build(view, style = nil, opts = {}, &block)
178
210
  opts[:do_not_add] = true
179
211
  opts[:style] = style
212
+ opts[:block] = block if block
180
213
  add_subview view, opts
181
214
  end
182
215
 
@@ -184,7 +217,8 @@ module RubyMotionQuery
184
217
  #
185
218
  # @example
186
219
  # @my_cell = rmq.build! cell
187
- def build!(view, style = nil, opts = {})
220
+ def build!(view, style = nil, opts = {}, &block)
221
+ opts[:raw_block] = block if block
188
222
  build(view, style, opts).get
189
223
  end
190
224
 
@@ -18,6 +18,16 @@ module RubyMotionQuery
18
18
  end
19
19
  end
20
20
 
21
+ # Converts any string to a friendly symbol version.
22
+ # Example: RubyMotionQuery::RMQ.symbolize("This is a TEST!!")
23
+ # #=> :this_is_a_test
24
+ #
25
+ # @param [String]
26
+ # @return [Symbol]
27
+ def symbolize(s)
28
+ s.to_s.gsub(/\s+/,"_").gsub(/\W+/,"").downcase.to_sym
29
+ end
30
+
21
31
  # @param view
22
32
  # @return [UIViewController] The controller the view it is sitting in, or nil if it's not sitting anywhere in particular
23
33
  def controller_for_view(view)
@@ -1,5 +1,5 @@
1
1
  module RubyMotionQuery
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
 
4
4
  class RMQ
5
5
  def version
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_motion_query
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd Werth
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-03-19 00:00:00.000000000 Z
12
+ date: 2015-04-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bacon