Ver código fonte

Move drawer setup to BaseReactActivity

Jason Skuby 8 anos atrás
pai
commit
fe4835c116

+ 20
- 0
android/app/src/main/java/com/reactnativenavigation/activities/BaseReactActivity.java Ver arquivo

@@ -7,6 +7,7 @@ import android.os.Bundle;
7 7
 import android.os.Handler;
8 8
 import android.provider.Settings;
9 9
 import android.support.annotation.CallSuper;
10
+import android.support.v4.widget.DrawerLayout;
10 11
 import android.support.v7.app.ActionBarDrawerToggle;
11 12
 import android.support.v7.app.AppCompatActivity;
12 13
 import android.util.Log;
@@ -14,6 +15,7 @@ import android.view.KeyEvent;
14 15
 import android.view.Menu;
15 16
 import android.view.MenuItem;
16 17
 import android.widget.EditText;
18
+import android.widget.FrameLayout;
17 19
 import android.widget.Toast;
18 20
 
19 21
 import com.facebook.common.logging.FLog;
@@ -30,12 +32,14 @@ import com.reactnativenavigation.BuildConfig;
30 32
 import com.reactnativenavigation.controllers.ModalController;
31 33
 import com.reactnativenavigation.core.RctManager;
32 34
 import com.reactnativenavigation.core.objects.Button;
35
+import com.reactnativenavigation.core.objects.Drawer;
33 36
 import com.reactnativenavigation.core.objects.Screen;
34 37
 import com.reactnativenavigation.modal.RnnModal;
35 38
 import com.reactnativenavigation.packages.RnnPackage;
36 39
 import com.reactnativenavigation.utils.ContextProvider;
37 40
 import com.reactnativenavigation.utils.StyleHelper;
38 41
 import com.reactnativenavigation.views.RnnToolBar;
42
+import com.reactnativenavigation.views.ScreenStack;
39 43
 
40 44
 import java.util.Arrays;
41 45
 import java.util.List;
@@ -64,6 +68,8 @@ public abstract class BaseReactActivity extends AppCompatActivity implements Def
64 68
     private Menu mMenu;
65 69
     protected RnnToolBar mToolbar;
66 70
     protected ActionBarDrawerToggle mDrawerToggle;
71
+    protected DrawerLayout mDrawerLayout;
72
+    protected ScreenStack mDrawerStack;
67 73
 
68 74
     /**
69 75
      * Returns the name of the bundle in assets. If this is null, and no file path is specified for
@@ -383,6 +389,20 @@ public abstract class BaseReactActivity extends AppCompatActivity implements Def
383 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 406
     public void setNavigationButtons(ReadableMap buttons){
387 407
         if (mToolbar == null) {
388 408
             return;

+ 1
- 18
android/app/src/main/java/com/reactnativenavigation/activities/BottomTabActivity.java Ver arquivo

@@ -4,7 +4,6 @@ import android.graphics.Color;
4 4
 import android.graphics.drawable.Drawable;
5 5
 import android.os.AsyncTask;
6 6
 import android.os.Bundle;
7
-import android.support.v4.widget.DrawerLayout;
8 7
 import android.view.Menu;
9 8
 import android.widget.FrameLayout;
10 9
 
@@ -43,8 +42,6 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
43 42
     private AHBottomNavigation mBottomNavigation;
44 43
     private FrameLayout mContentFrame;
45 44
     private ArrayList<ScreenStack> mScreenStacks;
46
-    private ScreenStack mDrawerStack;
47
-    private DrawerLayout mDrawerLayout;
48 45
     private int mCurrentStackPosition = -1;
49 46
 
50 47
     @Override
@@ -59,7 +56,7 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
59 56
         final ArrayList<Screen> screens = (ArrayList<Screen>) getIntent().getSerializableExtra(EXTRA_SCREENS);
60 57
         final Drawer drawer = (Drawer) getIntent().getSerializableExtra(DRAWER_PARAMS);
61 58
         mBottomNavigation.setForceTint(true);
62
-        setupDrawer(drawer, screens.get(0));
59
+        setupDrawer(screens.get(0), drawer, R.id.drawerFrame, R.id.drawerLayout);
63 60
         setupTabs(getIntent().getExtras());
64 61
         setupPages(screens);
65 62
 
@@ -72,20 +69,6 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
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 72
     private void setupPages(ArrayList<Screen> screens) {
90 73
         new SetupTabsTask(this, mToolbar, screens).execute();
91 74
     }

+ 2
- 19
android/app/src/main/java/com/reactnativenavigation/activities/SingleScreenActivity.java Ver arquivo

@@ -1,6 +1,5 @@
1 1
 package com.reactnativenavigation.activities;
2 2
 
3
-import android.support.v4.widget.DrawerLayout;
4 3
 import android.widget.FrameLayout;
5 4
 
6 5
 import com.reactnativenavigation.R;
@@ -21,8 +20,6 @@ public class SingleScreenActivity extends BaseReactActivity {
21 20
 
22 21
     private ScreenStack mScreenStack;
23 22
     private String mNavigatorId;
24
-    private ScreenStack mDrawerStack;
25
-    private DrawerLayout mDrawerLayout;
26 23
 
27 24
     @Override
28 25
     protected void handleOnCreate() {
@@ -36,7 +33,7 @@ public class SingleScreenActivity extends BaseReactActivity {
36 33
 
37 34
         mNavigatorId = screen.navigatorId;
38 35
         setupToolbar(screen);
39
-        setupDrawer(drawer, screen);
36
+        setupDrawer(screen, drawer, R.id.drawerFrame, R.id.drawerLayout);
40 37
 
41 38
         mScreenStack = new ScreenStack(this);
42 39
         FrameLayout contentFrame = (FrameLayout) findViewById(R.id.contentFrame);
@@ -53,25 +50,11 @@ public class SingleScreenActivity extends BaseReactActivity {
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 53
     protected void setupToolbar(Screen screen) {
71 54
         mToolbar.update(screen);
72 55
         StyleHelper.updateStyles(mToolbar, screen);
73 56
     }
74
-    
57
+
75 58
     @Override
76 59
     public void push(Screen screen) {
77 60
         super.push(screen);