ruby_motion_query 0.5.7 → 0.5.8

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: 6e5ff3ba1784ba4853de389ef894f7f88133be26
4
- data.tar.gz: 3c8c609b0d461f2e381b5a17598eed68548cda93
3
+ metadata.gz: aa133628d3efe0e1beb494c8ef295c3a7cdab391
4
+ data.tar.gz: edc16ec2f3ec05282b28ca648ffe3b59ad85c53e
5
5
  SHA512:
6
- metadata.gz: b66320409149b8836ae9cbb1ef7453b365ffe9961216254a1c21429b5000df8b397d0390160a94f6b5ce0f12f1016e2c802fea0c457e4b03264f2f40dc0fedbb
7
- data.tar.gz: cbc448fef154692862a6b52b477bab49a3fa9d270fde94140010089990e1521c847c241187faecf25f7c782ba4aaad87c08ad24c95e85c4b47ab5ed4ebb656a7
6
+ metadata.gz: 026d4488d133248e345a94ba44ed8f4f288d4bb5dc13e734528dd0d5fc934a82452f0ddf0e8b142560f5328b3f71cd6e85f883ec4af42f9236044ac7b6c842fb
7
+ data.tar.gz: f19f35abb82757fc11d29e4c39e6ce9a425d5ce44d252f522e5c6db4c495b4420ef58b527dc925b338d015af3cdad5c16b113e32b76b0c242b8f97dd22c7d09a
data/README.md CHANGED
@@ -100,9 +100,7 @@ for **bleeding edge**, add this to your `Gemfile`:
100
100
 
101
101
  ## Deprecation
102
102
 
103
- - **RubyMotionQuery::RMQ.weak_ref(object)** - no longer needed post RubyMotion 2.18
104
103
  - **UIView#rmq_did_create(self_in_rmq)** - *Use rmq_build instead*
105
- - **RubyMotionQuery::RMQ.weak_ref_to_strong_ref(object)** - no longer needed post RubyMotion 2.24
106
104
 
107
105
  <br />
108
106
 
@@ -295,11 +293,11 @@ end
295
293
 
296
294
  ----
297
295
 
