Browse Source

Fixed issues in Android

Toolbar buttons not updating
Pushes into BottomTabActivity not always working
Modal not closing properly when back pressed
Yedidya Kennard 8 years ago
parent
commit
cf4a284ab9

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

190
         }
190
         }
191
     }
191
     }
192
 
192
 
193
+    public void updateStyles() {
194
+        try {
195
+            mToolbar.update(getCurrentScreen());
196
+            setNavigationStyle(getCurrentScreen());
197
+            mToolbar.setupToolbarButtonsAsync(getCurrentScreen());
198
+        } catch (Exception e) {
199
+            Log.w("RNNavigation", "Tried to update styles with no screen!");
200
+        }
201
+    }
202
+
193
     @Override
203
     @Override
194
     protected void onPause() {
204
     protected void onPause() {
195
         super.onPause();
205
         super.onPause();

+ 17
- 5
android/app/src/main/java/com/reactnativenavigation/activities/BottomTabActivity.java View File

69
         setNavigationStyle(initialScreen);
69
         setNavigationStyle(initialScreen);
70
     }
70
     }
71
 
71
 
72
-    private void setupTabs(Bundle style) {
72
+    @Override
73
+    protected void onResume() {
74
+        super.onResume();
75
+        if(mScreenStacks != null) {
76
+            updateStyles();
77
+        }
78
+    }
73
 
79
 
80
+    private void setupTabs(Bundle style) {
74
         mBottomNavigation.setForceTitlesDisplay(style.getBoolean(TAB_STYLE_INACTIVE_TITLES, DEFAULT_TAB_INACTIVE_TITLES));
81
         mBottomNavigation.setForceTitlesDisplay(style.getBoolean(TAB_STYLE_INACTIVE_TITLES, DEFAULT_TAB_INACTIVE_TITLES));
75
         mBottomNavigation.setForceTint(true);
82
         mBottomNavigation.setForceTint(true);
76
         mBottomNavigation.setDefaultBackgroundColor(getColor(style, TAB_STYLE_BAR_BG_COLOR, DEFAULT_TAB_BAR_BG_COLOR));
83
         mBottomNavigation.setDefaultBackgroundColor(getColor(style, TAB_STYLE_BAR_BG_COLOR, DEFAULT_TAB_BAR_BG_COLOR));
97
     @Override
104
     @Override
98
     public void push(Screen screen) {
105
     public void push(Screen screen) {
99
         super.push(screen);
106
         super.push(screen);
100
-        mScreenStacks.get(mCurrentStackPosition).push(screen);
107
+        for (ScreenStack stack : mScreenStacks) {
108
+            if (stack.peek().navigatorId.equals(screen.navigatorId)) {
109
+                stack.push(screen);
110
+            }
111
+        }
112
+        updateStyles();
101
     }
113
     }
102
 
114
 
103
     @Override
115
     @Override
106
         for (ScreenStack stack: mScreenStacks) {
118
         for (ScreenStack stack: mScreenStacks) {
107
             if (stack.peek().navigatorId.equals(navigatorId)) {
119
             if (stack.peek().navigatorId.equals(navigatorId)) {
108
                 Screen popped = stack.pop();
120
                 Screen popped = stack.pop();
109
-                setNavigationStyle(getCurrentScreen());
121
+                updateStyles();
110
                 return popped;
122
                 return popped;
111
             }
123
             }
112
         }
124
         }
136
         mContentFrame.removeAllViews();
148
         mContentFrame.removeAllViews();
137
         mContentFrame.addView(mScreenStacks.get(position), new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
149
         mContentFrame.addView(mScreenStacks.get(position), new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
138
         mCurrentStackPosition = position;
150
         mCurrentStackPosition = position;
139
-        mToolbar.setupToolbarButtonsAsync(getCurrentScreen());
140
-        setNavigationStyle(getCurrentScreen());
151
+        updateStyles();
141
     }
152
     }
142
 
153
 
143
     private static class SetupTabsTask extends AsyncTask<Void, Void, Map<Screen, Drawable>> {
154
     private static class SetupTabsTask extends AsyncTask<Void, Void, Map<Screen, Drawable>> {
163
         @Override
174
         @Override
164
         protected void onPostExecute(Map<Screen, Drawable> icons) {
175
         protected void onPostExecute(Map<Screen, Drawable> icons) {
165
             mActivity.setTabsWithIcons(mScreens, icons);
176
             mActivity.setTabsWithIcons(mScreens, icons);
177
+            mActivity.updateStyles();
166
         }
178
         }
167
     }
179
     }
168
 
180
 

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

44
     public void push(Screen screen) {
44
     public void push(Screen screen) {
45
         super.push(screen);
45
         super.push(screen);
46
         mScreenStack.push(screen);
46
         mScreenStack.push(screen);
47
+        updateStyles();
47
     }
48
     }
48
 
49
 
49
     @Override
50
     @Override
50
     public Screen pop(String navigatorId) {
51
     public Screen pop(String navigatorId) {
51
         super.pop(navigatorId);
52
         super.pop(navigatorId);
52
         Screen screen = mScreenStack.pop();
53
         Screen screen = mScreenStack.pop();
53
-        Screen currentScreen = getCurrentScreen();
54
-        setNavigationStyle(currentScreen);
55
-        mToolbar.update(currentScreen);
54
+        updateStyles();
56
         return screen;
55
         return screen;
57
     }
56
     }
58
 
57
 

+ 4
- 7
android/app/src/main/java/com/reactnativenavigation/modal/RnnModal.java View File

15
 import com.reactnativenavigation.activities.BaseReactActivity;
15
 import com.reactnativenavigation.activities.BaseReactActivity;
16
 import com.reactnativenavigation.controllers.ModalController;
16
 import com.reactnativenavigation.controllers.ModalController;
17
 import com.reactnativenavigation.core.objects.Screen;
17
 import com.reactnativenavigation.core.objects.Screen;
18
+import com.reactnativenavigation.utils.ContextProvider;
18
 import com.reactnativenavigation.utils.SdkSupports;
19
 import com.reactnativenavigation.utils.SdkSupports;
19
 import com.reactnativenavigation.utils.StyleHelper;
20
 import com.reactnativenavigation.utils.StyleHelper;
20
 import com.reactnativenavigation.views.RctView;
21
 import com.reactnativenavigation.views.RctView;
59
             window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
60
             window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
60
             StyleHelper.setWindowStyle(window, context.getApplicationContext(), screen);
61
             StyleHelper.setWindowStyle(window, context.getApplicationContext(), screen);
61
         }
62
         }
