Sha256: 87c067090cdb06d2cf5f4beeb9ac4018e98cd994573d64a58dbae91d3a69fdec

Contents?: true

Size: 1.36 KB

Versions: 2

Compression:

Stored size: 1.36 KB

Contents

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

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

      open_home_screen if has_home_screen

      get_home_screen.on_opened if has_home_screen && get_home_screen.respond_to?(:on_opened)
      
      true
    end

    def app_delegate
      UIApplication.sharedApplication.delegate
    end

    def app_window
      self.app_delegate.window
    end

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

    def open_screen(screen)
      home(screen)
    end

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

    def fresh_start(new_screen)
      home(new_screen)
      open_home_screen
    end

    def open_home_screen
      root = get_home_screen.main_controller
      load_root_view root
    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.1.1 lib/ProMotion/AppDelegate.rb
ProMotion-0.1.0 lib/ProMotion/AppDelegate.rb