Skip to content

Commit d5be4c1

Browse files
committed
Updated UICollectionView template
1 parent 29f7cc1 commit d5be4c1

File tree

7 files changed

+30
-19
lines changed

7 files changed

+30
-19
lines changed

Gemfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
ruby_motion_query (0.4.1b)
4+
ruby_motion_query (0.4.1)
55

66
GEM
77
remote: https://rubygems.org/

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ A fast, muggle, nonpolluting, jQuery-like library for [RubyMotion](http://rubymo
2626

2727
----------
2828

29-
**Tested only on iOS only, not OS X (nor is there any OS X specific code)**
29+
**Tested on iOS, not OS X (nor is there any OS X specific code)**
3030

3131
----------
3232

@@ -183,6 +183,8 @@ Here are the commands available to you:
183183
> rmq create shared some_class_used_app_wide
184184
> rmq create lib some_class_used_by_multiple_apps
185185
186+
> rmq create collection_view_controller foos
187+
186188
# To test the create command without actually creating any files, do:
187189
> rmq create view my_view dry_run
188190
@@ -1116,6 +1118,7 @@ Future features that I plan on adding
11161118
- add borders to UIView styler: st.borders = {l: {w: 2, color: color.black}, r: {w: 2, color: color.black}}
11171119
- add templates for: nav controller, tab controller, table controller, collection controller
11181120
- add from_right, from_bottom, and centered to both st.frame and to move
1121+
- add binding that combines KVO and events to bind an attribute of one object to the attribute of selected view(s), keeping both in sync, like so: rmq.append(UITextField).bind(@person, attr: :name, to: :text)
11191122

11201123

11211124
## Contact

motion/ruby_motion_query/stylers/ui_view_styler.rb

+7
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,13 @@ def rotation=(new_angle)
250250
@view.transform = CGAffineTransformMakeRotation(radians)
251251
end
252252

253+
def content_mode=(value)
254+
@view.contentMode = value
255+
end
256+
def content_mode
257+
@view.contentMode
258+
end
259+
253260
end
254261
end
255262
end

templates/collection_view_controller/app/controllers/name_controller.rb

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
class <%= @name_camel_case %>Controller < UICollectionViewController
2-
# In app_delegate.rb or wherever you use this controller, just call #new like so:
3-
# @window.rootViewController = <%= @name_camel_case %>Controller.new
2+
# In app_delegate.rb or wherever you use this controller, just call .new like so:
3+
# @window.rootViewController = <%= @name_camel_case %>Controller.new
4+
#
5+
# Or if you're adding using it in a navigation controller, do this
6+
# main_controller = <%= @name_camel_case %>Controller.new
7+
# @window.rootViewController = UINavigationController.alloc.initWithRootViewController(main_controller)
48

9+
<%= @name.upcase %>_CELL_ID = "<%= @name_camel_case %>Cell"
10+
511
def self.new(args = {})
612
# Set layout
713
layout = UICollectionViewFlowLayout.alloc.init
@@ -14,7 +20,7 @@ def viewDidLoad
1420
rmq.stylesheet = <%= @name_camel_case %>ControllerStylesheet
1521
1622
collectionView.tap do |cv|
17-
cv.registerClass(<%= @name_camel_case %>Cell, forCellWithReuseIdentifier: <%= @name_camel_case %>Cell.name)
23+
cv.registerClass(<%= @name_camel_case %>Cell, forCellWithReuseIdentifier: <%= @name.upcase %>_CELL_ID)
1824
cv.delegate = self
1925
cv.dataSource = self
2026
cv.allowsSelection = true
@@ -30,27 +36,28 @@ def supportedInterfaceOrientations
3036
3137
# Remove if you are only supporting portrait
3238
def willAnimateRotationToInterfaceOrientation(orientation, duration: duration)
33-
rmq.all.reapply_styles
39+
rmq(:reapply_style).reapply_styles
3440
end
3541
3642
def numberOfSectionsInCollectionView(view)
3743
1
3844
end
3945
4046
def collectionView(view, numberOfItemsInSection: section)
41-
40
47+
200
4248
end
4349
4450
def collectionView(view, cellForItemAtIndexPath: index_path)
45-
view.dequeueReusableCellWithReuseIdentifier(<%= @name_camel_case %>Cell.name, forIndexPath: index_path).tap do |cell|
51+
view.dequeueReusableCellWithReuseIdentifier(<%= @name.upcase %>_CELL_ID, forIndexPath: index_path).tap do |cell|
4652
cell.setup_with(rmq)
4753
4854
# Update cell's data here
4955
end
5056
end
5157
5258
def collectionView(view, didSelectItemAtIndexPath: index_path)
53-
cell = collectionView.cellForItemAtIndexPath(index_path)
59+
cell = view.cellForItemAtIndexPath(index_path)
60+
puts "Selected at section: #{index_path.section}, row: #{index_path.row}"
5461
end
5562

5663
end

templates/collection_view_controller/app/stylesheets/name_controller_stylesheet.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ def setup
1010
end
1111

1212
def collection_view(st)
13-
st.frame = :full
1413
st.view.contentInset = [@margin, @margin, @margin, @margin]
1514
st.background_color = color.white
1615

1716
st.view.collectionViewLayout.tap do |cl|
1817
cl.itemSize = cell_size
18+
#cl.scrollDirection = UICollectionViewScrollDirectionHorizontal
1919
#cl.headerReferenceSize = cell_size
2020
cl.minimumInteritemSpacing = @margin
2121
cl.minimumLineSpacing = @margin
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
11
class <%= @name_camel_case %>Cell < UICollectionViewCell
22
def setup_with(controller_rmq)
33
unless @initialized
4+
@initialized = true
5+
46
controller_rmq.wrap(self).tap do |q|
57
q.apply_style :<%= @name %>_cell
68

79
# Add your subviews, init stuff here
810
# @foo = q.append(UILabel, :foo).get
911
end
10-
11-
@initialized = true
1212
end
1313
end
1414

1515
def prepareForReuse
1616
end
17-
18-
def select
19-
end
20-
21-
def deselect
22-
end
2317
end

templates/view/app/views/name.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def rmq_did_create(self_in_rmq)
1717
# To style this view include its stylesheet at the top of each controller's
1818
# stylesheet that is going to use it:
1919
# class SomeStylesheet < ApplicationStylesheet
20-
# include <%= @stylesheet_name %>
20+
# include <%= @name_camel_case %>Stylesheet
2121

2222
# Another option is to use your controller's stylesheet to style this view. This
2323
# works well if only one controller uses it. If you do that, delete the

0 commit comments

Comments
 (0)