Parcourir la source

Fixed issues in Android

Toolbar buttons not updating
Pushes into BottomTabActivity not always working
Modal not closing properly when back pressed
Yedidya Kennard il y a 8 ans
Parent
révision
cf4a284ab9

+ 10
- 0
android/app/src/main/java/com/reactnativenavigation/activities/BaseReactActivity.java Voir le fichier

@@ -190,6 +190,16 @@ public abstract class BaseReactActivity extends AppCompatActivity implements Def
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 203
     @Override
194 204
     protected void onPause() {
195 205
         super.onPause();

+ 17
- 5
android/app/src/main/java/com/reactnativenavigation/activities/BottomTabActivity.java Voir le fichier

@@ -69,8 +69,15 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
69 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 81
         mBottomNavigation.setForceTitlesDisplay(style.getBoolean(TAB_STYLE_INACTIVE_TITLES, DEFAULT_TAB_INACTIVE_TITLES));
75 82
         mBottomNavigation.setForceTint(true);
76 83
         mBottomNavigation.setDefaultBackgroundColor(getColor(style, TAB_STYLE_BAR_BG_COLOR, DEFAULT_TAB_BAR_BG_COLOR));
@@ -97,7 +104,12 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
97 104
     @Override
98 105
     public void push(Screen screen) {
99 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 115
     @Override
@@ -106,7 +118,7 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
106 118
         for (ScreenStack stack: mScreenStacks) {
107 119
             if (stack.peek().navigatorId.equals(navigatorId)) {
108 120
                 Screen popped = stack.pop();
109
-                setNavigationStyle(getCurrentScreen());
121
+                updateStyles();
110 122
                 return popped;
111 123
             }
112 124
         }
@@ -136,8 +148,7 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
136 148
         mContentFrame.removeAllViews();
137 149
         mContentFrame.addView(mScreenStacks.get(position), new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
138 150
         mCurrentStackPosition = position;
139
-        mToolbar.setupToolbarButtonsAsync(getCurrentScreen());
140
-        setNavigationStyle(getCurrentScreen());
151
+        updateStyles();
141 152
     }
142 153
 
143 154
     private static class SetupTabsTask extends AsyncTask<Void, Void, Map<Screen, Drawable>> {
@@ -163,6 +174,7 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
163 174
         @Override
164 175
         protected void onPostExecute(Map<Screen, Drawable> icons) {
165 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 Voir le fichier

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

+ 4
- 7
android/app/src/main/java/com/reactnativenavigation/modal/RnnModal.java Voir le fichier

@@ -15,6 +15,7 @@ import com.reactnativenavigation.R;
15 15
 import com.reactnativenavigation.activities.BaseReactActivity;
16 16
 import com.reactnativenavigation.controllers.ModalController;
17 17
 import com.reactnativenavigation.core.objects.Screen;
18
+import com.reactnativenavigation.utils.ContextProvider;
18 19
 import com.reactnativenavigation.utils.SdkSupports;
19 20
 import com.reactnativenavigation.utils.StyleHelper;
20 21
 import com.reactnativenavigation.views.RctView;
@@ -59,6 +60,7 @@ public class RnnModal extends Dialog implements DialogInterface.OnDismissListene
59 60
             window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
60 61
             StyleHelper.setWindowStyle(window, context.getApplicationContext(), screen);
61 62
         }
63
+        setOnDismissListener(this);
62 64
     }
63 65
 
64 66
     public void push(Screen screen) {
@@ -69,7 +71,6 @@ public class RnnModal extends Dialog implements DialogInterface.OnDismissListene
69 71
     public Screen pop() {
70 72
         Screen popped = mScreenStack.pop();
71 73
         if (mScreenStack.isEmpty()) {
72
-            ModalController.getInstance().remove();
73 74
             dismiss();
74 75
         }
75 76
         return popped;
@@ -77,16 +78,12 @@ public class RnnModal extends Dialog implements DialogInterface.OnDismissListene
77 78
 
78 79
     @Override
79 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 84
     @Override
89 85
     public void onDismiss(DialogInterface dialog) {
90 86
         ModalController.getInstance().remove();
87
+        ContextProvider.getActivityContext().updateStyles();
91 88
     }
92 89
 }

+ 8
- 0
android/app/src/main/java/com/reactnativenavigation/modules/RctActivityModule.java Voir le fichier

@@ -12,6 +12,7 @@ import com.facebook.react.bridge.ReadableMap;
12 12
 import com.facebook.react.bridge.ReadableNativeMap;
13 13
 import com.reactnativenavigation.activities.BaseReactActivity;
14 14
 import com.reactnativenavigation.activities.BottomTabActivity;
15
+import com.reactnativenavigation.activities.RootActivity;
15 16
 import com.reactnativenavigation.activities.SingleScreenActivity;
16 17
 import com.reactnativenavigation.controllers.ModalController;
17 18
 import com.reactnativenavigation.core.objects.Screen;
@@ -51,6 +52,10 @@ public class RctActivityModule extends ReactContextBaseJavaModule {
51 52
             intent.putExtras(extras);
52 53
             
53 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,6 +79,9 @@ public class RctActivityModule extends ReactContextBaseJavaModule {
74 79
             intent.putExtras(extras);
75 80
 
76 81
             context.startActivity(intent);
82
+            if(ContextProvider.getActivityContext() instanceof RootActivity) {
83
+                context.overridePendingTransition(0, 0);
84
+            }
77 85
         }
78 86
     }
79 87