README.md in ProMotion-0.0.1 vs README.md in ProMotion-0.0.2

- old
+ new

@@ -43,17 +43,17 @@ $ gem install ProMotion ## Usage -It's easy to load your first view with a navigation bar (the view is opened in a UINavigationController): +It's easy to load your first screen with a navigation bar (the screen is opened in a UINavigationController behind the scenes): ```ruby -# In /app/app_delegate.rb: -class AppDelegate +# In /app/app_delegate.rb (note that AppDelegate extends ProMotion::AppDelegate) +class AppDelegate < ProMotion::AppDelegate def application(application, didFinishLaunchingWithOptions:launchOptions) - @window = HomeScreen.open_with_nav_bar + open_with_nav_bar HomeScreen true end end ``` @@ -64,11 +64,11 @@ # In /app/screens/home_screen.rb: class HomeScreen < ProMotion::Screen # Set the title for use in nav bars and other containers title "Home" - # Called when this view is first "opened" and allows you to set up your view + # Called when this screen is first "opened" and allows you to set up your view components def on_load @default_image = add_image(:default_image, src: "default.png", frame: [10, 50, 100, 100]) end end ``` @@ -79,11 +79,10 @@ # In /app/screens/home_screen.rb: class HomeScreen < ProMotion::Screen # Set the title for use in nav bars and other containers title "Home" - # Called when this view is first "opened" and allows you to set up your view def on_load # Add view items as instance vars so you can access them in other methods # This adds a right nav bar button. on_tap allows you to set a method to call when it's tapped. @right_bar_button = add_right_nav_button(label: "Save", on_tap: :save) @@ -98,11 +97,11 @@ @custom_view = add_view(ChatView.alloc.initWithFrame(CGRectMake(10, 300, 40, 40))) end end ``` -View items can be bound to events (like jQuery) and run methods or run a block. +View components can be bound to events (like jQuery) and run methods or run a block. ```ruby # settings_pushed is executed when the button is tapped @settings_button = add_button(label: "Settings", frame: [10, 10, 100, 30]) @settings_button.on(:tap, :settings_pushed) @@ -115,15 +114,23 @@ # This button passes in arguments to the method when it's tapped @edit_button = add_button(label: "Edit", frame: [10, 10, 100, 30]) @edit_button.on(:tap, :edit_pushed, id: 4) ``` -To open other screens, just call their "open" method: +To open other screens, just call the built-in "open" method on a new instance or class: ```ruby def settings_button_tapped - SettingsScreen.open + # ...with a class... + open SettingsScreen + + # ...or with an instance... + @settings_screen = SettingsScreen.new(some_attr: 4) + open @settings_screen + + # ...or if you like... + open SettingsScreen.new end ``` You can pass in arguments to those screens if they have accessors: @@ -144,21 +151,21 @@ # /app/screens/home_screen.rb class HomeScreen < ProMotion::Screen # ... def settings_button_tapped - SettingsScreen.open(user_type: "Admin") + open SettingsScreen.new(user_type: "Admin") end end ``` When you're done with a screen, just close it: ```ruby def save_and_close if @model.save - self.close + close end end ``` If you want to pass arguments back to the previous screen, go for it. @@ -166,11 +173,11 @@ ```ruby class SettingsScreen < ProMotion::Screen # ... def save_and_close - self.close(saved_changes: true) + close(saved_changes: true) end end class MainScreen < ProMotion::Screen # ... @@ -236,11 +243,11 @@ title "Home" # Defaults to :normal. :plain_table, :grouped_table are options. screen_type :plain_table - # Called when this view is first "opened" and allows you to set up your view + # Called when this screen is first "opened" and allows you to set up your view components def on_load # Add view items as instance vars so you can access them in other methods # This adds a right nav bar button. on_tap allows you to set a method to call when it's tapped. @right_bar_button = add_right_nav_button(label: "Save", on_tap: :save) @@ -292,16 +299,16 @@ # Custom method, invoked when tapping something with this as the action def save # Assuming some sort of ORM, like ParseModel @my_model.save - # When you want to close the current view (usually in a navigation controller), just run this. - self.close + # When you want to close the current screen (usually in a navigation controller), just run this. + close - # You can also pass back arguments to the previous view as you close. + # You can also pass back arguments to the previous screen as you close. # If the previous screen has an `on_return` method, this will be passed into that method - self.close(did_stuff: true) + close(did_stuff: true) end # This is called any time a screen "above" this screen is closed. args = {} is required. def on_return(args = {}) if args[:did_stuff] @@ -310,20 +317,23 @@ end # Custom method def settings_pushed # Just open a settings screen - SettingsScreen.open + open SettingsScreen + + # If you prefer to pass in an instance, that works too: + open SettingsScreen.new end def close_pushed - self.close + close end # Custom method with passed in arguments def edit_pushed(args) # Open a screen and set some of its attributes - EditScreen.open(id: args[:id]) + open EditScreen.new(id: args[:id]) end end ```