ruby_motion_query 0.4.1 → 0.5.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 +8 -8
- data/README.md +82 -43
- data/motion/ext.rb +30 -38
- data/motion/ruby_motion_query/actions.rb +20 -0
- data/motion/ruby_motion_query/animations.rb +38 -31
- data/motion/ruby_motion_query/app.rb +21 -1
- data/motion/ruby_motion_query/base.rb +27 -15
- data/motion/ruby_motion_query/data.rb +11 -1
- data/motion/ruby_motion_query/debug.rb +92 -0
- data/motion/ruby_motion_query/factory.rb +28 -17
- data/motion/ruby_motion_query/image.rb +5 -5
- data/motion/ruby_motion_query/position.rb +52 -0
- data/motion/ruby_motion_query/selectors.rb +0 -1
- data/motion/ruby_motion_query/stylers/ui_label_styler.rb +10 -10
- data/motion/ruby_motion_query/stylers/ui_view_styler.rb +25 -16
- data/motion/ruby_motion_query/stylesheet.rb +32 -5
- data/motion/ruby_motion_query/subviews.rb +30 -1
- data/motion/ruby_motion_query/traverse.rb +61 -13
- data/motion/ruby_motion_query/utils.rb +54 -11
- data/motion/ruby_motion_query/version.rb +7 -1
- data/templates/collection_view_controller/app/controllers/name_controller.rb +1 -1
- data/templates/collection_view_controller/app/stylesheets/name_cell_stylesheet.rb +1 -1
- data/templates/collection_view_controller/app/stylesheets/name_controller_stylesheet.rb +2 -3
- data/templates/collection_view_controller/app/views/name_cell.rb +8 -8
- data/templates/controller/app/stylesheets/name_controller_stylesheet.rb +2 -0
- data/templates/view/app/views/name.rb +4 -6
- metadata +3 -2
@@ -1,12 +1,11 @@
|
|
1
1
|
module RubyMotionQuery
|
2
2
|
class RMQ
|
3
|
-
|
4
3
|
class << self
|
5
4
|
# @return [Boolean]
|
6
5
|
def is_class?(o)
|
7
6
|
# This line fails in spec, causes exit without message. It works fine in production
|
8
7
|
#(o.class == Class) && (defined?(o) == 'constant')
|
9
|
-
|
8
|
+
|
10
9
|
# So I'm doing this instead
|
11
10
|
!!(o.respond_to?(:name) && o.name.to_s[0] =~ /[A-Z]/)
|
12
11
|
end
|
@@ -24,19 +23,63 @@ module RubyMotionQuery
|
|
24
23
|
end
|
25
24
|
|
26
25
|
# @param view
|
27
|
-
# @return [UIViewController] The controller the view it is sitting in, or nil if it's not sitting anywhere in particular
|
26
|
+
# @return [UIViewController] The controller the view it is sitting in, or nil if it's not sitting anywhere in particular
|
28
27
|
def controller_for_view(view)
|
29
|
-
#
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
28
|
+
#debug.assert(view.nil? || view.is_a?(UIView), 'Invalid view in controller for view', {view: view})
|
29
|
+
|
30
|
+
if view && (vc = view.rmq_data.view_controller)
|
31
|
+
vc
|
32
|
+
else
|
33
|
+
# Non-recursive for speed
|
34
|
+
while view
|
35
|
+
view = view.nextResponder
|
36
|
+
if view.is_a?(UIViewController)
|
37
|
+
break
|
38
|
+
elsif view.is_a?(UIView)
|
39
|
+
if vc = view.rmq_data.view_controller
|
40
|
+
view = vc
|
41
|
+
break
|
42
|
+
end
|
43
|
+
else
|
44
|
+
view = nil
|
45
|
+
end
|
36
46
|
end
|
47
|
+
|
48
|
+
view
|
49
|
+
|
37
50
|
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# @deprecated this has been fixed in 2.17, so this method is no longer needed.
|
54
|
+
#
|
55
|
+
# Creates a weak reference to an object. Unlike WeakRef.new provided by RubyMotion, this will
|
56
|
+
# not wrap a weak ref inside another weak ref (which causes bugs).
|
57
|
+
#
|
58
|
+
# This is fairly performant. It's about twice as slow as WeakRef.new. However, you can
|
59
|
+
# create a million weak refs in about 651 miliseconds, compared to 319 for WeakRef.new
|
60
|
+
#
|
61
|
+
# Creating a WeakRef with a literal like a string will cause your app to crash
|
62
|
+
# instantly, it's fun, try it. Only create weak refs of variables
|
63
|
+
#
|
64
|
+
# @example
|
65
|
+
# foo = RubyMotionQuery::RMQ.weak_ref(bar)
|
66
|
+
def weak_ref(o)
|
67
|
+
weak = WeakRef.new(weak_ref_to_strong_ref(o))
|
68
|
+
end
|
69
|
+
|
70
|
+
# @deprecated this has been fixed in 2.17, so this method is no longer needed.
|
71
|
+
#
|
72
|
+
# This gets around a bug in RubyMotion
|
73
|
+
# Hopefully I can remove this quickly. Only use this for complex objects that have no comparison
|
74
|
+
# other than that they are the exact same object. For example, strings compare their contents.
|
75
|
+
def weak_ref_is_same_object?(a, b)
|
76
|
+
(a.class == b.class) && (a.object_id == b.object_id)
|
77
|
+
end
|
38
78
|
|
39
|
-
|
79
|
+
# Gets a strong reference from a weak reference
|
80
|
+
def weak_ref_to_strong_ref(weak_ref)
|
81
|
+
# This is a hack but it works, is there a better way?
|
82
|
+
weak_ref.tap{}
|
40
83
|
end
|
41
84
|
|
42
85
|
# Mainly used for console and logging
|
@@ -49,7 +49,7 @@ class <%= @name_camel_case %>Controller < UICollectionViewController
|
|
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
|
53
53
|
|
54
54
|
# Update cell's data here
|
55
55
|
end
|
@@ -14,12 +14,11 @@ class <%= @name_camel_case %>ControllerStylesheet < ApplicationStylesheet
|
|
14
14
|
st.background_color = color.white
|
15
15
|
|
16
16
|
st.view.collectionViewLayout.tap do |cl|
|
17
|
-
cl.itemSize = cell_size
|
17
|
+
cl.itemSize = [cell_size[:w], cell_size[:h]]
|
18
18
|
#cl.scrollDirection = UICollectionViewScrollDirectionHorizontal
|
19
|
-
#cl.headerReferenceSize = cell_size
|
19
|
+
#cl.headerReferenceSize = [cell_size[:w], cell_size[:h]]
|
20
20
|
cl.minimumInteritemSpacing = @margin
|
21
21
|
cl.minimumLineSpacing = @margin
|
22
|
-
#cl.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight,
|
23
22
|
#cl.sectionInsert = [0,0,0,0]
|
24
23
|
end
|
25
24
|
end
|
@@ -1,17 +1,17 @@
|
|
1
1
|
class <%= @name_camel_case %>Cell < UICollectionViewCell
|
2
|
-
|
3
|
-
unless @initialized
|
4
|
-
@initialized = true
|
2
|
+
attr_reader :reused
|
5
3
|
|
6
|
-
|
7
|
-
|
4
|
+
def rmq_build
|
5
|
+
rmq(self).apply_style :<%= @name %>_cell
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
rmq(self.contentView).tap do |q|
|
8
|
+
# Add your subviews, init stuff here
|
9
|
+
# @foo = q.append(UILabel, :foo).get
|
12
10
|
end
|
13
11
|
end
|
14
12
|
|
15
13
|
def prepareForReuse
|
14
|
+
@reused = true
|
16
15
|
end
|
16
|
+
|
17
17
|
end
|
@@ -1,13 +1,11 @@
|
|
1
1
|
class <%= @name_camel_case %> < UIView
|
2
2
|
|
3
|
-
def
|
3
|
+
def rmq_build
|
4
4
|
|
5
|
-
|
6
|
-
q.apply_style :<%= @name %>
|
5
|
+
rmq.apply_style :<%= @name %>
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
end
|
7
|
+
# Add subviews here, like so:
|
8
|
+
#rmq.append(UILabel, :some_label)
|
11
9
|
|
12
10
|
end
|
13
11
|
|
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.
|
4
|
+
version: 0.5.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: 2013-
|
12
|
+
date: 2013-12-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bacon
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- motion/ruby_motion_query/base.rb
|
58
58
|
- motion/ruby_motion_query/color.rb
|
59
59
|
- motion/ruby_motion_query/data.rb
|
60
|
+
- motion/ruby_motion_query/debug.rb
|
60
61
|
- motion/ruby_motion_query/device.rb
|
61
62
|
- motion/ruby_motion_query/enumerablish.rb
|
62
63
|
- motion/ruby_motion_query/event.rb
|