|  | @@ -68,13 +68,12 @@ public class ScreenStack extends FrameLayout {
 | 
	
		
			
			| 68 | 68 |      }
 | 
	
		
			
			| 69 | 69 |  
 | 
	
		
			
			| 70 | 70 |      public Screen pop() {
 | 
	
		
			
			| 71 |  | -        if (mStack.isEmpty()) {
 | 
	
		
			
			|  | 71 | +        if (mStack.isEmpty() || getStackSize() == 1) {
 | 
	
		
			
			| 72 | 72 |              return null;
 | 
	
		
			
			| 73 | 73 |          }
 | 
	
		
			
			|  | 74 | +
 | 
	
		
			
			| 74 | 75 |          ScreenView popped = mStack.pop();
 | 
	
		
			
			| 75 |  | -        if (!mStack.isEmpty()) {
 | 
	
		
			
			| 76 |  | -            addView(mStack.peek().view, 0);
 | 
	
		
			
			| 77 |  | -        }
 | 
	
		
			
			|  | 76 | +        addView(mStack.peek().view, 0);
 | 
	
		
			
			| 78 | 77 |  
 | 
	
		
			
			| 79 | 78 |          ReflectionUtils.setBooleanField(popped.view.getReactRootView(), "mAttachScheduled", false);
 | 
	
		
			
			| 80 | 79 |          removeView(popped.view);
 | 
	
	
		
			
			|  | @@ -82,22 +81,17 @@ public class ScreenStack extends FrameLayout {
 | 
	
		
			
			| 82 | 81 |      }
 | 
	
		
			
			| 83 | 82 |  
 | 
	
		
			
			| 84 | 83 |      public Screen popToRoot() {
 | 
	
		
			
			| 85 |  | -        if (mStack.isEmpty()) {
 | 
	
		
			
			| 86 |  | -            return null;
 | 
	
		
			
			| 87 |  | -        }
 | 
	
		
			
			| 88 |  | -
 | 
	
		
			
			| 89 |  | -        int stackSize = getStackSize();
 | 
	
		
			
			| 90 |  | -        if (stackSize < 2) {
 | 
	
		
			
			|  | 84 | +        if (mStack.isEmpty() || getStackSize() <= 1) {
 | 
	
		
			
			| 91 | 85 |              return null;
 | 
	
		
			
			| 92 | 86 |          }
 | 
	
		
			
			| 93 | 87 |  
 | 
	
		
			
			| 94 |  | -        ScreenView lastView = null;
 | 
	
		
			
			| 95 |  | -        while (getStackSize() >= 2) {
 | 
	
		
			
			|  | 88 | +        ScreenView oldScreenView = null;
 | 
	
		
			
			|  | 89 | +        while (getStackSize() > 1) {
 | 
	
		
			
			| 96 | 90 |              ScreenView popped = mStack.pop();
 | 
	
		
			
			| 97 | 91 |              ReflectionUtils.setBooleanField(popped.view.getReactRootView(), "mAttachScheduled", false);
 | 
	
		
			
			| 98 | 92 |              removeView(popped.view);
 | 
	
		
			
			| 99 |  | -            if (lastView == null) {
 | 
	
		
			
			| 100 |  | -                lastView = popped;
 | 
	
		
			
			|  | 93 | +            if (oldScreenView == null) {
 | 
	
		
			
			|  | 94 | +                oldScreenView = popped;
 | 
	
		
			
			| 101 | 95 |              }
 | 
	
		
			
			| 102 | 96 |          }
 | 
	
		
			
			| 103 | 97 |  
 | 
	
	
		
			
			|  | @@ -105,7 +99,37 @@ public class ScreenStack extends FrameLayout {
 | 
	
		
			
			| 105 | 99 |              addView(mStack.peek().view, 0);
 | 
	
		
			
			| 106 | 100 |          }
 | 
	
		
			
			| 107 | 101 |  
 | 
	
		
			
			| 108 |  | -        return lastView.screen;
 | 
	
		
			
			|  | 102 | +        return oldScreenView.screen;
 | 
	
		
			
			|  | 103 | +    }
 | 
	
		
			
			|  | 104 | +
 | 
	
		
			
			|  | 105 | +    public Screen resetTo(Screen screen) {
 | 
	
		
			
			|  | 106 | +        return resetTo(screen, null);
 | 
	
		
			
			|  | 107 | +    }
 | 
	
		
			
			|  | 108 | +
 | 
	
		
			
			|  | 109 | +    public Screen resetTo(Screen screen, RctView.OnDisplayedListener onDisplayed) {
 | 
	
		
			
			|  | 110 | +        RctView view = new RctView(mReactActivity, mReactInstanceManager, screen, onDisplayed);
 | 
	
		
			
			|  | 111 | +        addView(view, MATCH_PARENT, MATCH_PARENT);
 | 
	
		
			
			|  | 112 | +
 | 
	
		
			
			|  | 113 | +        ScreenView oldScreenView = null;
 | 
	
		
			
			|  | 114 | +        if (!mStack.isEmpty()) {
 | 
	
		
			
			|  | 115 | +            while (getStackSize() > 0) {
 | 
	
		
			
			|  | 116 | +                ScreenView screenView = mStack.pop();
 | 
	
		
			
			|  | 117 | +                ReflectionUtils.setBooleanField(screenView.view.getReactRootView(), "mAttachScheduled", false);
 | 
	
		
			
			|  | 118 | +                removeView(screenView.view);
 | 
	
		
			
			|  | 119 | +                if (oldScreenView == null) {
 | 
	
		
			
			|  | 120 | +                    oldScreenView = screenView;
 | 
	
		
			
			|  | 121 | +                }
 | 
	
		
			
			|  | 122 | +            }
 | 
	
		
			
			|  | 123 | +        }
 | 
	
		
			
			|  | 124 | +
 | 
	
		
			
			|  | 125 | +        // Add screen to stack after it's clear
 | 
	
		
			
			|  | 126 | +        mStack.push(new ScreenView(screen, view));
 | 
	
		
			
			|  | 127 | +
 | 
	
		
			
			|  | 128 | +        if (oldScreenView == null) {
 | 
	
		
			
			|  | 129 | +            return null;
 | 
	
		
			
			|  | 130 | +        }
 | 
	
		
			
			|  | 131 | +
 | 
	
		
			
			|  | 132 | +        return oldScreenView.screen;
 | 
	
		
			
			| 109 | 133 |      }
 | 
	
		
			
			| 110 | 134 |  
 | 
	
		
			
			| 111 | 135 |      public boolean isEmpty() {
 |