Browse Source

Move drawer setup to BaseReactActivity

Jason Skuby 8 years ago
parent
commit
fe4835c116

+ 20
- 0
android/app/src/main/java/com/reactnativenavigation/activities/BaseReactActivity.java View File

7
 import android.os.Handler;
7
 import android.os.Handler;
8
 import android.provider.Settings;
8
 import android.provider.Settings;
9
 import android.support.annotation.CallSuper;
9
 import android.support.annotation.CallSuper;
10
+import android.support.v4.widget.DrawerLayout;
10
 import android.support.v7.app.ActionBarDrawerToggle;
11
 import android.support.v7.app.ActionBarDrawerToggle;
11
 import android.support.v7.app.AppCompatActivity;
12
 import android.support.v7.app.AppCompatActivity;
12
 import android.util.Log;
13
 import android.util.Log;
14
 import android.view.Menu;
15
 import android.view.Menu;
15
 import android.view.MenuItem;
16
 import android.view.MenuItem;
16
 import android.widget.EditText;
17
 import android.widget.EditText;
18
+import android.widget.FrameLayout;
17
 import android.widget.Toast;
19
 import android.widget.Toast;
18
 
20
 
19
 import com.facebook.common.logging.FLog;
21
 import com.facebook.common.logging.FLog;
30
 import com.reactnativenavigation.controllers.ModalController;
32
 import com.reactnativenavigation.controllers.ModalController;
31
 import com.reactnativenavigation.core.RctManager;
33
 import com.reactnativenavigation.core.RctManager;
32
 import com.reactnativenavigation.core.objects.Button;
34
 import com.reactnativenavigation.core.objects.Button;
35
+import com.reactnativenavigation.core.objects.Drawer;
33
 import com.reactnativenavigation.core.objects.Screen;
36
 import com.reactnativenavigation.core.objects.Screen;
34
 import com.reactnativenavigation.modal.RnnModal;
37
 import com.reactnativenavigation.modal.RnnModal;
35
 import com.reactnativenavigation.packages.RnnPackage;
38
 import com.reactnativenavigation.packages.RnnPackage;
36
 import com.reactnativenavigation.utils.ContextProvider;
39
 import com.reactnativenavigation.utils.ContextProvider;
37
 import com.reactnativenavigation.utils.StyleHelper;
40
 import com.reactnativenavigation.utils.StyleHelper;
38
 import com.reactnativenavigation.views.RnnToolBar;
41
 import com.reactnativenavigation.views.RnnToolBar;
42
+import com.reactnativenavigation.views.ScreenStack;
39
 
43
 
40
 import java.util.Arrays;
44
 import java.util.Arrays;
41
 import java.util.List;
45
 import java.util.List;
64
     private Menu mMenu;
68
     private Menu mMenu;
65
     protected RnnToolBar mToolbar;
69
     protected RnnToolBar mToolbar;
66
     protected ActionBarDrawerToggle mDrawerToggle;
70
     protected ActionBarDrawerToggle mDrawerToggle;
71
+    protected DrawerLayout mDrawerLayout;
72
+    protected ScreenStack mDrawerStack;
67
 
73
 
