From d5be4c183fa777d00aacc2a250d46e391daaa3de Mon Sep 17 00:00:00 2001 From: Todd Werth Date: Tue, 22 Oct 2013 11:38:15 -0700 Subject: [PATCH] Updated UICollectionView template --- Gemfile.lock | 2 +- README.md | 5 ++++- .../stylers/ui_view_styler.rb | 7 +++++++ .../app/controllers/name_controller.rb | 21 ++++++++++++------- .../stylesheets/name_controller_stylesheet.rb | 2 +- .../app/views/name_cell.rb | 10 ++------- templates/view/app/views/name.rb | 2 +- 7 files changed, 30 insertions(+), 19 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index aa2205e..c304941 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - ruby_motion_query (0.4.1b) + ruby_motion_query (0.4.1) GEM remote: https://rubygems.org/ diff --git a/README.md b/README.md index 39ff146..2bdde36 100755 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ A fast, muggle, nonpolluting, jQuery-like library for [RubyMotion](http://rubymo ---------- -**Tested only on iOS only, not OS X (nor is there any OS X specific code)** +**Tested on iOS, not OS X (nor is there any OS X specific code)** ---------- @@ -183,6 +183,8 @@ Here are the commands available to you: > rmq create shared some_class_used_app_wide > rmq create lib some_class_used_by_multiple_apps + > rmq create collection_view_controller foos + # To test the create command without actually creating any files, do: > rmq create view my_view dry_run @@ -1116,6 +1118,7 @@ Future features that I plan on adding - add borders to UIView styler: st.borders = {l: {w: 2, color: color.black}, r: {w: 2, color: color.black}} - add templates for: nav controller, tab controller, table controller, collection controller - add from_right, from_bottom, and centered to both st.frame and to move +- 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) ## Contact diff --git a/motion/ruby_motion_query/stylers/ui_view_styler.rb b/motion/ruby_motion_query/stylers/ui_view_styler.rb index 73ea92a..ad9005a 100644 --- a/motion/ruby_motion_query/stylers/ui_view_styler.rb +++ b/motion/ruby_motion_query/stylers/ui_view_styler.rb @@ -250,6 +250,13 @@ module RubyMotionQuery @view.transform = CGAffineTransformMakeRotation(radians) end + def content_mode=(value) + @view.contentMode = value + end + def content_mode + @view.contentMode + end + end end end diff --git a/templates/collection_view_controller/app/controllers/name_controller.rb b/templates/collection_view_controller/app/controllers/name_controller.rb index 63d3b5c..c327e15 100644 --- a/templates/collection_view_controller/app/controllers/name_controller.rb +++ b/templates/collection_view_controller/app/controllers/name_controller.rb @@ -1,7 +1,13 @@ class <%= @name_camel_case %>Controller < UICollectionViewController - # In app_delegate.rb or wherever you use this controller, just call #new like so: - # @window.rootViewController = <%= @name_camel_case %>Controller.new + # In app_delegate.rb or wherever you use this controller, just call .new like so: + # @window.rootViewController = <%= @name_camel_case %>Controller.new + # + # Or if you're adding using it in a navigation controller, do this + # main_controller = <%= @name_camel_case %>Controller.new + # @window.rootViewController = UINavigationController.alloc.initWithRootViewController(main_controller) + <%= @name.upcase %>_CELL_ID = "<%= @name_camel_case %>Cell" + def self.new(args = {}) # Set layout layout = UICollectionViewFlowLayout.alloc.init @@ -14,7 +20,7 @@ class <%= @name_camel_case %>Controller < UICollectionViewController rmq.stylesheet = <%= @name_camel_case %>ControllerStylesheet collectionView.tap do |cv| - cv.registerClass(<%= @name_camel_case %>Cell, forCellWithReuseIdentifier: <%= @name_camel_case %>Cell.name) + cv.registerClass(<%= @name_camel_case %>Cell, forCellWithReuseIdentifier: <%= @name.upcase %>_CELL_ID) cv.delegate = self cv.dataSource = self cv.allowsSelection = true @@ -30,7 +36,7 @@ class <%= @name_camel_case %>Controller < UICollectionViewController # Remove if you are only supporting portrait def willAnimateRotationToInterfaceOrientation(orientation, duration: duration) - rmq.all.reapply_styles + rmq(:reapply_style).reapply_styles end def numberOfSectionsInCollectionView(view) @@ -38,11 +44,11 @@ class <%= @name_camel_case %>Controller < UICollectionViewController end def collectionView(view, numberOfItemsInSection: section) - 40 + 200 end def collectionView(view, cellForItemAtIndexPath: index_path) - view.dequeueReusableCellWithReuseIdentifier(<%= @name_camel_case %>Cell.name, forIndexPath: index_path).tap do |cell| + view.dequeueReusableCellWithReuseIdentifier(<%= @name.upcase %>_CELL_ID, forIndexPath: index_path).tap do |cell| cell.setup_with(rmq) # Update cell's data here @@ -50,7 +56,8 @@ class <%= @name_camel_case %>Controller < UICollectionViewController end def collectionView(view, didSelectItemAtIndexPath: index_path) - cell = collectionView.cellForItemAtIndexPath(index_path) + cell = view.cellForItemAtIndexPath(index_path) + puts "Selected at section: #{index_path.section}, row: #{index_path.row}" end end diff --git a/templates/collection_view_controller/app/stylesheets/name_controller_stylesheet.rb b/templates/collection_view_controller/app/stylesheets/name_controller_stylesheet.rb index 3b97a82..a3d1739 100644 --- a/templates/collection_view_controller/app/stylesheets/name_controller_stylesheet.rb +++ b/templates/collection_view_controller/app/stylesheets/name_controller_stylesheet.rb @@ -10,12 +10,12 @@ class <%= @name_camel_case %>ControllerStylesheet < ApplicationStylesheet end def collection_view(st) - st.frame = :full st.view.contentInset = [@margin, @margin, @margin, @margin] st.background_color = color.white st.view.collectionViewLayout.tap do |cl| cl.itemSize = cell_size + #cl.scrollDirection = UICollectionViewScrollDirectionHorizontal #cl.headerReferenceSize = cell_size cl.minimumInteritemSpacing = @margin cl.minimumLineSpacing = @margin diff --git a/templates/collection_view_controller/app/views/name_cell.rb b/templates/collection_view_controller/app/views/name_cell.rb index 2e1427d..30879a8 100644 --- a/templates/collection_view_controller/app/views/name_cell.rb +++ b/templates/collection_view_controller/app/views/name_cell.rb @@ -1,23 +1,17 @@ class <%= @name_camel_case %>Cell < UICollectionViewCell def setup_with(controller_rmq) unless @initialized + @initialized = true + controller_rmq.wrap(self).tap do |q| q.apply_style :<%= @name %>_cell # Add your subviews, init stuff here # @foo = q.append(UILabel, :foo).get end - - @initialized = true end end def prepareForReuse end - - def select - end - - def deselect - end end diff --git a/templates/view/app/views/name.rb b/templates/view/app/views/name.rb index 852bacf..770029d 100644 --- a/templates/view/app/views/name.rb +++ b/templates/view/app/views/name.rb @@ -17,7 +17,7 @@ end # To style this view include its stylesheet at the top of each controller's # stylesheet that is going to use it: # class SomeStylesheet < ApplicationStylesheet -# include <%= @stylesheet_name %> +# include <%= @name_camel_case %>Stylesheet # Another option is to use your controller's stylesheet to style this view. This # works well if only one controller uses it. If you do that, delete the