Skip to content

Commit

Permalink
Merge pull request #808 from infinitered/bugfix/screen-configuration
Browse files Browse the repository at this point in the history
Fix an issue preventing certain screen options from being applied in certain scenarios
  • Loading branch information
andrewhavens committed Apr 19, 2018
2 parents eefba37 + d8b7192 commit 163d9d8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
23 changes: 22 additions & 1 deletion lib/ProMotion/delegate/delegate_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def ui_window
end

def open(screen, args={})
screen = screen.new if screen.respond_to?(:new)
screen = set_up_screen_for_open(screen, args)

self.home_screen = screen

Expand All @@ -65,6 +65,27 @@ def open(screen, args={})
alias :open_screen :open
alias :open_root_screen :open_screen

def set_up_screen_for_open(screen, args={})
# Instantiate screen if given a class
screen = screen.new(args) if screen.respond_to?(:new)

# Store screen options
screen.screen_options.merge(args) if screen.respond_to?(:screen_options)

# Set title & modal properties
screen.title = args[:title] if args[:title] && screen.respond_to?(:title=)
screen.modal = args[:modal] if args[:modal] && screen.respond_to?(:modal=)

# Hide bottom bar?
screen.hidesBottomBarWhenPushed = args[:hide_tab_bar] == true

# Wrap in a PM::NavigationController?
screen.add_nav_bar(args) if args[:nav_bar] && screen.respond_to?(:add_nav_bar)

# Return modified screen instance
screen
end

# DEPRECATED
def status_bar?
mp "The default behavior of `status_bar?` has changed. Calling `status_bar?` on AppDelegate may not return the correct result.", force_color: :yellow
Expand Down
9 changes: 6 additions & 3 deletions lib/ProMotion/screen/nav_bar_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def navigation_controller
def navigation_controller=(nav)
self.navigationController = nav
end
alias :nav_controller= :navigation_controller=

def navigationController=(nav)
@navigationController = nav
Expand Down Expand Up @@ -59,9 +60,11 @@ def add_nav_bar(args = {})
self.navigationController.toolbarHidden = !args[:toolbar] unless args[:toolbar].nil?
end

def view_will_appear(animated)
if @screen_options && !@screen_options[:hide_nav_bar].nil?
self.navigationController.setNavigationBarHidden(@screen_options[:hide_nav_bar], animated: false)
def update_nav_bar_visibility(animated)
return unless navigationController
hidden = @screen_options[:hide_nav_bar]
unless hidden.nil?
navigationController.setNavigationBarHidden(hidden, animated: animated)
end
end

Expand Down
5 changes: 3 additions & 2 deletions lib/ProMotion/screen/screen_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module ScreenModule
include ProMotion::SplitScreen if UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad || (UIDevice.currentDevice.systemVersion.to_i >= 8 )

attr_reader :parent_screen
attr_accessor :first_screen, :modal, :split_screen
attr_accessor :screen_options, :first_screen, :modal, :split_screen

def screen_init(args = {})
@screen_options = args
Expand Down Expand Up @@ -41,7 +41,8 @@ def view_did_load
end

def view_will_appear(animated)
super
update_nav_bar_visibility(animated)

self.will_appear

self.will_present if isMovingToParentViewController
Expand Down
6 changes: 2 additions & 4 deletions lib/ProMotion/screen/screen_navigation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,11 @@ def push_view_controller(vc, nav_controller=nil, animated=true)
protected

def set_up_screen_for_open(screen, args={})

# Instantiate screen if given a class
screen = screen.new if screen.respond_to?(:new)
screen = screen.new(args) if screen.respond_to?(:new)

# Store screen options
screen.instance_variable_set(:@screen_options, args)
screen.screen_options.merge(args) if screen.respond_to?(:screen_options)

# Set parent
screen.parent_screen = self if screen.respond_to?(:parent_screen=)
Expand All @@ -100,7 +99,6 @@ def set_up_screen_for_open(screen, args={})

# Return modified screen instance
screen

end

def ensure_wrapper_controller_in_place(screen, args={})
Expand Down

0 comments on commit 163d9d8

Please sign in to comment.