68
     /**
74
     /**
69
      * Returns the name of the bundle in assets. If this is null, and no file path is specified for
75
      * Returns the name of the bundle in assets. If this is null, and no file path is specified for
383
         super.onBackPressed();
389
         super.onBackPressed();
384
     }
390
     }
385
 
391
 
392
+    protected void setupDrawer(Screen screen, Drawer drawer, int drawerFrameId, int drawerLayoutId) {
393
+        if (drawer == null || drawer.left == null) {
394
+            return;
395
+        }
396
+
397
+        mDrawerStack = new ScreenStack(this);
398
+        FrameLayout drawerFrame = (FrameLayout) findViewById(drawerFrameId);
399
+        drawerFrame.addView(mDrawerStack);
400
+        mDrawerStack.push(drawer.left);
401
+
402
+        mDrawerLayout = (DrawerLayout) findViewById(drawerLayoutId);
403
+        mDrawerToggle = mToolbar.setupDrawer(mDrawerLayout, drawer.left, screen);
404
+    }
405
+
386
     public void setNavigationButtons(ReadableMap buttons){
406
     public void setNavigationButtons(ReadableMap buttons){
387
         if (mToolbar == null) {
407
         if (mToolbar == null) {
388
             return;
408
             return;

+ 1
- 18
android/app/src/main/java/com/reactnativenavigation/activities/BottomTabActivity.java View File

4
 import android.graphics.drawable.Drawable;
4
 import android.graphics.drawable.Drawable;
5
 import android.os.AsyncTask;
5
 import android.os.AsyncTask;
6
 import android.os.Bundle;
6
 import android.os.Bundle;
7
-import android.support.v4.widget.DrawerLayout;
8
 import android.view.Menu;
7
 import android.view.Menu;
9
 import android.widget.FrameLayout;
8
 import android.widget.FrameLayout;
10
 
9
 
43
     private AHBottomNavigation mBottomNavigation;
42
     private AHBottomNavigation mBottomNavigation;
44
     private FrameLayout mContentFrame;
43
     private FrameLayout mContentFrame;
45
     private ArrayList<ScreenStack> mScreenStacks;
44
     private ArrayList<ScreenStack> mScreenStacks;
46
-    private ScreenStack mDrawerStack;
47
-    private DrawerLayout mDrawerLayout;
48
     private int mCurrentStackPosition = -1;
45
     private int mCurrentStackPosition = -1;
49
 
46
 
50
     @Override
47
     @Override
59
         final ArrayList<Screen> screens = (ArrayList<Screen>) getIntent().getSerializableExtra(EXTRA_SCREENS);
56
         final ArrayList<Screen> screens = (ArrayList<Screen>) getIntent().getSerializableExtra(EXTRA_SCREENS);
60
         final Drawer drawer = (Drawer) getIntent().getSerializableExtra(DRAWER_PARAMS);
57
         final Drawer drawer = (Drawer) getIntent().getSerializableExtra(DRAWER_PARAMS);
61
         mBottomNavigation.setForceTint(true);
58
         mBottomNavigation.setForceTint(true);
62
-        setupDrawer(drawer, screens.get(0));
59
+        setupDrawer(screens.get(0), drawer, R.id.drawerFrame, R.id.drawerLayout);
63
         setupTabs(getIntent().getExtras());
60
         setupTabs(getIntent().getExtras());
64
         setupPages(screens);
61
         setupPages(screens);
65
 
62
 
72
         });
69
         });
73
     }
70
     }
74
 
71
 
75
-    protected void setupDrawer(Drawer drawer, Screen screen) {
76
-        if (drawer == null || drawer.left == null) {
77
-            return;
78
-        }
79
-
80
-        mDrawerStack = new ScreenStack(this);
81
-        FrameLayout drawerFrame = (FrameLayout) findViewById(R.id.drawerFrame);
82
-        drawerFrame.addView(mDrawerStack);
83
-        mDrawerStack.push(drawer.left);
84
-
85
-        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
86
-        mDrawerToggle = mToolbar.setupDrawer(mDrawerLayout, drawer.left, screen);
87
-    }
88
-
89
     private void setupPages(ArrayList<Screen> screens) {
72
     private void setupPages(ArrayList<Screen> screens) {
90
         new SetupTabsTask(this, mToolbar, screens).execute();
73
         new SetupTabsTask(this, mToolbar, screens).execute();
91
     }
74
     }

+ 2
- 19
android/app/src/main/java/com/reactnativenavigation/activities/SingleScreenActivity.java View File

1
 package com.reactnativenavigation.activities;
1
 package com.reactnativenavigation.activities;
2
 
2
 
3
-import android.support.v4.widget.DrawerLayout;
4
 import android.widget.FrameLayout;
3
 import android.widget.FrameLayout;
5
 
4
 
6
 import com.reactnativenavigation.R;
5
 import com.reactnativenavigation.R;
21
 
20
 
22
     private ScreenStack mScreenStack;
21
     private ScreenStack mScreenStack;
23
     private String mNavigatorId;
22
     private String mNavigatorId;
24
-    private ScreenStack mDrawerStack;
25
-    private DrawerLayout mDrawerLayout;
26
 
23
 
27
     @Override
24
     @Override
28
     protected void handleOnCreate() {
25
     protected void handleOnCreate() {
36
 
33
 
37
         mNavigatorId = screen.navigatorId;
34
         mNavigatorId = screen.navigatorId;
38
         setupToolbar(screen);
35
         setupToolbar(screen);
39
-        setupDrawer(drawer, screen);
36
+        setupDrawer(screen, drawer, R.id.drawerFrame, R.id.drawerLayout);
40
 
37
 
41
         mScreenStack = new ScreenStack(this);
38
         mScreenStack = new ScreenStack(this);
42
         FrameLayout contentFrame = (FrameLayout) findViewById(R.id.contentFrame);
39
         FrameLayout contentFrame = (FrameLayout) findViewById(R.id.contentFrame);
53
         });
50
         });
54
     }
51
     }
55
 
52
 
56
-    protected void setupDrawer(Drawer drawer, Screen screen) {
57
-        if (drawer == null || drawer.left == null) {
58
-            return;
59
-        }
60
-
61
-        mDrawerStack = new ScreenStack(this);
62
-        FrameLayout drawerFrame = (FrameLayout) findViewById(R.id.drawerFrame);
63
-        drawerFrame.addView(mDrawerStack);
64
-        mDrawerStack.push(drawer.left);
65
-
66
-        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
67
-        mDrawerToggle = mToolbar.setupDrawer(mDrawerLayout, drawer.left, screen);
68
-    }
69
-
70
     protected void setupToolbar(Screen screen) {
53
     protected void setupToolbar(Screen screen) {
71
         mToolbar.update(screen);
54
         mToolbar.update(screen);
72
         StyleHelper.updateStyles(mToolbar, screen);
55
         StyleHelper.updateStyles(mToolbar, screen);
73
     }
56
     }
74
-    
57
+
75
     @Override
58
     @Override
76
     public void push(Screen screen) {
59
     public void push(Screen screen) {
77
         super.push(screen);
60
         super.push(screen);