Browse Source

Added back, getNavigatorID

Yedidya Kennard 9 years ago
parent
commit
1302152190

+ 11
- 7
android/app/src/main/java/com/reactnativenavigation/activities/BaseReactActivity.java View File

@@ -191,8 +191,8 @@ public abstract class BaseReactActivity extends AppCompatActivity implements Def
191 191
         super.onDestroy();
192 192
 
193 193
         // Destroy react instance manager only if there are no resumed react activities
194
-        Activity activity = ContextProvider.getActivityContext();
195
-        if (mReactInstanceManager != null && !(activity instanceof BaseReactActivity)) {
194
+        BaseReactActivity activity = ContextProvider.getActivityContext();
195
+        if (mReactInstanceManager != null ) {
196 196
             Log.i(TAG, "Destroying ReactInstanceManager");
197 197
             mReactInstanceManager.onDestroy();
198 198
         } else {
@@ -204,6 +204,8 @@ public abstract class BaseReactActivity extends AppCompatActivity implements Def
204 204
 
205 205
     public abstract Screen pop(String navID);
206 206
 
207
+    public abstract String getActiveNavigatorID();
208
+
207 209
     @Override
208 210
     public boolean onCreateOptionsMenu(Menu menu) {
209 211
         mMenu = menu;
@@ -252,11 +254,13 @@ public abstract class BaseReactActivity extends AppCompatActivity implements Def
252 254
 
253 255
     @Override
254 256
     public void onBackPressed() {
255
-        if (mReactInstanceManager != null)
256
-            mReactInstanceManager.onBackPressed();
257
-        //TODO uncomment and add current navID
258
-         else //if(pop() == null)
259
-            super.onBackPressed();
257
+
258
+        if(pop(getActiveNavigatorID()) == null) {
259
+            if (mReactInstanceManager != null)
260
+                mReactInstanceManager.onBackPressed();
261
+            else
262
+                super.onBackPressed();
263
+        }
260 264
     }
261 265
 
262 266
     @Override

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

@@ -65,4 +65,10 @@ public class RootActivity extends BaseReactActivity {
65 65
         return null;
66 66
         //TODO
67 67
     }
68
+
69
+    @Override
70
+    public String getActiveNavigatorID() {
71
+        return null;
72
+        //TODO
73
+    }
68 74
 }

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

@@ -18,6 +18,7 @@ public class SingleScreenActivity extends BaseReactActivity {
18 18
     private Toolbar mToolbar;
19 19
     private FrameLayout mContentFrame;
20 20
     private ScreenStack screenStack;
21
+    private String navID;
21 22
 
22 23
     @Override
23 24
     protected void handleOnCreate() {
@@ -28,6 +29,7 @@ public class SingleScreenActivity extends BaseReactActivity {
28 29
         mContentFrame = (FrameLayout) findViewById(R.id.contentFrame);
29 30
 
30 31
         Screen screen = (Screen) getIntent().getSerializableExtra(EXTRA_SCREEN);
32
+        navID = screen.navigatorId;
31 33
         setupToolbar(screen.title);
32 34
 
33 35
         screenStack = new ScreenStack(this);
@@ -48,4 +50,9 @@ public class SingleScreenActivity extends BaseReactActivity {
48 50
     public Screen pop(String navID) {
49 51
         return screenStack.pop();
50 52
     }
53
+
54
+    @Override
55
+    public String getActiveNavigatorID() {
56
+        return navID;
57
+    }
51 58
 }

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

@@ -69,4 +69,9 @@ public class TabActivity extends BaseReactActivity {
69 69
         mToolbar.handleOnCreateOptionsMenuAsync();
70 70
         return ret;
71 71
     }
72
+
73
+    @Override
74
+    public String getActiveNavigatorID() {
75
+        return adapter.getNavID(mViewPager.getCurrentItem());
76
+    }
72 77
 }

+ 11
- 3
android/app/src/main/java/com/reactnativenavigation/adapters/ViewPagerAdapter.java View File

@@ -13,6 +13,7 @@ import com.facebook.react.bridge.WritableMap;
13 13
 import com.reactnativenavigation.activities.BaseReactActivity;
14 14
 import com.reactnativenavigation.core.RctManager;
15 15
 import com.reactnativenavigation.core.objects.Screen;
16
+import com.reactnativenavigation.views.RnnToolBar;
16 17
 import com.reactnativenavigation.views.ScreenStack;
17 18
 
18 19
 import java.util.ArrayList;
@@ -28,23 +29,26 @@ public class ViewPagerAdapter extends PagerAdapter implements TabLayout.OnTabSel
28 29
 
29 30
     private BaseReactActivity mContext;
30 31
     private ViewPager mViewPager;
31
-    private Toolbar mToolbar;
32
+    private RnnToolBar mToolbar;
32 33
     private final ReactInstanceManager mReactInstanceManager;
33 34
     private final ArrayList<ScreenStack> screenStacks;
35
+    private final ArrayList<String> navIDs;
34 36
     private final Map<String, ScreenStack> stacksByNavId;
35 37
 
36 38
 
37
-    public ViewPagerAdapter(BaseReactActivity context, ViewPager viewPager, Toolbar toolbar,
39
+    public ViewPagerAdapter(BaseReactActivity context, ViewPager viewPager, RnnToolBar toolbar,
38 40
                             ArrayList<Screen> screens) {
39 41
         mContext = context;
40 42
         mViewPager = viewPager;
41 43
         mToolbar = toolbar;
42 44
         screenStacks = new ArrayList<>();
45
+        navIDs = new ArrayList<>();
43 46
         stacksByNavId  = new HashMap<>();
44 47
         for(Screen screen: screens){
45 48
             ScreenStack stack = new ScreenStack(context);
46 49
             stack.push(screen);
47 50
             screenStacks.add(stack);
51
+            navIDs.add(screen.navigatorId);
48 52
             stacksByNavId.put(screen.navigatorId, stack);
49 53
         }
50 54
         mReactInstanceManager = RctManager.getInstance().getReactInstanceManager();
@@ -100,7 +104,7 @@ public class ViewPagerAdapter extends PagerAdapter implements TabLayout.OnTabSel
100 104
         Screen screen = screenStacks.get(position).peek();
101 105
         params.putString(Screen.KEY_NAVIGATOR_EVENT_ID, screen.navigatorEventId);
102 106
 
103
-//        mToolbar.setupToolbarButtonsAsync(mScreens.get(position));
107
+        mToolbar.setupToolbarButtonsAsync(screenStacks.get(position).peek());
104 108
 
105 109
         RctManager.getInstance().sendEvent(EVENT_ON_TAB_SELECTED, screen.navigatorEventId, params);
106 110
     }
@@ -114,4 +118,8 @@ public class ViewPagerAdapter extends PagerAdapter implements TabLayout.OnTabSel
114 118
     public void onTabReselected(TabLayout.Tab tab) {
115 119
 
116 120
     }
121
+
122
+    public String getNavID(int position) {
123
+        return navIDs.get(position);
124
+    }
117 125
 }

+ 2
- 0
android/app/src/main/java/com/reactnativenavigation/modules/RctActivityModule.java View File

@@ -34,6 +34,7 @@ public class RctActivityModule extends ReactContextBaseJavaModule {
34 34
 
35 35
     @ReactMethod
36 36
     public void startTabBasedApp(ReadableArray screens) {
37
+        Log.e("START", "NEW_TAB");
37 38
         Activity context = ContextProvider.getActivityContext();
38 39
         if (context != null && !context.isFinishing()) {
39 40
             Intent intent = new Intent(context, TabActivity.class);
@@ -54,6 +55,7 @@ public class RctActivityModule extends ReactContextBaseJavaModule {
54 55
 
55 56
     @ReactMethod
56 57
     public void startSingleScreenApp(ReadableMap screen) {
58
+        Log.e("START", "NEW_SINGLE");
57 59
         BaseReactActivity context = ContextProvider.getActivityContext();
58 60
         if (context != null && !context.isFinishing()) {
59 61
             Intent intent = new Intent(context, SingleScreenActivity.class);

+ 9
- 5
android/app/src/main/java/com/reactnativenavigation/views/ScreenStack.java View File

@@ -11,7 +11,7 @@ import com.reactnativenavigation.core.objects.Screen;
11 11
 
12 12
 import java.util.Stack;
13 13
 
14
-import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
14
+import static android.view.ViewGroup.LayoutParams.*;
15 15
 
16 16
 public class ScreenStack extends FrameLayout {
17 17
 
@@ -37,22 +37,26 @@ public class ScreenStack extends FrameLayout {
37 37
 
38 38
     public void push(Screen screen){
39 39
         View oldView = null;
40
-        if(!stack.isEmpty())
40
+        if(!stack.isEmpty()) {
41 41
             oldView = stack.peek().view;
42
+        }
42 43
         RctView view = new RctView(reactActivity, mReactInstanceManager, screen);
43 44
         addView(view, MATCH_PARENT, MATCH_PARENT);
44
-        if(oldView!=null)
45
+        if(oldView!=null) {
45 46
             removeView(oldView);
47
+        }
46 48
         stack.push(new ScreenView(screen, view));
47 49
     }
48 50
 
49 51
     public Screen pop(){
50 52
         //TODO maybe return null if size is 1?
51
-        if(stack.isEmpty())
53
+        if(stack.isEmpty()) {
52 54
             return null;
55
+        }
53 56
         ScreenView popped = stack.pop();
54
-        if(!stack.isEmpty());
57
+        if(!stack.isEmpty()) {
55 58
             addView(stack.peek().view, 0);
59
+        }
56 60
         removeView(popped.view);
57 61
         return popped.screen;
58 62
     }