Просмотр исходного кода

Misc ToolBar fixes

Minor refactor after merging #52.
Guy Carmeli 8 лет назад
Родитель
Сommit
923dd6eddf

+ 7
- 4
android/app/src/main/java/com/reactnativenavigation/activities/BaseReactActivity.java Просмотреть файл

@@ -219,10 +219,13 @@ public abstract class BaseReactActivity extends AppCompatActivity implements Def
219 219
     @CallSuper
220 220
     public void push(Screen screen) {
221 221
         setNavigationStyle(screen);
222
-        if (mToolbar != null &&
223
-            getCurrentNavigatorId().equals(screen.navigatorId) &&
224
-            getScreenStackSize() >= 1) {
225
-            mToolbar.showBackButton(screen);
222
+        if (mToolbar != null) {
223
+            mToolbar.update(screen);
224
+
225
+            if (getCurrentNavigatorId().equals(screen.navigatorId) &&
226
+                getScreenStackSize() >= 1) {
227
+                mToolbar.showBackButton(screen);
228
+            }
226 229
         }
227 230
     }
228 231
 

+ 5
- 10
android/app/src/main/java/com/reactnativenavigation/activities/BottomTabActivity.java Просмотреть файл

@@ -63,18 +63,12 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
63 63
     }
64 64
 
65 65
     private void setupToolbar(ArrayList<Screen> screens) {
66
-        Screen initialScreen = screens.get(0);
67 66
         mToolbar.setScreens(screens);
68
-        mToolbar.updateToolbar(initialScreen);
67
+        Screen initialScreen = screens.get(0);
68
+        mToolbar.update(initialScreen);
69 69
         setNavigationStyle(initialScreen);
70 70
     }
71 71
 
