What is a Screen?

"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::Screen, which will be runned after first opening screen.

class FooScreen < Prime::Screen
  def render
    @main_section = MyProfileSection.new(screen: self, model: User.first)
    @main_section.render
  end
end

Set screen's title

Title will be used in screen's navigation controller and will be shown on top of screen.

class FooScreen < Prime::Screen
  title 'Foo screen'
end

You can pass block to define screen's title

class FooScreen < Prime::Screen
  title { params[:title] }
end

Initialize screen.

Available options:

class AppDelegate < Prime::BaseAppDelegate
  def on_load(application, launch_options)
    foo_screen = FooScreen.new(navigation: false)
  end
end

Open screen: from app delegate.

Opening screen using app delegate is the most basic way, you would use it at least on app load.

Available options:

class AppDelegate < Prime::BaseAppDelegate
  def on_load(application, launch_options)
    foo_screen = FooScreen.new
    sidebar = MySidebar.new(navigation: false)
    app_delegate.open_screen foo_screen, sidebar: sidebar
  end
end

Open screen: from parent screen.

Opening screen using parent screen is usefull if you want to create inherited screen. Parent screen should have been initialized with navigation support.

class FooScreen < Prime::Screen
  def render
    second_screen = SecondScreen.new(navigation: true)
    foo_screen.open_screen second_screen
  end
end

Open screen: using short version.

Opening screen using short syntax available both for opening via app delegate and via parent screen.

class AppDelegate < Prime::BaseAppDelegate
  def on_load(application, launch_options)
    open_screen :foo_bar, sidebar: true
  end
end

Next

Read more about Sections

h