63
+        setOnDismissListener(this);
62
     }
64
     }
63
 
65
 
64
     public void push(Screen screen) {
66
     public void push(Screen screen) {
69
     public Screen pop() {
71
     public Screen pop() {
70
         Screen popped = mScreenStack.pop();
72
         Screen popped = mScreenStack.pop();
71
         if (mScreenStack.isEmpty()) {
73
         if (mScreenStack.isEmpty()) {
72
-            ModalController.getInstance().remove();
73
             dismiss();
74
             dismiss();
74
         }
75
         }
75
         return popped;
76
         return popped;
77
 
78
 
78
     @Override
79
     @Override
79
     public void onBackPressed() {
80
     public void onBackPressed() {
80
-        if (mScreenStack.isEmpty()) {
81
-            ModalController.getInstance().remove();
82
-            super.onBackPressed();
83
-        } else {
84
-            mScreenStack.pop();
85
-        }
81
+        pop();
86
     }
82
     }
87
 
83
 
88
     @Override
84
     @Override
89
     public void onDismiss(DialogInterface dialog) {
85
     public void onDismiss(DialogInterface dialog) {
90
         ModalController.getInstance().remove();
86
         ModalController.getInstance().remove();
87
+        ContextProvider.getActivityContext().updateStyles();
91
     }
88
     }
92
 }
89
 }

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

12
 import com.facebook.react.bridge.ReadableNativeMap;
12
 import com.facebook.react.bridge.ReadableNativeMap;
13
 import com.reactnativenavigation.activities.BaseReactActivity;
13
 import com.reactnativenavigation.activities.BaseReactActivity;
14
 import com.reactnativenavigation.activities.BottomTabActivity;
14
 import com.reactnativenavigation.activities.BottomTabActivity;
15
+import com.reactnativenavigation.activities.RootActivity;
15
 import com.reactnativenavigation.activities.SingleScreenActivity;
16
 import com.reactnativenavigation.activities.SingleScreenActivity;
16
 import com.reactnativenavigation.controllers.ModalController;
17
 import com.reactnativenavigation.controllers.ModalController;
17
 import com.reactnativenavigation.core.objects.Screen;
18
 import com.reactnativenavigation.core.objects.Screen;
51
             intent.putExtras(extras);
52
             intent.putExtras(extras);
52
             
53
             
53
             context.startActivity(intent);
54
             context.startActivity(intent);
55
+            //TODO add abstract isRoot() instead of instanceof?
56
+            if(ContextProvider.getActivityContext() instanceof RootActivity) {
57
+                context.overridePendingTransition(0, 0);
58
+            }
54
         }
59
         }
55
     }
60
     }
56
 
61
 
74
             intent.putExtras(extras);
79
             intent.putExtras(extras);
75
 
80
 
76
             context.startActivity(intent);
81
             context.startActivity(intent);
82
+            if(ContextProvider.getActivityContext() instanceof RootActivity) {
83
+                context.overridePendingTransition(0, 0);
84
+            }
77
         }
85
         }
78
     }
86
     }
79
 
87