72
-    @Override
73
-    public void setNavigationStyle(Screen screen) {
74
-        super.setNavigationStyle(screen);
75
-        mToolbar.setTitle(screen.title);
76
-    }
77
-
78 72
     private void setupTabs(Bundle style) {
79 73
 
80 74
         mBottomNavigation.setForceTitlesDisplay(style.getBoolean(TAB_STYLE_INACTIVE_TITLES, DEFAULT_TAB_INACTIVE_TITLES));
@@ -103,7 +97,6 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
103 97
     @Override
104 98
     public void push(Screen screen) {
105 99
         super.push(screen);
106
-        setNavigationStyle(screen);
107 100
         mScreenStacks.get(mCurrentStackPosition).push(screen);
108 101
     }
109 102
 
@@ -111,7 +104,9 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
111 104
     public Screen pop(String navigatorId) {
112 105
         super.pop(navigatorId);
113 106
         Screen screen = mScreenStacks.get(mCurrentStackPosition).pop();
114
-        setNavigationStyle(getCurrentScreen());
107
+        Screen currentScreen = getCurrentScreen();
108
+        setNavigationStyle(currentScreen);
109
+        mToolbar.update(currentScreen);
115 110
         return screen;
116 111
     }
117 112
 

+ 4
- 3
android/app/src/main/java/com/reactnativenavigation/activities/SingleScreenActivity.java Просмотреть файл

@@ -36,14 +36,13 @@ public class SingleScreenActivity extends BaseReactActivity {
36 36
     }
37 37
 
38 38
     protected void setupToolbar(Screen screen) {
39
-        mToolbar.updateToolbar(screen);
39
+        mToolbar.update(screen);
40 40
         setNavigationStyle(screen);
41 41
     }
42 42
     
43 43
     @Override
44 44
     public void push(Screen screen) {
45 45
         super.push(screen);
46
-        setNavigationStyle(screen);
47 46
         mScreenStack.push(screen);
48 47
     }
49 48
 
@@ -51,7 +50,9 @@ public class SingleScreenActivity extends BaseReactActivity {
51 50
     public Screen pop(String navigatorId) {
52 51
         super.pop(navigatorId);
53 52
         Screen screen = mScreenStack.pop();
54
-        setNavigationStyle(getCurrentScreen());
53
+        Screen currentScreen = getCurrentScreen();
54
+        setNavigationStyle(currentScreen);
55
+        mToolbar.update(currentScreen);
55 56
         return screen;
56 57
     }
57 58
 

+ 3
- 1
android/app/src/main/java/com/reactnativenavigation/activities/TabActivity.java Просмотреть файл

@@ -13,8 +13,10 @@ import com.reactnativenavigation.views.RnnToolBar;
13 13
 import java.util.ArrayList;
14 14
 
15 15
 /**
16
+ * This class is currently not supported and will be removed in future release.
16 17
  * Created by guyc on 02/04/16.
17 18
  */
19
+@Deprecated
18 20
 public class TabActivity extends BaseReactActivity {
19 21
     public static final String EXTRA_SCREENS = "extraScreens";
20 22
 
@@ -40,7 +42,7 @@ public class TabActivity extends BaseReactActivity {
40 42
     private void setupToolbar(ArrayList<Screen> screens) {
41 43
         Screen initialScreen = screens.get(0);
42 44
         mToolbar.setScreens(screens);
43
-        mToolbar.updateToolbar(initialScreen);
45
+        mToolbar.update(initialScreen);
44 46
         setNavigationStyle(initialScreen);
45 47
     }
46 48
 

+ 12
- 14
android/app/src/main/java/com/reactnativenavigation/modal/RnnModal.java Просмотреть файл

@@ -28,25 +28,23 @@ public class RnnModal extends Dialog implements DialogInterface.OnDismissListene
28 28
 
29 29
     private ScreenStack mScreenStack;
30 30
     private View mContentView;
31
-    private Screen mScreen;
32 31
     private RnnToolBar mToolBar;
33 32
 
34 33
     public RnnModal(BaseReactActivity context, Screen screen) {
35 34
         super(context, R.style.Modal);
36
-        mScreen = screen;
37 35
         ModalController.getInstance().add(this);
38
-        init(context);
36
+        init(context, screen);
39 37
     }
40 38
 
41 39
     @SuppressLint("InflateParams")
42
-    private void init(final Context context) {
40
+    private void init(final Context context, Screen screen) {
43 41
         requestWindowFeature(Window.FEATURE_NO_TITLE);
44 42
         mContentView = LayoutInflater.from(context).inflate(R.layout.modal_layout, null, false);
45 43
         mToolBar = (RnnToolBar) mContentView.findViewById(R.id.toolbar);
46 44
         mScreenStack = (ScreenStack) mContentView.findViewById(R.id.screenStack);
47 45
         setContentView(mContentView);
48
-        mToolBar.updateToolbar(mScreen);
49
-        mScreenStack.push(mScreen, new RctView.OnDisplayedListener() {
46
+        mToolBar.update(screen);
47
+        mScreenStack.push(screen, new RctView.OnDisplayedListener() {
50 48
             @Override
51 49
             public void onDisplayed() {
52 50
                 Animation animation = AnimationUtils.loadAnimation(context, R.anim.slide_up);
@@ -59,32 +57,32 @@ public class RnnModal extends Dialog implements DialogInterface.OnDismissListene
59 57
         if (SdkSupports.lollipop()) {
60 58
             Window window = getWindow();
61 59
             window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
62
-            StyleHelper.setWindowStyle(window, context.getApplicationContext(), mScreen);
60
+            StyleHelper.setWindowStyle(window, context.getApplicationContext(), screen);
63 61
         }
64 62
     }
65 63
 
66 64
     public void push(Screen screen) {
67 65
         mScreenStack.push(screen);
68
-        mToolBar.updateToolbar(mScreen);
66
+        mToolBar.update(screen);
69 67
     }
70 68
 
71 69
     public Screen pop() {
72
-        if (mScreenStack.getStackSize() > 1) {
73
-            return mScreenStack.pop();
74
-        } else {
70
+        if (mScreenStack.isEmpty()) {
75 71
             ModalController.getInstance().remove();
76 72
             super.onBackPressed();
77 73
             return null;
74
+        } else {
75
+            return mScreenStack.pop();
78 76
         }
79 77
     }
80 78
 
81 79
     @Override
82 80
     public void onBackPressed() {
83
-        if (mScreenStack.getStackSize() > 1) {
84
-            mScreenStack.pop();
85
-        } else {
81
+        if (mScreenStack.isEmpty()) {
86 82
             ModalController.getInstance().remove();
87 83
             super.onBackPressed();
84
+        } else {
85
+            mScreenStack.pop();
88 86
         }
89 87
     }
90 88
 

+ 7
- 7
android/app/src/main/java/com/reactnativenavigation/views/RnnToolBar.java Просмотреть файл

@@ -23,7 +23,6 @@ import com.reactnativenavigation.utils.ContextProvider;
23 23
 import com.reactnativenavigation.utils.ImageUtils;
24 24
 
25 25
 import java.lang.ref.WeakReference;
26
-import java.util.Collections;
27 26
 import java.util.HashMap;
28 27
 import java.util.List;
29 28
 import java.util.Map;
@@ -148,18 +147,19 @@ public class RnnToolBar extends Toolbar {
148 147
         ContextProvider.getActivityContext().getSupportActionBar().setDisplayHomeAsUpEnabled(false);
149 148
     }
150 149
 
150
+    /**
151
+     * Update the ToolBar from screen. This function sets any properties that are defined
152
+     * in the screen.
153
+     * @param screen The currently displayed screen
154
+     */
151 155
     @UiThread
152
-    public void updateToolbar(Screen screen) {
153
-        setSupportActionBar();
156
+    public void update(Screen screen) {
157
+        ((AppCompatActivity) getContext()).setSupportActionBar(this);
154 158
         setTitle(screen.title);
155 159
         setStyle(screen);
156 160
         setupToolbarButtonsAsync(screen);
157 161
     }
158 162
 
159
-    private void setSupportActionBar() {
160
-        ((AppCompatActivity) getContext()).setSupportActionBar(this);
161
-    }
162
-
163 163
     private static class SetupToolbarButtonsTask extends AsyncTask<Void, Void, Map<String, Drawable>> {
164 164
         private final List<Button> mOldButtons;
165 165
         private final List<Button> mNewButtons;