Browse Source

Feed back for empty stack, experimental fix for react state cleared when view pushed down the stack.

Yedidya Kennard 8 years ago
parent
commit
e64986a608

+ 6
- 2
android/app/src/main/java/com/reactnativenavigation/activities/BaseReactActivity.java View File

@@ -205,6 +205,8 @@ public abstract class BaseReactActivity extends AppCompatActivity implements Def
205 205
 
206 206
     public abstract String getActiveNavigatorID();
207 207
 
208
+    public abstract int getScreenStackSize();
209
+
208 210
     @Override
209 211
     public boolean onCreateOptionsMenu(Menu menu) {
210 212
         mMenu = menu;
@@ -253,8 +255,10 @@ public abstract class BaseReactActivity extends AppCompatActivity implements Def
253 255
 
254 256
     @Override
255 257
     public void onBackPressed() {
256
-
257
-        if(pop(getActiveNavigatorID()) == null) {
258
+        if(getScreenStackSize() > 1){
259
+            pop(getActiveNavigatorID());
260
+        }
261
+        else{
258 262
             if (mReactInstanceManager != null)
259 263
                 mReactInstanceManager.onBackPressed();
260 264
             else

+ 6
- 0
android/app/src/main/java/com/reactnativenavigation/activities/RootActivity.java View File

@@ -71,4 +71,10 @@ public class RootActivity extends BaseReactActivity {
71 71
         return null;
72 72
         //TODO
73 73
     }
74
+
75
+    @Override
76
+    public int getScreenStackSize() {
77
+        return 0;
78
+        //TODO
79
+    }
74 80
 }

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/activities/SingleScreenActivity.java View File

@@ -55,4 +55,9 @@ public class SingleScreenActivity extends BaseReactActivity {
55 55
     public String getActiveNavigatorID() {
56 56
         return navID;
57 57
     }
58
+
59
+    @Override
60
+    public int getScreenStackSize() {
61
+        return screenStack.getStackSize();
62
+    }
58 63
 }

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/activities/TabActivity.java View File

@@ -74,4 +74,9 @@ public class TabActivity extends BaseReactActivity {
74 74
     public String getActiveNavigatorID() {
75 75
         return adapter.getNavID(mViewPager.getCurrentItem());
76 76
     }
77
+
78
+    @Override
79
+    public int getScreenStackSize() {
80
+        return adapter.getStackSizeForNavigatorId(getActiveNavigatorID());
81
+    }
77 82
 }

+ 4
- 0
android/app/src/main/java/com/reactnativenavigation/adapters/ViewPagerAdapter.java View File

@@ -122,4 +122,8 @@ public class ViewPagerAdapter extends PagerAdapter implements TabLayout.OnTabSel
122 122
     public String getNavID(int position) {
123 123
         return navIDs.get(position);
124 124
     }
125
+
126
+    public int getStackSizeForNavigatorId(String activeNavigatorID) {
127
+        return stacksByNavId.get(activeNavigatorID).getStackSize();
128
+    }
125 129
 }

+ 7
- 3
android/app/src/main/java/com/reactnativenavigation/views/ScreenStack.java View File

@@ -43,19 +43,23 @@ public class ScreenStack extends FrameLayout {
43 43
         RctView view = new RctView(reactActivity, mReactInstanceManager, screen);
44 44
         addView(view, MATCH_PARENT, MATCH_PARENT);
45 45
         if(oldView!=null) {
46
-            removeView(oldView);
46
+            oldView.setVisibility(GONE);
47 47
         }
48 48
         stack.push(new ScreenView(screen, view));
49 49
     }
50 50
 
51 51
     public Screen pop(){
52
-        //TODO maybe return null if size is 1?
53 52
         if(stack.isEmpty()) {
54 53
             return null;
55 54
         }
56 55
         ScreenView popped = stack.pop();
57 56
         if(!stack.isEmpty()) {
58
-            addView(stack.peek().view, 0);
57
+            View view = stack.peek().view;
58
+            if(view.getParent() == null)
59
+                addView(stack.peek().view, 0);
60
+            else {
61
+                view.setVisibility(VISIBLE);
62
+            }
59 63
         }
60 64
         removeView(popped.view);
61 65
         return popped.screen;