Browse Source

merged from master

Daniel Zlotin 8 years ago
parent
commit
790cc607ff

+ 1
- 0
.npmignore View File

153
 android/bin/
153
 android/bin/
154
 android/gen/
154
 android/gen/
155
 android/out/
155
 android/out/
156
+android/app/build/
156
 
157
 
157
 # Gradle files
158
 # Gradle files
158
 android/.gradle/
159
 android/.gradle/

+ 1
- 1
README.md View File

173
     {
173
     {
174
       label: 'One', // tab label as appears under the icon in iOS (optional)
174
       label: 'One', // tab label as appears under the icon in iOS (optional)
175
       screen: 'example.FirstTabScreen', // unique ID registered with Navigation.registerScreen
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
       selectedIcon: require('../img/one_selected.png'), // local image asset for the tab icon selected state (optional)
177
       selectedIcon: require('../img/one_selected.png'), // local image asset for the tab icon selected state (optional)
178
       title: 'Screen One', // title of the screen as appears in the nav bar (optional)
178
       title: 'Screen One', // title of the screen as appears in the nav bar (optional)
179
       navigatorStyle: {}, // override the navigator style for the tab screen, see "Styling the navigator" below (optional),
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
 package com.reactnativenavigation.activities;
1
 package com.reactnativenavigation.activities;
2
 
2
 
3
-import android.content.BroadcastReceiver;
4
-import android.content.Context;
5
 import android.content.Intent;
3
 import android.content.Intent;
6
-import android.content.IntentFilter;
7
 import android.content.res.Configuration;
4
 import android.content.res.Configuration;
8
 import android.os.Build;
5
 import android.os.Build;
9
 import android.os.Bundle;
6
 import android.os.Bundle;
29
 import com.facebook.react.bridge.ReadableMap;
26
 import com.facebook.react.bridge.ReadableMap;
30
 import com.facebook.react.bridge.WritableMap;
27
 import com.facebook.react.bridge.WritableMap;
31
 import com.facebook.react.common.ReactConstants;
28
 import com.facebook.react.common.ReactConstants;
32
-import com.facebook.react.devsupport.DevServerHelper;
33
 import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
29
 import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
34
 import com.facebook.react.shell.MainReactPackage;
30
 import com.facebook.react.shell.MainReactPackage;
35
 import com.reactnativenavigation.BuildConfig;
31
 import com.reactnativenavigation.BuildConfig;
299
     public boolean onCreateOptionsMenu(Menu menu) {
295
     public boolean onCreateOptionsMenu(Menu menu) {
300
         mMenu = menu;
296
         mMenu = menu;
301
         Screen currentScreen = getCurrentScreen();
297
         Screen currentScreen = getCurrentScreen();
302
-        if (mToolbar != null && currentScreen != null) {
298
+        if (mToolbar != null && currentScreen != null && !isFinishing()) {
303
             mToolbar.setupToolbarButtonsAsync(currentScreen);
299
             mToolbar.setupToolbarButtonsAsync(currentScreen);
304
         }
300
         }
305
         return super.onCreateOptionsMenu(menu);
301
         return super.onCreateOptionsMenu(menu);
384
 
380
 
385
     @Override
381
     @Override
386
     public void onBackPressed() {
382
     public void onBackPressed() {
383
+        ModalController modalController = ModalController.getInstance();
384
+        if (modalController.isModalDisplayed()) {
385
+            modalController.dismissModal();
386
+            return;
387
+        }
388
+
387
         if (getScreenStackSize() > 1) {
389
         if (getScreenStackSize() > 1) {
388
             pop(getCurrentNavigatorId());
390
             pop(getCurrentNavigatorId());
391
+        } else if (mReactInstanceManager != null) {
392
+            mReactInstanceManager.onBackPressed();
389
         } else {
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
 import android.os.AsyncTask;
5
 import android.os.AsyncTask;
6
 import android.os.Bundle;
6
 import android.os.Bundle;
7
 import android.view.Menu;
7
 import android.view.Menu;
8
+import android.view.View;
8
 import android.widget.FrameLayout;
9
 import android.widget.FrameLayout;
9
 
10
 
10
 import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
11
 import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
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
     @Override
106
     @Override
113
     public void push(Screen screen) {
107
     public void push(Screen screen) {
114
         super.push(screen);
108
         super.push(screen);
118
             }
112
             }
119
         }
113
         }
120
         StyleHelper.updateStyles(mToolbar, getCurrentScreen());
114
         StyleHelper.updateStyles(mToolbar, getCurrentScreen());
115
+
116
+        if (shouldToggleTabs(screen)) {
117
+            toggleTabs(screen.bottomTabsHidden, false);
118
+        }
121
     }
119
     }
122
 
120
 
123
     @Override
121
     @Override
126
         for (ScreenStack stack : mScreenStacks) {
124
         for (ScreenStack stack : mScreenStacks) {
127
             if (stack.peek().navigatorId.equals(navigatorId)) {
125
             if (stack.peek().navigatorId.equals(navigatorId)) {
128
                 Screen popped = stack.pop();
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
                 return popped;
134
                 return popped;
131
             }
135
             }
132
         }
136
         }
139
         for (ScreenStack stack : mScreenStacks) {
143
         for (ScreenStack stack : mScreenStacks) {
140
             if (stack.peek().navigatorId.equals(navigatorId)) {
144
             if (stack.peek().navigatorId.equals(navigatorId)) {
141
                 Screen popped = stack.popToRoot();
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
                 return popped;
153
                 return popped;
144
             }
154
             }
145
         }
155
         }
225
     public void toggleTabs(ReadableMap params) {
235
     public void toggleTabs(ReadableMap params) {
226
         boolean hide = params.getBoolean(KEY_HIDDEN);
236
         boolean hide = params.getBoolean(KEY_HIDDEN);
227
         boolean animated = params.getBoolean(KEY_ANIMATED);
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
         if (hide) {
243
         if (hide) {
229
-            mBottomNavigation.hideBottomNavigation(animated);
244
+//            mBottomNavigation.hideBottomNavigation(animated);
245
+            mBottomNavigation.setVisibility(View.GONE);
230
         } else {
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
     private static class SetupTabsTask extends AsyncTask<Void, Void, Map<Screen, Drawable>> {
256
     private static class SetupTabsTask extends AsyncTask<Void, Void, Map<Screen, Drawable>> {
236
         private BottomTabActivity mActivity;
257
         private BottomTabActivity mActivity;
237
         private RnnToolBar mToolBar;
258
         private RnnToolBar mToolBar;

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

18
     @Override
18
     @Override
19
     protected void handleOnCreate() {
19
     protected void handleOnCreate() {
20
         super.handleOnCreate();
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
     @Override
27
     @Override

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

49
     }
49
     }
50
 
50
 
51
     protected void setupToolbar(Screen screen) {
51
     protected void setupToolbar(Screen screen) {
52
-        mToolbar.update(screen);
53
         StyleHelper.updateStyles(mToolbar, screen);
52
         StyleHelper.updateStyles(mToolbar, screen);
54
     }
53
     }
55
 
54
 

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

25
 public class RctManager {
25
 public class RctManager {
26
     private static final String TAG = "RctManager";
26
     private static final String TAG = "RctManager";
27
     private static final String KEY_EVENT_ID = "id";
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
     private static RctManager sInstance;
30
     private static RctManager sInstance;
29
 
31
 
30
     private ReactInstanceManager mReactManager;
32
     private ReactInstanceManager mReactManager;
136
             return;
138
             return;
137
         }
139
         }
138
 
140
 
141
+        params.putString(KEY_EVENT_TYPE, EVENT_TYPE);
139
         params.putString(KEY_EVENT_ID, eventName);
142
         params.putString(KEY_EVENT_ID, eventName);
140
         params.putString(Screen.KEY_NAVIGATOR_EVENT_ID, screen.navigatorEventId);
143
         params.putString(Screen.KEY_NAVIGATOR_EVENT_ID, screen.navigatorEventId);
141
         eventEmitter.emit(screen.navigatorEventId, params);
144
         eventEmitter.emit(screen.navigatorEventId, params);

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

43
     private static final String KEY_TAB_NORMAL_TEXT_COLOR = "tabNormalTextColor";
43
     private static final String KEY_TAB_NORMAL_TEXT_COLOR = "tabNormalTextColor";
44
     private static final String KEY_TAB_SELECTED_TEXT_COLOR = "tabSelectedTextColor";
44
     private static final String KEY_TAB_SELECTED_TEXT_COLOR = "tabSelectedTextColor";
45
     private static final String KEY_TAB_INDICATOR_COLOR = "tabIndicatorColor";
45
     private static final String KEY_TAB_INDICATOR_COLOR = "tabIndicatorColor";
46
+    private static final String KEY_BOTTOM_TABS_HIDDEN = "tabBarHidden";
46
     private static final String KEY_PROPS = "passProps";
47
     private static final String KEY_PROPS = "passProps";
47
 
48
 
48
     public String title;
49
     public String title;
66
     @Nullable @ColorInt public Integer tabNormalTextColor;
67
     @Nullable @ColorInt public Integer tabNormalTextColor;
67
     @Nullable @ColorInt public Integer tabSelectedTextColor;
68
     @Nullable @ColorInt public Integer tabSelectedTextColor;
68
     @Nullable @ColorInt public Integer tabIndicatorColor;
69
     @Nullable @ColorInt public Integer tabIndicatorColor;
70
+    public Boolean bottomTabsHidden;
69
 
71
 
70
     @NonNull
72
     @NonNull
71
     public List<Button> getButtons() {
73
     public List<Button> getButtons() {
132
             tabNormalTextColor = getColor(style, KEY_TAB_NORMAL_TEXT_COLOR);
134
             tabNormalTextColor = getColor(style, KEY_TAB_NORMAL_TEXT_COLOR);
133
             tabSelectedTextColor = getColor(style, KEY_TAB_SELECTED_TEXT_COLOR);
135
             tabSelectedTextColor = getColor(style, KEY_TAB_SELECTED_TEXT_COLOR);
134
             tabIndicatorColor = getColor(style, KEY_TAB_INDICATOR_COLOR);
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
 package com.reactnativenavigation.utils;
1
 package com.reactnativenavigation.utils;
2
 
2
 
3
+import android.support.annotation.Nullable;
4
+
3
 import com.reactnativenavigation.activities.BaseReactActivity;
5
 import com.reactnativenavigation.activities.BaseReactActivity;
4
 
6
 
5
 import java.lang.ref.WeakReference;
7
 import java.lang.ref.WeakReference;
19
     /**
21
     /**
20
      * Returns the currently resumed activity or {@code null} if there is none.
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
         return sActivityWR != null ? sActivityWR.get() : null;
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
         try {
18
         try {
19
             toolBar.updateAndSetButtons(screen);
19
             toolBar.updateAndSetButtons(screen);
20
             setWindowStyle(screen);
20
             setWindowStyle(screen);
21
-            toolBar.setupToolbarButtonsAsync(screen);
22
         } catch (Exception e) {
21
         } catch (Exception e) {
23
             Log.w("RNNavigation", "Tried to update styles with no screen!");
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
 
212
 
213
     @SuppressWarnings({"ConstantConditions"})
213
     @SuppressWarnings({"ConstantConditions"})
214
     public void setNavUpButton(Screen screen) {
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
         if (actionBar == null) {
221
         if (actionBar == null) {
217
             return;
222
             return;
218
         }
223
         }
226
             navArrow = (DrawerArrowDrawable) this.getNavigationIcon();
231
             navArrow = (DrawerArrowDrawable) this.getNavigationIcon();
227
         } else {
232
         } else {
228
             if (isBack && !screen.backButtonHidden) {
233
             if (isBack && !screen.backButtonHidden) {
229
-                navArrow = new DrawerArrowDrawable(ContextProvider.getActivityContext());
234
+                navArrow = new DrawerArrowDrawable(context);
230
             } else if (hasDrawer) {
235
             } else if (hasDrawer) {
231
                 navIcon = mDrawerIcon;
236
                 navIcon = mDrawerIcon;
232
             }
237
             }

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

33
     addNavigatorParams(tab, null, idx);
33
     addNavigatorParams(tab, null, idx);
34
     addNavigatorButtons(tab);
34
     addNavigatorButtons(tab);
35
     addNavigationStyleParams(tab);
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
     tab.passProps = params.passProps;
37
     tab.passProps = params.passProps;
43
   });
38
   });
44
 
39
 
46
   RctActivity.startTabBasedApp(params.tabs, params.tabsStyle, drawer);
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
 function navigatorPush(navigator, params) {
57
 function navigatorPush(navigator, params) {
50
   addNavigatorParams(params, navigator);
58
   addNavigatorParams(params, navigator);
51
   addNavigatorButtons(params);
59
   addNavigatorButtons(params);