Sha256: 32f1d4c5540d31ba583f9236da3650656fc6afcd2544410317ae7b0acb2eb536

Contents?: true

Size: 1.71 KB

Versions: 3

Compression:

Stored size: 1.71 KB

Contents

module ProMotion
  class Delegate
    include ProMotion::ScreenTabs
    include ProMotion::SplitScreen if NSBundle.mainBundle.infoDictionary["UIDeviceFamily"].include?("2") # Only with iPad
    attr_accessor :window

    def application(application, didFinishLaunchingWithOptions:launch_options)
      unless self.respond_to?(:on_load)
        PM.logger.error "Your AppDelegate (usually in app_delegate.rb) needs an on_load(application, options) method."
      end

      on_load(application, launch_options)

      true
    end

    def app_delegate
      UIApplication.sharedApplication.delegate
    end

    def app_window
      self.app_delegate.window
    end

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

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

      self.window ||= self.ui_window.alloc.initWithFrame(UIScreen.mainScreen.bounds)
      self.window.rootViewController = new_screen
      self.window.makeKeyAndVisible
    end
    
    def ui_window
      (defined?(Motion) && defined?(Motion::Xray) && defined?(Motion::Xray::XrayWindow)) ? Motion::Xray::XrayWindow : UIWindow
    end

    def open_screen(screen, args={})
      home(screen)
      open_home_screen
    end
    alias :open :open_screen
    alias :open_root_screen :open_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
  class AppDelegateParent < Delegate; end # For backwards compatibility
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ProMotion-0.6.2 lib/ProMotion/delegate.rb
ProMotion-0.6.1 lib/ProMotion/delegate.rb
ProMotion-0.6.0 lib/ProMotion/delegate.rb