Browse Source

merged from master

Daniel Zlotin 8 years ago
parent
commit
790cc607ff

+ 1
- 0
.npmignore View File

@@ -153,6 +153,7 @@ fastlane/screenshots
153 153
 android/bin/
154 154
 android/gen/
155 155
 android/out/
156
+android/app/build/
156 157
 
157 158
 # Gradle files
158 159
 android/.gradle/

+ 1
- 1
README.md View File

@@ -173,7 +173,7 @@ Navigation.startTabBasedApp({
173 173
     {
174 174
       label: 'One', // tab label as appears under the icon in iOS (optional)
175 175
       screen: 'example.FirstTabScreen', // unique ID registered with Navigation.registerScreen
176
-      icon: require('../img/one.png'), // local image asset for the tab icon unselected state (optional)
176
+      icon: require('../img/one.png'), // local image asset for the tab icon unselected state (optional on iOS)
177 177
       selectedIcon: require('../img/one_selected.png'), // local image asset for the tab icon selected state (optional)
178 178
       title: 'Screen One', // title of the screen as appears in the nav bar (optional)
179 179
       navigatorStyle: {}, // override the navigator style for the tab screen, see "Styling the navigator" below (optional),

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

@@ -1,9 +1,6 @@
1 1
 package com.reactnativenavigation.activities;
2 2
 
3
-import android.content.BroadcastReceiver;
4
-import android.content.Context;
5 3
 import android.content.Intent;
6
-import android.content.IntentFilter;
7 4
 import android.content.res.Configuration;
8 5
 import android.os.Build;
9 6
 import android.os.Bundle;
@@ -29,7 +26,6 @@ import com.facebook.react.bridge.Arguments;
29 26
 import com.facebook.react.bridge.ReadableMap;
30 27
 import com.facebook.react.bridge.WritableMap;
31 28
 import com.facebook.react.common.ReactConstants;
32
-import com.facebook.react.devsupport.DevServerHelper;
33 29
 import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
34 30
 import com.facebook.react.shell.MainReactPackage;
35 31
 import com.reactnativenavigation.BuildConfig;
@@ -299,7 +295,7 @@ public abstract class BaseReactActivity extends AppCompatActivity implements Def
299 295
     public boolean onCreateOptionsMenu(Menu menu) {
300 296
         mMenu = menu;
301 297
         Screen currentScreen = getCurrentScreen();
302
-        if (mToolbar != null && currentScreen != null) {
298
+        if (mToolbar != null && currentScreen != null && !isFinishing()) {
303 299
             mToolbar.setupToolbarButtonsAsync(currentScreen);
304 300
         }
305 301
         return super.onCreateOptionsMenu(menu);
@@ -384,14 +380,18 @@ public abstract class BaseReactActivity extends AppCompatActivity implements Def
384 380
 
385 381
     @Override
386 382
     public void onBackPressed() {
383
+        ModalController modalController = ModalController.getInstance();
384
+        if (modalController.isModalDisplayed()) {
385
+            modalController.dismissModal();
386
+            return;
387
+        }
388
+
387 389
         if (getScreenStackSize() > 1) {
388 390
             pop(getCurrentNavigatorId());
391
+        } else if (mReactInstanceManager != null) {
392
+            mReactInstanceManager.onBackPressed();
389 393
         } else {
390
-            if (mReactInstanceManager != null) {
391
-                mReactInstanceManager.onBackPressed();
392
-            } else {
393
-                super.onBackPressed();
394
-            }
394
+            super.onBackPressed();
395 395
         }
396 396
     }
397 397
 

+ 32
- 11
android/app/src/main/java/com/reactnativenavigation/activities/BottomTabActivity.java View File

@@ -5,6 +5,7 @@ import android.graphics.drawable.Drawable;
5 5
 import android.os.AsyncTask;
6 6
 import android.os.Bundle;
7 7
 import android.view.Menu;
8
+import android.view.View;
8 9
 import android.widget.FrameLayout;
9 10
 
10 11
 import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
@@ -102,13 +103,6 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
102 103
         }
103 104
     }
104 105
 
105
-    @Override
106
-    public boolean onCreateOptionsMenu(Menu menu) {
107
-        boolean ret = super.onCreateOptionsMenu(menu);
108
-        mToolbar.handleOnCreateOptionsMenuAsync();
109
-        return ret;
110
-    }
111
-
112 106
     @Override
113 107
     public void push(Screen screen) {
114 108
         super.push(screen);
@@ -118,6 +112,10 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
118 112
             }
119 113
         }
120 114
         StyleHelper.updateStyles(mToolbar, getCurrentScreen());
115
+
116
+        if (shouldToggleTabs(screen)) {
117
+            toggleTabs(screen.bottomTabsHidden, false);
118
+        }
121 119
     }
122 120
 
123 121
     @Override
@@ -126,7 +124,13 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
126 124
         for (ScreenStack stack : mScreenStacks) {
127 125
             if (stack.peek().navigatorId.equals(navigatorId)) {
128 126
                 Screen popped = stack.pop();
129
-                StyleHelper.updateStyles(mToolbar, getCurrentScreen());
127
+                Screen currentScreen = getCurrentScreen();
128
+                StyleHelper.updateStyles(mToolbar, currentScreen);
129
+
130
+                if (shouldToggleTabs(currentScreen)) {
131
+                    toggleTabs(currentScreen.bottomTabsHidden, false);
132
+                }
133
+
130 134
                 return popped;
131 135
             }
132 136
         }
@@ -139,7 +143,13 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
139 143
         for (ScreenStack stack : mScreenStacks) {
140 144
             if (stack.peek().navigatorId.equals(navigatorId)) {
141 145
                 Screen popped = stack.popToRoot();
142
-                StyleHelper.updateStyles(mToolbar, getCurrentScreen());
146
+                Screen currentScreen = getCurrentScreen();
147
+                StyleHelper.updateStyles(mToolbar, currentScreen);
148
+
149
+                if (shouldToggleTabs(currentScreen)) {
150
+                    toggleTabs(currentScreen.bottomTabsHidden, false);
151
+                }
152
+
143 153
                 return popped;
144 154
             }
145 155
         }
@@ -225,13 +235,24 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
225 235
     public void toggleTabs(ReadableMap params) {
226 236
         boolean hide = params.getBoolean(KEY_HIDDEN);
227 237
         boolean animated = params.getBoolean(KEY_ANIMATED);
238
+        toggleTabs(hide, animated);
239
+    }
240
+
241
+    // TODO: support animated = false -guyca
242
+    private void toggleTabs(boolean hide, boolean animated) {
228 243
         if (hide) {
229
-            mBottomNavigation.hideBottomNavigation(animated);
244
+//            mBottomNavigation.hideBottomNavigation(animated);
245
+            mBottomNavigation.setVisibility(View.GONE);
230 246
         } else {
231
-            mBottomNavigation.restoreBottomNavigation(animated);
247
+            mBottomNavigation.setVisibility(View.VISIBLE);
248
+//            mBottomNavigation.restoreBottomNavigation(animated);
232 249
         }
233 250
     }
234 251
 
252
+    private boolean shouldToggleTabs(Screen newScreen) {
253
+        return mBottomNavigation.isShown() == newScreen.bottomTabsHidden;
254
+    }
255
+
235 256
     private static class SetupTabsTask extends AsyncTask<Void, Void, Map<Screen, Drawable>> {
236 257
         private BottomTabActivity mActivity;
237 258
         private RnnToolBar mToolBar;

+ 4
- 2
android/app/src/main/java/com/reactnativenavigation/activities/RootActivity.java View File

@@ -18,8 +18,10 @@ public class RootActivity extends BaseReactActivity {
18 18
     @Override
19 19
     protected void handleOnCreate() {
20 20
         super.handleOnCreate();
21
-        // Trigger react context initialization, global javascript code will now execute
22
-        getReactInstanceManager().createReactContextInBackground();
21
+        if (!getReactInstanceManager().hasStartedCreatingInitialContext()) {
22
+            // Trigger react context initialization, global javascript code will now execute
23
+            getReactInstanceManager().createReactContextInBackground();
24
+        }
23 25
     }
24 26
 
25 27
     @Override

+ 0
- 1
android/app/src/main/java/com/reactnativenavigation/activities/SingleScreenActivity.java View File

@@ -49,7 +49,6 @@ public class SingleScreenActivity extends BaseReactActivity {
49 49
     }
50 50
 
51 51
     protected void setupToolbar(Screen screen) {
52
-        mToolbar.update(screen);
53 52
         StyleHelper.updateStyles(mToolbar, screen);
54 53
     }
55 54
 

+ 3
- 0
android/app/src/main/java/com/reactnativenavigation/core/RctManager.java View File

@@ -25,6 +25,8 @@ import static com.facebook.react.modules.core.DeviceEventManagerModule.RCTDevice
25 25
 public class RctManager {
26 26
     private static final String TAG = "RctManager";
27 27
     private static final String KEY_EVENT_ID = "id";
28
+    private static final String KEY_EVENT_TYPE = "type";
29
+    private static final String EVENT_TYPE = "NavBarButtonPress";
28 30
     private static RctManager sInstance;
29 31
 
30 32
     private ReactInstanceManager mReactManager;
@@ -136,6 +138,7 @@ public class RctManager {
136 138
             return;
137 139
         }
138 140
 
141
+        params.putString(KEY_EVENT_TYPE, EVENT_TYPE);
139 142
         params.putString(KEY_EVENT_ID, eventName);
140 143
         params.putString(Screen.KEY_NAVIGATOR_EVENT_ID, screen.navigatorEventId);
141 144
         eventEmitter.emit(screen.navigatorEventId, params);

+ 3
- 0
android/app/src/main/java/com/reactnativenavigation/core/objects/Screen.java View File

@@ -43,6 +43,7 @@ public class Screen extends JsonObject implements Serializable {
43 43
     private static final String KEY_TAB_NORMAL_TEXT_COLOR = "tabNormalTextColor";
44 44
     private static final String KEY_TAB_SELECTED_TEXT_COLOR = "tabSelectedTextColor";
45 45
     private static final String KEY_TAB_INDICATOR_COLOR = "tabIndicatorColor";
46
+    private static final String KEY_BOTTOM_TABS_HIDDEN = "tabBarHidden";
46 47
     private static final String KEY_PROPS = "passProps";
47 48
 
48 49
     public String title;
@@ -66,6 +67,7 @@ public class Screen extends JsonObject implements Serializable {
66 67
     @Nullable @ColorInt public Integer tabNormalTextColor;
67 68
     @Nullable @ColorInt public Integer tabSelectedTextColor;
68 69
     @Nullable @ColorInt public Integer tabIndicatorColor;
70
+    public Boolean bottomTabsHidden;
69 71
 
70 72
     @NonNull
71 73
     public List<Button> getButtons() {
@@ -132,6 +134,7 @@ public class Screen extends JsonObject implements Serializable {
132 134
             tabNormalTextColor = getColor(style, KEY_TAB_NORMAL_TEXT_COLOR);
133 135
             tabSelectedTextColor = getColor(style, KEY_TAB_SELECTED_TEXT_COLOR);
134 136
             tabIndicatorColor = getColor(style, KEY_TAB_INDICATOR_COLOR);
137
+            bottomTabsHidden = getBoolean(style, KEY_BOTTOM_TABS_HIDDEN);
135 138
         }
136 139
     }
137 140
 }

+ 3
- 1
android/app/src/main/java/com/reactnativenavigation/utils/ContextProvider.java View File

@@ -1,5 +1,7 @@
1 1
 package com.reactnativenavigation.utils;
2 2
 
3
+import android.support.annotation.Nullable;
4
+
3 5
 import com.reactnativenavigation.activities.BaseReactActivity;
4 6
 
5 7
 import java.lang.ref.WeakReference;
@@ -19,7 +21,7 @@ public class ContextProvider {
19 21
     /**
20 22
      * Returns the currently resumed activity or {@code null} if there is none.
21 23
      */
22
-    public static BaseReactActivity getActivityContext() {
24
+    public static @Nullable BaseReactActivity getActivityContext() {
23 25
         return sActivityWR != null ? sActivityWR.get() : null;
24 26
     }
25 27
 

+ 0
- 1
android/app/src/main/java/com/reactnativenavigation/utils/StyleHelper.java View File

@@ -18,7 +18,6 @@ public class StyleHelper {
18 18
         try {
19 19
             toolBar.updateAndSetButtons(screen);
20 20
             setWindowStyle(screen);
21
-            toolBar.setupToolbarButtonsAsync(screen);
22 21
         } catch (Exception e) {
23 22
             Log.w("RNNavigation", "Tried to update styles with no screen!");
24 23
         }

+ 7
- 2
android/app/src/main/java/com/reactnativenavigation/views/RnnToolBar.java View File

@@ -212,7 +212,12 @@ public class RnnToolBar extends Toolbar {
212 212
 
213 213
     @SuppressWarnings({"ConstantConditions"})
214 214
     public void setNavUpButton(Screen screen) {
215
-        ActionBar actionBar = ContextProvider.getActivityContext().getSupportActionBar();
215
+        BaseReactActivity context = ContextProvider.getActivityContext();
216
+        if (context == null) {
217
+            return;
218
+        }
219
+
220
+        ActionBar actionBar = context.getSupportActionBar();
216 221
         if (actionBar == null) {
217 222
             return;
218 223
         }
@@ -226,7 +231,7 @@ public class RnnToolBar extends Toolbar {
226 231
             navArrow = (DrawerArrowDrawable) this.getNavigationIcon();
227 232
         } else {
228 233
             if (isBack && !screen.backButtonHidden) {
229
-                navArrow = new DrawerArrowDrawable(ContextProvider.getActivityContext());
234
+                navArrow = new DrawerArrowDrawable(context);
230 235
             } else if (hasDrawer) {
231 236
                 navIcon = mDrawerIcon;
232 237
             }

+ 14
- 6
src/platformSpecific.android.js View File

@@ -33,12 +33,7 @@ function startTabBasedApp(params) {
33 33
     addNavigatorParams(tab, null, idx);
34 34
     addNavigatorButtons(tab);
35 35
     addNavigationStyleParams(tab);
36
-    if (tab.icon) {
37
-      const icon = resolveAssetSource(tab.icon);
38
-      if (icon) {
39
-        tab.icon = icon.uri;
40
-      }
41
-    }
36
+    addTabIcon(tab);
42 37
     tab.passProps = params.passProps;
43 38
   });
44 39
 
@@ -46,6 +41,19 @@ function startTabBasedApp(params) {
46 41
   RctActivity.startTabBasedApp(params.tabs, params.tabsStyle, drawer);
47 42
 }
48 43
 
44
+function addTabIcon(tab) {
45
+  if (tab.icon) {
46
+    const icon = resolveAssetSource(tab.icon);
47
+    if (icon) {
48
+      tab.icon = icon.uri;
49
+    }
50
+  }
51
+
52
+  if (!tab.icon) {
53
+    throw new Error("No icon defined for tab " + tab.screen);
54
+  }
55
+}
56
+
49 57
 function navigatorPush(navigator, params) {
50 58
   addNavigatorParams(params, navigator);
51 59
   addNavigatorButtons(params);