doc/code/screens.rb in motion-prime-0.4.5 vs doc/code/screens.rb in motion-prime-0.5.0

- old
+ new

@@ -3,15 +3,22 @@ # "Screen" is the most common class in MotionPrime, you can create entire application using only "Screens". # Generally it's just a "UIViewController" wrapper with some syntax sugar. # For RubyOnRails developers the nearest analogy would be "Controllers". --- +# ** Create a screen. ** +# +# Just inherit it from `Prime::Screen`. + +class FooScreen < Prime::Screen +end + # ** Render the screen. ** # -# You should rewrite the `render` method of `Prime::BaseScreen`, which will be runned after first opening screen. +# You should rewrite the `render` method of `Prime::Screen`, which will be runned after first opening screen. -class FooScreen < Prime::BaseScreen +class FooScreen < Prime::Screen def render @main_section = MyProfileSection.new(screen: self, model: User.first) @main_section.render end end @@ -20,28 +27,28 @@ # # Title will be used in screen's navigation controller and will be shown on top of screen. # # NOTE: screen should be created with enabled navigation (see "Initialize screen" block). -class FooScreen < Prime::BaseScreen +class FooScreen < Prime::Screen title 'Foo screen' end # You can pass block to define screen's title -class FooScreen < Prime::BaseScreen +class FooScreen < Prime::Screen title { params[:title] } end # ** Initialize screen. ** # # Available options: # * `:navigation`. When this options is true, screen will be created with navigation support: it will allow adding title and left/right buttons. -# This option is false by default. +# This option is true by default. def open_foo_screen - foo_screen = FooScreen.new(navigation: true) + foo_screen = FooScreen.new(navigation: false) end # ** Open screen: using app delegate. ** # Opening screen using app delegate is the most basic way, you would use it at least on app load. @@ -49,16 +56,17 @@ # Available options: # * `:root`. When this option is true, screen will not be in content controller and will create new root screen. # You can use root: true when you have already opened screen with sidebar, and you want to open new screen without sidebar. # This option is false by default if you already have root screen and true if not. # -# * `:sidebar`. Send `Prime::BaseScreen` instance to this option if you want to create root screen with sidebar. -# Value of this options will be used as sidebar controller. +# * `:sidebar`. Send `Prime::Screen` instance to this option if you want to create root screen with sidebar. +# Value of this options will be used as sidebar controller. +# NOTE: you should install some gem providing sidebar functionality, e.g. 'prime_reside_menu' def open_foo_screen - foo_screen = FooScreen.new(navigation: true) - sidebar = MySidebar.new + foo_screen = FooScreen.new + sidebar = MySidebar.new(navigation: false) app_delegate.open_screen foo_screen, sidebar: sidebar end # ** Open screen: using parent screen. ** @@ -67,6 +75,13 @@ def open_second_screen second_screen = SecondScreen.new(navigation: true) foo_screen.open_screen second_screen end + +# ** Open screen: using short version. ** + +# Opening screen using short syntax available both for opening via app delegate and via parent screen. + +foo_screen.open_screen :hello_world +app_delegate.open_screen :foo_bar, sidebar: true