Browse Source

Misc ToolBar fixes

Minor refactor after merging #52.
Guy Carmeli 8 years ago
parent
commit
923dd6eddf

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

219
     @CallSuper
219
     @CallSuper
220
     public void push(Screen screen) {
220
     public void push(Screen screen) {
221
         setNavigationStyle(screen);
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 View File

63
     }
63
     }
64
 
64
 
65
     private void setupToolbar(ArrayList<Screen> screens) {
65
     private void setupToolbar(ArrayList<Screen> screens) {
66
-        Screen initialScreen = screens.get(0);
67
         mToolbar.setScreens(screens);
66
         mToolbar.setScreens(screens);
68
-        mToolbar.updateToolbar(initialScreen);
67
+        Screen initialScreen = screens.get(0);
68
+        mToolbar.update(initialScreen);
69
         setNavigationStyle(initialScreen);
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
     private void setupTabs(Bundle style) {
72
     private void setupTabs(Bundle style) {
79
 
73
 
80
         mBottomNavigation.setForceTitlesDisplay(style.getBoolean(TAB_STYLE_INACTIVE_TITLES, DEFAULT_TAB_INACTIVE_TITLES));
74
         mBottomNavigation.setForceTitlesDisplay(style.getBoolean(TAB_STYLE_INACTIVE_TITLES, DEFAULT_TAB_INACTIVE_TITLES));
103
     @Override
97
     @Override
104
     public void push(Screen screen) {
98
     public void push(Screen screen) {
105
         super.push(screen);
99
         super.push(screen);
106
-        setNavigationStyle(screen);
107
         mScreenStacks.get(mCurrentStackPosition).push(screen);
100
         mScreenStacks.get(mCurrentStackPosition).push(screen);
108
     }
101
     }
109
 
102
 
111
     public Screen pop(String navigatorId) {
104
     public Screen pop(String navigatorId) {
112
         super.pop(navigatorId);
105
         super.pop(navigatorId);
113
         Screen screen = mScreenStacks.get(mCurrentStackPosition).pop();
106
         Screen screen = mScreenStacks.get(mCurrentStackPosition).pop();
114
-        setNavigationStyle(getCurrentScreen());
107
+        Screen currentScreen = getCurrentScreen();
108
+        setNavigationStyle(currentScreen);
109
+        mToolbar.update(currentScreen);
115
         return screen;
110
         return screen;
116
     }
111
     }
117
 
112
 

+ 4
- 3
android/app/src/main/java/com/reactnativenavigation/activities/SingleScreenActivity.java View File

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

+ 3
- 1
android/app/src/main/java/com/reactnativenavigation/activities/TabActivity.java View File

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

+ 12
- 14
android/app/src/main/java/com/reactnativenavigation/modal/RnnModal.java View File

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

23
 import com.reactnativenavigation.utils.ImageUtils;
23
 import com.reactnativenavigation.utils.ImageUtils;
24
 
24
 
25
 import java.lang.ref.WeakReference;
25
 import java.lang.ref.WeakReference;
26
-import java.util.Collections;
27
 import java.util.HashMap;
26
 import java.util.HashMap;
28
 import java.util.List;
27
 import java.util.List;
29
 import java.util.Map;
28
 import java.util.Map;
148
         ContextProvider.getActivityContext().getSupportActionBar().setDisplayHomeAsUpEnabled(false);
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
     @UiThread
155
     @UiThread
152
-    public void updateToolbar(Screen screen) {
153
-        setSupportActionBar();
156
+    public void update(Screen screen) {
157
+        ((AppCompatActivity) getContext()).setSupportActionBar(this);
154
         setTitle(screen.title);
158
         setTitle(screen.title);
155
         setStyle(screen);
159
         setStyle(screen);
156
         setupToolbarButtonsAsync(screen);
160
         setupToolbarButtonsAsync(screen);
157
     }
161
     }
158
 
162
 
159
-    private void setSupportActionBar() {
160
-        ((AppCompatActivity) getContext()).setSupportActionBar(this);
161
-    }
162
-
163
     private static class SetupToolbarButtonsTask extends AsyncTask<Void, Void, Map<String, Drawable>> {
163
     private static class SetupToolbarButtonsTask extends AsyncTask<Void, Void, Map<String, Drawable>> {
164
         private final List<Button> mOldButtons;
164
         private final List<Button> mOldButtons;
165
         private final List<Button> mNewButtons;
165
         private final List<Button> mNewButtons;