Sha256: ef2f5f14bfbf05f792040aa5ec037800f8915fb87682b3da06a6f071456c84c0

Contents?: true

Size: 1.52 KB

Versions: 2

Compression:

Stored size: 1.52 KB

Contents

module ProMotion
  class AppDelegateParent
    include ProMotion::ScreenTabs
    attr_accessor :window
    
    def application(application, didFinishLaunchingWithOptions:launch_options)
      return true if RUBYMOTION_ENV == "test"

      Console.log(" Your AppDelegate (usually in app_delegate.rb) needs an on_load(options) method.", with_color: Console::RED_COLOR) unless self.respond_to?("on_load:")

      on_load(application, launch_options)

      open_home_screen if has_home_screen

      true
    end

    def app_delegate
      UIApplication.sharedApplication.delegate
    end

    def app_window
      self.app_delegate.window
    end

    def load_root_screen(new_screen)
      new_screen = new_screen.main_controller if new_screen.respond_to?(:main_controller)

      self.window ||= UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
      self.window.rootViewController = new_screen
      self.window.makeKeyAndVisible
    end

    def open_screen(screen)
      home(screen)
    end
    alias :open :open_screen

    def home(screen)
      screen = screen.new if screen.respond_to?(:new)
      @home_screen = screen
    end

    def open_root_screen(new_screen)
      home(new_screen)
      open_home_screen
    end
    alias :fresh_start :open_root_screen

    def open_home_screen
      get_home_screen.send(:on_load) if get_home_screen.respond_to?(:on_load)
      load_root_screen get_home_screen
    end
    
    def get_home_screen
      @home_screen
    end

    def has_home_screen
      @home_screen.nil? == false
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ProMotion-0.4.1 lib/ProMotion/app_delegate.rb
ProMotion-0.4.0 lib/ProMotion/app_delegate.rb