298
- * build: takes an existing view, applies the style if it exists, then calls rmq_build method
299
- * create: creates the view when given the class, or uses an existing view you pass it, then does a [build]
300
- * append: [create] + appends the view to the end of the subview tree or to then end of the children of a view (if called on an rmq object with that view in it)
301
- * prepend: Same as [append], but inserts the view to beginning of the subview tree (overall or view's children)
302
- * insert: Same as [append], but inserts the view at the index of the subview tree (overall or view's children)
296
+ * **build**: takes an existing view, applies the style if it exists, then calls rmq_build method
297
+ * **create**: creates the view when given the class, or uses an existing view you pass it, then does a [build]
298
+ * **append**: [create] + appends the view to the end of the subview tree or to then end of the children of a view (if called on an rmq object with that view in it)
299
+ * **prepend**: Same as [append], but inserts the view to beginning of the subview tree (overall or view's children)
300
+ * **insert**: Same as [append], but inserts the view at the index of the subview tree (overall or view's children)
303
301
 
304
302
  ```ruby
305
303
  rmq.append(UILabel) # Creates a UILabel in the current controller
@@ -327,6 +325,27 @@ rmq.root_view
327
325
  rmq.view_controller
328
326
  ```
329
327
 
328
+ Often when appending a subview, you assign the view to a instance variable, like so:
329
+
330
+ ```ruby
331
+ @name = rmq.append(UILabel, :name).get
332
+ ```
333
+
334
+ The **.get** returns the actual view. Without it you'll get a reference to an rmq instance, which is how
335
+ chaining works.
336
+
337
+ This is such a common pattern, an RMQ user (https://github.com/shreeve) created append!, which I've included into RMQ.
338
+ The ! version of append or create returns the view directly:
339
+
340
+ ```ruby
341
+ @name = rmq.append!(UILabel, :name)
342
+ # Or the even shorter:
343
+ @name = rmq.append! UILabel, :name
344
+ ```
345
+
346
+
347
+
348
+
330
349
  #### Create a view
331
350
  If you want to create a view but not add it to the subviews of any other view, you can
332
351
  use #create. It's basically #append without the actual appending.
@@ -559,6 +578,10 @@ If you see Event, just remember that's either an event or gesture. I decided to
559
578
  :pinch
560
579
  :rotate
561
580
  :swipe
581
+ :swipe_up
582
+ :swipe_down
583
+ :swipe_left
584
+ :swipe_right
562
585
  :pan
563
586
  :long_press
564
587
  ```
@@ -638,6 +661,16 @@ rmq(my_text_field).focus # or .become_first_responder
638
661
 
639
662
  ----
640
663
 
664
+ The most basic:
665
+
666
+ ```ruby
667
+ rmq.animate do |q|
668
+ rmq(UIButton).nudge r: 40
669
+ end
670
+ ```
671
+
672
+ Some more options, this time it is animating a selected view:
673
+
641
674
  ```ruby
642
675
  rmq(my_view).animate(
643
676
  duration: 0.3,
@@ -674,6 +707,8 @@ rmq(selectors).animate(
674
707
 
675
708
  ----
676
709
 
710
+ See animate above.
711
+
677
712
  #### Current animations included:
678
713
 
679
714
  ```ruby
@@ -684,6 +719,8 @@ rmq(my_view).animations.fade_out(duration: 0.8)
684
719
 
685
720
  rmq(my_view).animations.blink
686
721
  rmq(my_view).animations.throb
722
+ rmq(my_view).animations.sink_and_throb
723
+ rmq(my_view).animations.land_and_sink_and_throb
687
724
  rmq(my_view).animations.drop_and_spin
688
725
 
689
726
  rmq.animations.start_spinner
data/motion/ext.rb CHANGED
@@ -26,10 +26,6 @@ class UIView
26
26
  def rmq_appended
27
27
  end
28
28
 
29
- # I intend for this to be protected
30
- # Do not call rmq from outside a view. Because of some weirdness with table cells
31
- # and event blocks this has to be public (later I want to figure out why exactly).
32
- #
33
29
  # Technically my_view.rmq is the same as rmq(my_view), so it may seem enticing to use
34
30
  # but the really nice thing about rmq is its consistent API, and doing this
35
31
  # for one view: my_view.rmq and this for two views: rmq(my_view, my_other_view) sucks
@@ -4,8 +4,9 @@ module RubyMotionQuery
4
4
  # Animate
5
5
  #
6
6
  # @return [RMQ]
7
- def animate(opts = {})
8
- animations_callback = (opts[:animations] || opts[:changes])
7
+ def animate(opts = {}, &block)
8
+
9
+ animations_callback = (block || opts[:animations] || opts[:changes])
9
10
  after_callback = (opts[:completion] || opts[:after])
10
11
  return self unless animations_callback
11
12
 
@@ -87,15 +88,15 @@ module RubyMotionQuery
87
88
 
88
89
  # @return [RMQ]
89
90
  def throb(opts = {})
90
- opts.merge!({
91
+ opts = {
91
92
  duration: 0.4,
92
93
  animations: ->(cq) {
93
94
  cq.style {|st| st.scale = 1.0}
94
95
  }
95
- })
96
+ }.merge(opts)
96
97
 
97
98
  out = @rmq.animate(
98
- duration: 0.1,
99
+ duration: opts[:duration_out] || 0.1,
99
100
  animations: ->(q) {
100
101
  q.style {|st| st.scale = 1.1}
101
102
  },
@@ -110,15 +111,15 @@ module RubyMotionQuery
110
111
 
111
112
  # @return [RMQ]
112
113
  def sink_and_throb(opts = {})
113
- opts.merge!({
114
+ opts = {
114
115
  duration: 0.3,
115
116
  animations: ->(cq) {
116
117
  cq.animations.throb(duration: 0.6)
117
118
  }
118
- })
119
+ }.merge(opts)
119
120
 
120
121
  out = @rmq.animate(
121
- duration: 0.1,
122
+ duration: opts[:duration_out] || 0.1,
122
123
  animations: ->(q) {
123
124
  q.style {|st| st.scale = 0.9}
124
125
  },
@@ -139,7 +140,7 @@ module RubyMotionQuery
139
140
  st.hidden = false
140
141
  end
141
142
 
142
- opts.merge!({
143
+ opts = {
143
144
  duration: 0.5,
144
145
  animations: ->(cq) {
145
146
  cq.style do |st|
@@ -152,7 +153,7 @@ module RubyMotionQuery
152
153
  last_completion_rmq.animations.throb
153
154
  end
154
155
  }
155
- })
156
+ }.merge(opts)
156
157
 
157
158
  @rmq.animate(opts)
158
159
  end
@@ -160,7 +161,7 @@ module RubyMotionQuery
160
161
  # @return [RMQ]
161
162
  def drop_and_spin(opts = {})
162
163
  remove_view = opts[:remove_view]
163
- opts.merge!({
164
+ opts = {
164
165
  duration: 0.4 + (rand(8) / 10),
165
166
  options: UIViewAnimationOptionCurveEaseIn|UIViewAnimationOptionBeginFromCurrentState,
166
167
  animations: ->(cq) {
@@ -182,7 +183,7 @@ module RubyMotionQuery
182
183
  end
183
184
  end
184
185
  }
185
- })
186
+ }.merge(opts)
186
187
 
187
188
  @rmq.animate(opts)
188
189
  end
@@ -6,7 +6,7 @@ module RubyMotionQuery
6
6
  end
7
7
 
8
8
  # @return [Color]
9
- def color
9
+ def color
10
10
  Color
11
11
  end
12
12
  end
@@ -17,55 +17,55 @@ module RubyMotionQuery
17
17
  # # In a stylesheet, you can just use color. Anywhere else these would be
18
18
  # # rmq.color.clear, etc
19
19
  #
20
- # color.clear
21
- # color.white
22
- # color.light_gray
23
- # color.gray
24
- # color.dark_gray
25
- # color.black
26
- #
27
- # color.red
28
- # color.green
29
- # color.blue
30
- # color.yellow
31
- # color.orange
32
- # color.purple
33
- # color.brown
34
- # color.cyan
35
- # color.magenta
36
- #
37
- # color.table_view
20
+ # color.clear
21
+ # color.white
22
+ # color.light_gray
23
+ # color.gray
24
+ # color.dark_gray
25
+ # color.black
26
+ #
27
+ # color.red
28
+ # color.green
29
+ # color.blue
30
+ # color.yellow
31
+ # color.orange
32
+ # color.purple
33
+ # color.brown
34
+ # color.cyan
35
+ # color.magenta
36
+ #
37
+ # color.table_view
38
38
  # color.scroll_view
39
- # color.flipside
40
- # color.under_page
41
- # color.light_text
42
- # color.dark_text
39
+ # color.flipside
40
+ # color.under_page
41
+ # color.light_text
42
+ # color.dark_text
43
43
  class Color < UIColor
44
44
 
45
45
  class << self
46
- alias :clear :clearColor
47
- alias :white :whiteColor
48
- alias :light_gray :lightGrayColor
49
- alias :gray :grayColor
50
- alias :dark_gray :darkGrayColor
51
- alias :black :blackColor
52
-
53
- alias :red :redColor
54
- alias :green :greenColor
55
- alias :blue :blueColor
56
- alias :yellow :yellowColor
57
- alias :orange :orangeColor
58
- alias :purple :purpleColor
59
- alias :brown :brownColor
60
- alias :cyan :cyanColor
61
- alias :magenta :magentaColor
62
-
63
- alias :table_view :groupTableViewBackgroundColor
64
- alias :scroll_view :scrollViewTexturedBackgroundColor
65
- alias :flipside :viewFlipsideBackgroundColor
66
- alias :under_page :underPageBackgroundColor
67
- alias :light_text :lightTextColor
68
- alias :dark_text :darkTextColor
46
+ alias :clear :clearColor
47
+ alias :white :whiteColor
48
+ alias :light_gray :lightGrayColor
49
+ alias :gray :grayColor
50
+ alias :dark_gray :darkGrayColor
51
+ alias :black :blackColor
52
+
53
+ alias :red :redColor
54
+ alias :green :greenColor
55
+ alias :blue :blueColor
56
+ alias :yellow :yellowColor
57
+ alias :orange :orangeColor
58
+ alias :purple :purpleColor
59
+ alias :brown :brownColor
60
+ alias :cyan :cyanColor
61
+ alias :magenta :magentaColor
62
+
63
+ alias :table_view :groupTableViewBackgroundColor
64
+ alias :scroll_view :scrollViewTexturedBackgroundColor
65
+ alias :flipside :viewFlipsideBackgroundColor
66
+ alias :under_page :underPageBackgroundColor
67
+ alias :light_text :lightTextColor
68
+ alias :dark_text :darkTextColor
69
69
 
70
70
  # Add your own standard color
71
71
  #
@@ -96,21 +96,21 @@ module RubyMotionQuery
96
96
  # color.from_hex('#ffffff')
97
97
  # color.from_hex('ffffff')
98
98
  def from_hex(hex_color)
99
- hex_color = hex_color.gsub("#", "")
100
- case hex_color.size
99
+ hex_color = hex_color.gsub("#", "")
100
+ case hex_color.size
101
101
  when 3
102
102
  colors = hex_color.scan(%r{[0-9A-Fa-f]}).map{ |el| (el * 2).to_i(16) }
103
103
  when 6
104
- colors = hex_color.scan(%r<[0-9A-Fa-f]{2}>).map{ |el| el.to_i(16) }
104
+ colors = hex_color.scan(%r<[0-9A-Fa-f]{2}>).map{ |el| el.to_i(16) }
105
105
  else
106
106
  raise ArgumentError
107
- end
107
+ end
108
108
  if colors.size == 3
109
109
  from_rgba(colors[0], colors[1], colors[2], 1.0)
110
110
  else
111
111
  raise ArgumentError
112
- end
113
- end
112
+ end
113
+ end
114
114
 
115
115
  # @return [UIColor]
116
116
  #
@@ -134,5 +134,4 @@ module RubyMotionQuery
134
134
  end
135
135
 
136
136
  end
137
-
138
137
  end
@@ -39,7 +39,8 @@ module RubyMotionQuery
39
39
  end
40
40
 
41
41
  def simulator?
42
- @_simulator ||= !(UIDevice.currentDevice.model =~ /simulator/i).nil?
42
+ @_simulator = !(UIDevice.currentDevice.model =~ /simulator/i).nil? if @_simulator.nil?
43
+ @_simulator
43
44
  end
44
45
 
45
46
  def four_inch?
@@ -47,7 +48,7 @@ module RubyMotionQuery
47
48
  @_four_inch
48
49
  end
49
50
 
50
- def retina?()
51
+ def retina?
51
52
  if @_retina.nil?
52
53
  main_screen = Device.screen
53
54
  @_retina = !!(main_screen.respondsToSelector('displayLinkWithTarget:selector:') && main_screen.scale == 2.0)
@@ -52,6 +52,14 @@ module RubyMotionQuery
52
52
  o.rotation = opts[:rotation] if opts.include?(:rotation)
53
53
  o.scale = opts[:scale] if opts.include?(:scale)
54
54
 
55
+ case event
56
+ when :swipe_up then o.direction = UISwipeGestureRecognizerDirectionUp
57
+ when :swipe_down then o.direction = UISwipeGestureRecognizerDirectionDown
58
+ when :swipe_left then o.direction = UISwipeGestureRecognizerDirectionLeft
59
+ when :swipe_right then o.direction = UISwipeGestureRecognizerDirectionRight
60
+ end
61
+
62
+
55
63
  if opts.include?(:init)
56
64
  opts[:init].call(@recognizer)
57
65
  end
@@ -127,6 +135,10 @@ module RubyMotionQuery
127
135
  pinch: UIPinchGestureRecognizer,
128
136
  rotate: UIRotationGestureRecognizer,
129
137
  swipe: UISwipeGestureRecognizer,
138
+ swipe_up: UISwipeGestureRecognizer,
139
+ swipe_down: UISwipeGestureRecognizer,
140
+ swipe_left: UISwipeGestureRecognizer,
141
+ swipe_right: UISwipeGestureRecognizer,
130
142
  pan: UIPanGestureRecognizer,
131
143
  long_press: UILongPressGestureRecognizer
132
144
  }
@@ -45,6 +45,10 @@ module RubyMotionQuery
45
45
  # :pinch
46
46
  # :rotate
47
47
  # :swipe
48
+ # :swipe_up
49
+ # :swipe_down
50
+ # :swipe_left
51
+ # :swipe_right
48
52
  # :pan
49
53
  # :long_press
50
54
 
@@ -7,7 +7,7 @@ module RubyMotionQuery
7
7
  # rmq(my_view).resize(h: 10, w: 100)
8
8
  #
9
9
  # @return [RMQ]
10
- def layout(opts)
10
+ def layout(opts)
11
11
  # TODO, add centered and from_bottom and from_top, and bottom and top
12
12
  # TODO, add animate option
13
13
  left = opts[:left] || opts[:l] || opts[:x]
@@ -28,7 +28,7 @@ module RubyMotionQuery
28
28
  alias :resize :layout
29
29
 
30
30
  # @return [RMQ]
31
- def nudge(opts)
31
+ def nudge(opts)
32
32
  left = opts[:left] || opts[:l] || 0
33
33
  right = opts[:right] || opts[:r] || 0
34
34
  up = opts[:up] || opts[:u] || 0
@@ -61,7 +61,12 @@ module RubyMotionQuery
61
61
 
62
62
  selected.each_with_index do |view, i|
63
63
  st = self.styler_for(view)
64
- next if st.height == 0
64
+
65
+ if type == :vertical
66
+ next if st.height == 0
67
+ else
68
+ next if st.width == 0
69
+ end
65
70
 
66
71
  view_margin = if (margins && margins[i])
67
72
  margins[i]
@@ -69,16 +74,15 @@ module RubyMotionQuery
69
74
  margin
70
75
  end
71
76
 
72
- current_end = (st.top - view_margin) unless current_end
73
-
74
- if type == :horizontal
75
- st.left = current_end + view_margin
76
- current_end = st.right
77
- else
77
+ if type == :vertical
78
+ current_end = (st.top - view_margin) unless current_end
78
79
  st.top = current_end + view_margin
79
80
  current_end = st.bottom
81
+ else
82
+ current_end = (st.left - view_margin) unless current_end
83
+ st.left = current_end + view_margin
84
+ current_end = st.right
80
85
  end
81
-
82
86
  end
83
87
 
84
88
  self
@@ -45,6 +45,19 @@ module RubyMotionQuery
45
45
  @view.setBackgroundImage value, forState: UIControlStateHighlighted
46
46
  end
47
47
 
48
+ # Accepts UIEdgeInsetMake OR and array of values to be the inset.
49
+ # st.title_edge_insets = UIEdgeInsetsMake(0, 10.0, 0, 0)
50
+ # OR
51
+ # st.title_edge_insets = [0, 10.0, 0, 0]
52
+ def title_edge_insets=(value)
53
+ inset = UIEdgeInsetsMake(value[0], value[1], value[2], value[3]) if value.is_a? Array
54
+ @view.setTitleEdgeInsets(inset)
55
+ end
56
+
57
+ def title_edge_insets
58
+ @view.titleEdgeInsets
59
+ end
60
+
48
61
  end
49
62
  end
50
63
  end
@@ -75,6 +75,17 @@ module RubyMotionQuery
75
75
  @view.frame
76
76
  end
77
77
 
78
+ # Sets the frame using the Window's coordinates
79
+ def absolute_frame=(value)
80
+ self.frame = value
81
+
82
+ f = @view.frame
83
+ window_point = @view.convertPoint(f.origin, fromView: nil)
84
+ f.origin.x += window_point.x
85
+ f.origin.y += window_point.y
86
+ @view.frame = f
87
+ end
88
+
78
89
  def padded=(value)
79
90
  if value.is_a?(Hash)
80
91
  h = value
@@ -2,12 +2,20 @@
2
2
  module RubyMotionQuery
3
3
  class RMQ
4
4
 
5
+ # Removes the selected views from their parent's (superview) subview array
6
+ #
7
+ # @example
8
+ # rmq(a_view, another_view).remove
9
+ #
5
10
  # @return [RMQ]
6
11
  def remove
7
12
  selected.each { |view| view.removeFromSuperview }
8
13
  self
9
14
  end
10
15
 
16
+ # This is used by build, create, and append. You really shouldn't use it
17
+ # directly. Although it's totally fine if you do
18
+ #
11
19
  # @return [RMQ]
12
20
  def add_subview(view_or_constant, opts={})
13
21
  subviews_added = []
@@ -41,28 +49,60 @@ module RubyMotionQuery
41
49
  appended = true
42
50
  end
43
51
 
44
- if self.stylesheet
45
- apply_style_to_view(new_view, style) if style
46
- end
47
-
48
52
  if created
49
53
  new_view.rmq_did_create(self.wrap(new_view))
50
54
  new_view.rmq_created
51
55
  end
52
56
  new_view.rmq_build
53
57
  new_view.rmq_appended if appended
58
+
59
+ if self.stylesheet
60
+ apply_style_to_view(new_view, style) if style
61
+ end
54
62
  end
55
63
 
56
64
  RMQ.create_with_array_and_selectors(subviews_added, selectors, @context, self)
57
65
  end
58
66
  alias :insert :add_subview
59
67
 
68
+ # Performs a create, then appends view to the end of the subview array of the
69
+ # views you have selected (or the rootview if you have nothing selected).
70
+ #
71
+ # When you build, create, or append a view, the method rmq_build is called
72
+ # inside the view. If you are creating a your own subclass of a UIView, then
73
+ # that is a good place to do your initialization. Your view is created, then
74
+ # appended, then rmq_build is called, then the style is applied (if it exists)
75
+ #
76
+ # @example
77
+ # # Creating a new view instance then append it. Passing in the class
78
+ # # to create
79
+ # rmq.append(UIButton, :my_button_style)
80
+ # @title = rmq.append(ULabel, :title).get
81
+ #
82
+ # # You can also pass in an existing view
83
+ # my_view = UIView.alloc.initWithFrame([[0,0],[10,10]])
84
+ # rmq.append(my_view, :my_style)
85
+ #
86
+ # # Stylename is optional
87
+ # rmq.append(UIImageView)
88
+ #
60
89
  # @return [RMQ]
61
90
  def append(view_or_constant, style=nil, opts = {})
62
91
  opts[:style] = style
63
92
  add_subview(view_or_constant, opts)
64
93
  end
65
94
 
95
+ # Same as append, but instantly returns the view, without having to use .get
96
+ #
97
+ # @example
98
+ # @my_button = rmq.append! UIButton
99
+ # @my_label = rmq.append!(UILabel, :my_label)
100
+ def append!(view_or_constant, style=nil, opts = {})
101
+ append(view_or_constant, style, opts).get
102
+ end
103
+
104
+ # Just like append, but inserts the view at index 0 of the subview array
105
+ #
66
106
  # @return [RMQ]
67
107
  def unshift(view_or_constant, style=nil, opts = {})
68
108
  opts[:at_index] = 0
@@ -71,9 +111,20 @@ module RubyMotionQuery
71
111
  end
72
112
  alias :prepend :unshift
73
113
 
114
+ # Same as prepend, but instantly returns the view, without having to use .get
115
+ #
116
+ # @example
117
+ # @my_button = rmq.prepend! UIButton
118
+ # @my_label = rmq.prepend!(UILabel, :my_label)
119
+ def unshift!(view_or_constant, style=nil, opts = {})
120
+ unshift(view_or_constant, style, opts).get
121
+ end
122
+ alias :prepend! :unshift!
123
+
74
124
  # Creates a view then returns an rmq with that view in it. It does not add that
75
- # view to the view tree. This is useful for stuff like creating table cells. You
76
- # can use the rmq_did_create method, just like you do when you append a subview
125
+ # view to the view tree (append does this). This is useful for stuff like creating
126
+ # table cells. You can use the rmq_did_create method, just like you do when you
127
+ # append a subview
77
128
  #
78
129
  # @return [RMQ] wrapping the view that was just create
79
130
  #
@@ -97,6 +148,14 @@ module RubyMotionQuery
97
148
  add_subview view_or_constant, opts
98
149
  end
99
150
 
151
+ # Same as create, but instantly returns the view, without having to use .get
152
+ #
153
+ # @example
154
+ # @my_button = rmq.create! UIButton
155
+ def create!(view_or_constant, style=nil, opts = {})
156
+ create(view_or_constant, style, opts).get
157
+ end
158
+
100
159
  # Build a view, similar to create and append, but only inits an existing view. Usefull
101
160
  # in collectionview cells for example
102
161
  #
@@ -50,41 +50,38 @@ module RubyMotionQuery
50
50
  end
51
51
  end
52
52
 
53
- # @deprecated this is no longer needed in RubyMotion >= 2.19. In a later version this will be
54
- # changed to simply be a wrapper of RubyMotion's WeakRef
55
- #
56
- #
57
53
  # Creates a weak reference to an object. Unlike WeakRef.new provided by RubyMotion, this will
58
54
  # not wrap a weak ref inside another weak ref (which causes bugs).
59
55
  #
60
- # This is fairly performant. It's about twice as slow as WeakRef.new. However, you can
61
- # create a million weak refs in about 651 miliseconds, compared to 319 for WeakRef.new
62
- #
63
56
  # Creating a WeakRef with a literal like a string will cause your app to crash
64
57
  # instantly, it's fun, try it. Only create weak refs of variables
65
58
  #
66
59
  # @example
67
60
  # foo = RubyMotionQuery::RMQ.weak_ref(bar)
68
61
  def weak_ref(o)
69
- weak = WeakRef.new(weak_ref_to_strong_ref(o))
70
- #WeakRef.new(o) # For future release
62
+ if is_object_weak_ref?(o)
63
+ o
64
+ else
65
+ WeakRef.new(o)
66
+ end
67
+ end
68
+
69
+ # Gets a strong reference from a weak reference
70
+ def weak_ref_to_strong_ref(weak_ref)
71
+ weak_ref.tap{} # This is a hack but it works, is there a better way?
72
+ end
73
+
74
+ # Is an object a weak_ref
75
+ def is_object_weak_ref?(o)
76
+ o.respond_to?(:weakref_alive?) # This is the only way to do this currently
71
77
  end
72
78
 
73
79
  # @deprecated this has been fixed in RubyMotion 2.17, so this method is no longer needed.
74
- #
75
- # This gets around a bug in RubyMotion
76
- # Hopefully I can remove this quickly. Only use this for complex objects that have no comparison
77
- # other than that they are the exact same object. For example, strings compare their contents.
78
80
  def weak_ref_is_same_object?(a, b)
79
- (a.class == b.class) && (a.object_id == b.object_id)
80
- #a == b # For future release
81
- end
81
+ # This was the workaround that isn't needed anymore, for your reference:
82
+ #(a.class == b.class) && (a.object_id == b.object_id)
82
83
 
83
- # @deprecated, this has been fixed in RubyMotion 2.24, so this method is no longer needed.
84
- # Gets a strong reference from a weak reference
85
- def weak_ref_to_strong_ref(weak_ref)
86
- # This is a hack but it works, is there a better way?
87
- weak_ref.tap{}
84
+ a == b
88
85
  end
89
86
 
90
87
  # Mainly used for console and logging
@@ -1,5 +1,5 @@
1
1
  module RubyMotionQuery
2
- VERSION = "0.5.7"
2
+ VERSION = "0.5.8"
3
3
 
4
4
  class RMQ
5
5
  def version
@@ -7,9 +7,9 @@ class <%= @name_camel_case %>Controller < UICollectionViewController
7
7
  # @window.rootViewController = UINavigationController.alloc.initWithRootViewController(main_controller)
8
8
 
9
9
  <%= @name.upcase %>_CELL_ID = "<%= @name_camel_case %>Cell"
10
-
10
+
11
11
  def self.new(args = {})
12
- # Set layout
12
+ # Set layout
13
13
  layout = UICollectionViewFlowLayout.alloc.init
14
14
  self.alloc.initWithCollectionViewLayout(layout)
15
15
  end
@@ -42,11 +42,11 @@ class <%= @name_camel_case %>Controller < UICollectionViewController
42
42
  def numberOfSectionsInCollectionView(view)
43
43
  1
44
44
  end
45
-
45
+
46
46
  def collectionView(view, numberOfItemsInSection: section)
47
- 200
47
+ 200
48
48
  end
49
-
49
+
50
50
  def collectionView(view, cellForItemAtIndexPath: index_path)
51
51
  view.dequeueReusableCellWithReuseIdentifier(<%= @name.upcase %>_CELL_ID, forIndexPath: index_path).tap do |cell|
52
52
  rmq.build(cell) unless cell.reused
@@ -64,8 +64,8 @@ end
64
64
 
65
65
  __END__
66
66
 
67
- # You don't have to reapply styles to all UIViews, if you want to optimize,
68
- # another way to do it is tag the views you need to restyle in your stylesheet,
67
+ # You don't have to reapply styles to all UIViews, if you want to optimize,
68
+ # another way to do it is tag the views you need to restyle in your stylesheet,
69
69
  # then only reapply the tagged views, like so:
70
70
  def logo(st)
71
71
  st.frame = {t: 10, w: 200, h: 96}
@@ -17,9 +17,9 @@ class <%= @name_camel_case %>ControllerStylesheet < ApplicationStylesheet
17
17
  cl.itemSize = [cell_size[:w], cell_size[:h]]
18
18
  #cl.scrollDirection = UICollectionViewScrollDirectionHorizontal
19
19
  #cl.headerReferenceSize = [cell_size[:w], cell_size[:h]]
20
- cl.minimumInteritemSpacing = @margin
21
- cl.minimumLineSpacing = @margin
22
- #cl.sectionInsert = [0,0,0,0]
20
+ cl.minimumInteritemSpacing = @margin
21
+ cl.minimumLineSpacing = @margin
22
+ #cl.sectionInset = [0,0,0,0]
23
23
  end
24
24
  end
25
25
  end
@@ -1,13 +1,12 @@
1
- class <%= @name_camel_case %>Cell < UICollectionViewCell
1
+ class <%= @name_camel_case %>Cell < UICollectionViewCell
2
2
  attr_reader :reused
3
3
 
4
4
  def rmq_build
5
5
  rmq(self).apply_style :<%= @name %>_cell
6
6
 
7
- rmq(self.contentView).tap do |q|
8
- # Add your subviews, init stuff here
9
- # @foo = q.append(UILabel, :foo).get
10
- end
7
+ q = rmq(self.contentView)
8
+ # Add your subviews, init stuff here
9
+ # @foo = q.append(UILabel, :foo).get
11
10
  end
12
11
 
13
12
  def prepareForReuse
@@ -23,8 +23,8 @@ end
23
23
 
24
24
  __END__
25
25
 
26
- # You don't have to reapply styles to all UIViews, if you want to optimize,
27
- # another way to do it is tag the views you need to restyle in your stylesheet,
26
+ # You don't have to reapply styles to all UIViews, if you want to optimize,
27
+ # another way to do it is tag the views you need to restyle in your stylesheet,
28
28
  # then only reapply the tagged views, like so:
29
29
  def logo(st)
30
30
  st.frame = {t: 10, w: 200, h: 96}
@@ -1,12 +1,12 @@
1
- class <%= @name_camel_case %>Cell < UITableViewCell
1
+ class <%= @name_camel_case %>Cell < UITableViewCell
2
2
 
3
3
  def rmq_build
4
4
  q = rmq(self.contentView)
5
5
 
6
6
  # Add your subviews, init stuff here
7
7
  # @foo = q.append(UILabel, :foo).get
8
-
9
- # Or use the built-in table cell controls, if you don't use
8
+
9
+ # Or use the built-in table cell controls, if you don't use
10
10
  # these, they won't exist at runtime
11
11
  # q.build(self.imageView, :cell_image)
12
12
  # q.build(self.detailTextLabel, :cell_label_detail)
@@ -1,23 +1,24 @@
1
1
  class <%= @name_camel_case %> < UIView
2
2
 
3
3
  def rmq_build
4
-
5
- rmq.apply_style :<%= @name %>
4
+ q = rmq(self)
5
+ q.apply_style :<%= @name %>
6
6
 
7
7
  # Add subviews here, like so:
8
- #rmq.append(UILabel, :some_label)
9
-
8
+ # q.append(UILabel, :some_label)
9
+ # -or-
10
+ # @submit_button = q.append(UIButon, :submit).get
10
11
  end
11
12
 
12
13
  end
13
14
 
14
15
 
15
- # To style this view include its stylesheet at the top of each controller's
16
+ # To style this view include its stylesheet at the top of each controller's
16
17
  # stylesheet that is going to use it:
17
- # class SomeStylesheet < ApplicationStylesheet
18
+ # class SomeStylesheet < ApplicationStylesheet
18
19
  # include <%= @name_camel_case %>Stylesheet
19
20
 
20
21
  # Another option is to use your controller's stylesheet to style this view. This
21
- # works well if only one controller uses it. If you do that, delete the
22
+ # works well if only one controller uses it. If you do that, delete the
22
23
  # view's stylesheet with:
23
24
  # rm app/stylesheets/views/<%= @name %>.rb
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: 0.5.7
4
+ version: 0.5.8
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: 2014-04-26 00:00:00.000000000 Z
12
+ date: 2014-05-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bacon