Skip to content

Commit

Permalink
[Android] Maintain navigation stack correctly when hardware back butt…
Browse files Browse the repository at this point in the history
…on is used to pop screens
  • Loading branch information
hboon authored Dec 15, 2016
1 parent 05151b2 commit d8739a0
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion flow/ui/android/navigation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def items=(items)
end

def push(screen, animated=true)
@stack_change_reason = :push
screen.navigation = self

fragment = screen.proxy
Expand All @@ -73,6 +74,7 @@ def push(screen, animated=true)

def pop(animated=true)
if @current_screens.size > 1
@stack_change_reason = :pop
current_screen = @current_screens.pop
current_screen.proxy._animate = animated ? :slide : false
previous_screen = @current_screens.last
Expand All @@ -89,6 +91,35 @@ def pop(animated=true)
end

def proxy
@proxy ||= UI.context.fragmentManager
@proxy ||= begin
manager = UI.context.fragmentManager
manager.addOnBackStackChangedListener(FlowFragmentManagerStackChangedListener.new(self))
manager
end
end

def stack_changed
case @stack_change_reason
when :push
when :pop
else
@current_screens.pop
previous_screen = @current_screens.last
if previous_screen
previous_screen.before_on_show
previous_screen.on_show
end
end
@stack_change_reason = nil
end
end

class FlowFragmentManagerStackChangedListener
def initialize(navigation)
@navigation = navigation
end

def onBackStackChanged
@navigation.stack_changed
end
end

0 comments on commit d8739a0

Please sign in to comment.