Browse Source

Merge branch 'master' of https://github.com/wix/react-native-navigation

# Conflicts:
#	package.json
Yedidya Kennard 8 years ago
parent
commit
0495685337

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

@@ -219,10 +219,13 @@ public abstract class BaseReactActivity extends AppCompatActivity implements Def
219 219
     @CallSuper
220 220
     public void push(Screen screen) {
221 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,17 +63,10 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
63 63
     }
64 64
 
65 65
     private void setupToolbar(ArrayList<Screen> screens) {
66
+        mToolbar.setScreens(screens);
66 67
         Screen initialScreen = screens.get(0);
68
+        mToolbar.update(initialScreen);
67 69
         setNavigationStyle(initialScreen);
68
-        mToolbar.setScreens(screens);
69
-        mToolbar.setTitle(initialScreen.title);
70
-        setSupportActionBar(mToolbar);
71
-    }
72
-
73
-    @Override
74
-    public void setNavigationStyle(Screen screen) {
75
-        super.setNavigationStyle(screen);
76
-        mToolbar.setTitle(screen.title);
77 70
     }
78 71
 
79 72
     private void setupTabs(Bundle style) {
@@ -111,7 +104,9 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
111 104
     public Screen pop(String navigatorId) {
112 105
         super.pop(navigatorId);
113 106
         Screen screen = mScreenStacks.get(mCurrentStackPosition).pop();
114
-        setNavigationStyle(screen);
107
+        Screen currentScreen = getCurrentScreen();
108
+        setNavigationStyle(currentScreen);
109
+        mToolbar.update(currentScreen);
115 110
         return screen;
116 111
     }
117 112
 

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

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

+ 6
- 5
android/app/src/main/java/com/reactnativenavigation/activities/TabActivity.java View File

@@ -13,8 +13,10 @@ import com.reactnativenavigation.views.RnnToolBar;
13 13
 import java.util.ArrayList;
14 14
 
15 15
 /**
16
+ * This class is currently not supported and will be removed in future release.
16 17
  * Created by guyc on 02/04/16.
17 18
  */
19
+@Deprecated
18 20
 public class TabActivity extends BaseReactActivity {
19 21
     public static final String EXTRA_SCREENS = "extraScreens";
20 22
 
@@ -39,11 +41,9 @@ public class TabActivity extends BaseReactActivity {
39 41
 
40 42
     private void setupToolbar(ArrayList<Screen> screens) {
41 43
         Screen initialScreen = screens.get(0);
42
-        setNavigationStyle(initialScreen);
43 44
         mToolbar.setScreens(screens);
44
-        mToolbar.setTitle(initialScreen.title);
45
-        mToolbar.setupToolbarButtonsAsync(initialScreen);
46
-        setSupportActionBar(mToolbar);
45
+        mToolbar.update(initialScreen);
46
+        setNavigationStyle(initialScreen);
47 47
     }
48 48
 
49 49
     @Override
@@ -70,6 +70,7 @@ public class TabActivity extends BaseReactActivity {
70 70
     @Override
71 71
     public void push(Screen screen) {
72 72
         super.push(screen);
73
+        setNavigationStyle(screen);
73 74
         mAdapter.push(screen);
74 75
     }
75 76
 
@@ -77,7 +78,7 @@ public class TabActivity extends BaseReactActivity {
77 78
     public Screen pop(String navigatorId) {
78 79
         super.pop(navigatorId);
79 80
         Screen screen = mAdapter.pop(navigatorId);
80
-        setNavigationStyle(screen);
81
+        setNavigationStyle(getCurrentScreen());
81 82
         return screen;
82 83
     }
83 84
 

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

@@ -28,4 +28,8 @@ public class JsonObject {
28 28
     protected Integer getColor(ReadableMap map, String key) {
29 29
         return map.hasKey(key) ? Color.parseColor(map.getString(key)) : null;
30 30
     }
31
+    
32
+    protected Boolean getBoolean(ReadableMap map, String key) {
33
+        return map.hasKey(key) ? map.getBoolean(key) : null;
34
+    }
31 35
 }

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

@@ -34,6 +34,7 @@ public class Screen extends JsonObject implements Serializable {
34 34
     private static final String KEY_TOOL_BAR_STYLE = "navigatorStyle";
35 35
     private static final String KEY_STATUS_BAR_COLOR = "statusBarColor";
36 36
     private static final String KEY_TOOL_BAR_COLOR = "toolBarColor";
37
+    private static final String KEY_TOOL_BAR_HIDDEN = "navBarHidden";
37 38
     private static final String KEY_NAVIGATION_BAR_COLOR = "navigationBarColor";
38 39
     private static final String KEY_BUTTONS_TINT_COLOR = "buttonsTint";
39 40
     private static final String KEY_TITLE_COLOR = "titleColor";
@@ -54,6 +55,7 @@ public class Screen extends JsonObject implements Serializable {
54 55
 
55 56
     // Navigation styling
56 57
     @Nullable @ColorInt public Integer toolBarColor;
58
+    @Nullable public Boolean toolBarHidden;
57 59
     @Nullable @ColorInt public Integer statusBarColor;
58 60
     @Nullable @ColorInt public Integer navigationBarColor;
59 61
     @Nullable @ColorInt public Integer buttonsTintColor;
@@ -105,6 +107,7 @@ public class Screen extends JsonObject implements Serializable {
105 107
         ReadableMap style = getMap(screen, KEY_TOOL_BAR_STYLE);
106 108
         if (style != null) {
107 109
             toolBarColor = getColor(style, KEY_TOOL_BAR_COLOR);
110
+            toolBarHidden = getBoolean(style, KEY_TOOL_BAR_HIDDEN);
108 111
             statusBarColor = getColor(style, KEY_STATUS_BAR_COLOR);
109 112
             navigationBarColor = getColor(style, KEY_NAVIGATION_BAR_COLOR);
110 113
             buttonsTintColor = getColor(style, KEY_BUTTONS_TINT_COLOR);

+ 18
- 15
android/app/src/main/java/com/reactnativenavigation/modal/RnnModal.java View File

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

+ 35
- 1
android/app/src/main/java/com/reactnativenavigation/views/RnnToolBar.java View File

@@ -5,9 +5,11 @@ import android.content.Context;
5 5
 import android.content.res.Resources;
6 6
 import android.graphics.drawable.Drawable;
7 7
 import android.os.AsyncTask;
8
+import android.support.annotation.UiThread;
8 9
 import android.support.v4.content.ContextCompat;
9 10
 import android.support.v4.content.res.ResourcesCompat;
10 11
 import android.support.v7.app.ActionBar;
12
+import android.support.v7.app.AppCompatActivity;
11 13
 import android.support.v7.widget.Toolbar;
12 14
 import android.util.AttributeSet;
13 15
 import android.view.Menu;
@@ -21,7 +23,6 @@ import com.reactnativenavigation.utils.ContextProvider;
21 23
 import com.reactnativenavigation.utils.ImageUtils;
22 24
 
23 25
 import java.lang.ref.WeakReference;
24
-import java.util.Collections;
25 26
 import java.util.HashMap;
26 27
 import java.util.List;
27 28
 import java.util.Map;
@@ -70,6 +71,12 @@ public class RnnToolBar extends Toolbar {
70 71
         } else {
71 72
             resetTitleTextColor();
72 73
         }
74
+        
75
+        if (screen.toolBarHidden != null && screen.toolBarHidden) {
76
+            hideToolbar();
77
+        } else {
78
+            showToolbar();
79
+        }
73 80
     }
74 81
 
75 82
     private void resetBackground() {
@@ -95,6 +102,20 @@ public class RnnToolBar extends Toolbar {
95 102
         }
96 103
     }
97 104
 
105
+    private void showToolbar() {
106
+        ActionBar actionBar = ContextProvider.getActivityContext().getSupportActionBar();
107
+        if (actionBar != null) {
108
+            actionBar.show();
109
+        }
110
+    }
111
+
112
+    private void hideToolbar() {
113
+        ActionBar actionBar = ContextProvider.getActivityContext().getSupportActionBar();
114
+        if (actionBar != null) {
115
+            actionBar.hide();
116
+        }
117
+    }
118
+
98 119
     @SuppressWarnings({"ConstantConditions"})
99 120
     public void showBackButton(Screen screen) {
100 121
         ActionBar actionBar = ContextProvider.getActivityContext().getSupportActionBar();
@@ -126,6 +147,19 @@ public class RnnToolBar extends Toolbar {
126 147
         ContextProvider.getActivityContext().getSupportActionBar().setDisplayHomeAsUpEnabled(false);
127 148
     }
128 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
+     */
155
+    @UiThread
156
+    public void update(Screen screen) {
157
+        ((AppCompatActivity) getContext()).setSupportActionBar(this);
158
+        setTitle(screen.title);
159
+        setStyle(screen);
160
+        setupToolbarButtonsAsync(screen);
161
+    }
162
+
129 163
     private static class SetupToolbarButtonsTask extends AsyncTask<Void, Void, Map<String, Drawable>> {
130 164
         private final List<Button> mOldButtons;
131 165
         private final List<Button> mNewButtons;

+ 2
- 0
src/platformSpecific.ios.js View File

@@ -28,6 +28,8 @@ function startTabBasedApp(params) {
28 28
             componentRight={params.drawer.right ? params.drawer.right.screen : undefined}
29 29
             passPropsRight={{navigatorID: navigatorID}}
30 30
             disableOpenGesture={params.drawer.disableOpenGesture}
31
+            type={params.drawer.type ? params.drawer.type : undefined}
32
+            animationType={params.drawer.animationType ? params.drawer.animationType : undefined}
31 33
           >
32 34
             {this.renderBody()}
33 35
           </DrawerControllerIOS>