Module: MotionPrime::Layout
- Included in:
- Screen
- Defined in:
- motion-prime/views/layout.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_view(klass, options = {}, &block) ⇒ Object
- #set_options_for(view, options = {}, &block) ⇒ Object (also: #update_options_for)
- #setup(view, options = {}, &block) ⇒ Object
- #view_stack ⇒ Object
Class Method Details
.included(base) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'motion-prime/views/layout.rb', line 51 def self.included base base.class_eval do [::UIActionSheet, ::UIActivityIndicatorView, ::MPButton, ::UIDatePicker, ::UIImageView, ::MPLabel, ::UIPageControl, ::UIPickerView, ::UIProgressView, ::UIScrollView, ::UISearchBar, ::UISegmentedControl, ::UISlider, ::UIStepper, ::UISwitch, ::UITabBar, ::UICollectionView, ::UITableView, ::UITableViewCell, ::MPTextField, ::MPTextView, ::UIToolbar, ::UIWebView, ::UINavigationBar, ::UIPageViewController, ::MPTableCellWithSection, ::MPCollectionCellWithSection, ::MBProgressHUD, ::MPSpinner].each do |klass| shorthand = "#{klass}"[2..-1].underscore.to_sym define_method(shorthand) do |, &block| [:screen] = self element = MotionPrime::BaseElement.factory(shorthand, ) element.render({}, &block) element end end end end |
Instance Method Details
#add_view(klass, options = {}, &block) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'motion-prime/views/layout.rb', line 11 def add_view(klass, = {}, &block) = .clone render_target = .delete(:render_target) parent_view = .delete(:parent_view) || render_target parent_bounds = if view_stack.empty? parent_view.try(:bounds) || CGRectZero else view_stack.last.bounds end builder = ViewBuilder.new(klass, .merge(parent_bounds: parent_bounds)) = builder..merge(calculate_frame: .fetch(:calculate_frame, true), parent_bounds: parent_bounds) view = builder.view insert_index = .delete(:at_index) (view, , &block) if superview = render_target || view_stack.last insert_index ? superview.insertSubview(view, atIndex: insert_index) : superview.addSubview(view) end view.on_added if view.respond_to?(:on_added) view end |
#set_options_for(view, options = {}, &block) ⇒ Object Also known as: update_options_for
34 35 36 37 38 39 |
# File 'motion-prime/views/layout.rb', line 34 def (view, = {}, &block) ViewStyler.new(view, .delete(:parent_bounds), ).apply view_stack.push(view) block.call(view) if block_given? view_stack.pop end |
#setup(view, options = {}, &block) ⇒ Object
42 43 44 45 |
# File 'motion-prime/views/layout.rb', line 42 def setup(view, = {}, &block) puts "DEPRECATION: screen#setup is deprecated, please use screen#set_options_for instead" (view, , &block) end |
#view_stack ⇒ Object
47 48 49 |
# File 'motion-prime/views/layout.rb', line 47 def view_stack @view_stack ||= [] end |