Sfoglia il codice sorgente

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

# Conflicts:
#	package.json
Yedidya Kennard 8 anni fa
parent
commit
0495685337

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

219
     @CallSuper
219
     @CallSuper
220
     public void push(Screen screen) {
220
     public void push(Screen screen) {
221
         setNavigationStyle(screen);
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 Vedi File

63
     }
63
     }
64
 
64
 
65
     private void setupToolbar(ArrayList<Screen> screens) {
65
     private void setupToolbar(ArrayList<Screen> screens) {
66
+        mToolbar.setScreens(screens);
66
         Screen initialScreen = screens.get(0);
67
         Screen initialScreen = screens.get(0);
68
+        mToolbar.update(initialScreen);
67
         setNavigationStyle(initialScreen);
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
     private void setupTabs(Bundle style) {
72
     private void setupTabs(Bundle style) {
111
     public Screen pop(String navigatorId) {
104
     public Screen pop(String navigatorId) {
112
         super.pop(navigatorId);
105
         super.pop(navigatorId);
113
         Screen screen = mScreenStacks.get(mCurrentStackPosition).pop();
106
         Screen screen = mScreenStacks.get(mCurrentStackPosition).pop();
114
-        setNavigationStyle(screen);
107
+        Screen currentScreen = getCurrentScreen();
108
+        setNavigationStyle(currentScreen);
109
+        mToolbar.update(currentScreen);
115
         return screen;
110
         return screen;
116
     }
111
     }
117
 
112
 

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

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

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

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

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

28
     protected Integer getColor(ReadableMap map, String key) {
28
     protected Integer getColor(ReadableMap map, String key) {
29
         return map.hasKey(key) ? Color.parseColor(map.getString(key)) : null;
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 Vedi File

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

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

28
 
28
 
29
     private ScreenStack mScreenStack;
29
     private ScreenStack mScreenStack;
30
     private View mContentView;
30
     private View mContentView;
31
-    private Screen mScreen;
31
+    private RnnToolBar mToolBar;
32
 
32
 
33
     public RnnModal(BaseReactActivity context, Screen screen) {
33
     public RnnModal(BaseReactActivity context, Screen screen) {
34
         super(context, R.style.Modal);
34
         super(context, R.style.Modal);
35
-        mScreen = screen;
36
         ModalController.getInstance().add(this);
35
         ModalController.getInstance().add(this);
37
-        init(context);
36
+        init(context, screen);
38
     }
37
     }
39
 
38
 
40
     @SuppressLint("InflateParams")
39
     @SuppressLint("InflateParams")
41
-    private void init(final Context context) {
40
+    private void init(final Context context, Screen screen) {
42
         requestWindowFeature(Window.FEATURE_NO_TITLE);
41
         requestWindowFeature(Window.FEATURE_NO_TITLE);
43
         mContentView = LayoutInflater.from(context).inflate(R.layout.modal_layout, null, false);
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
         mScreenStack = (ScreenStack) mContentView.findViewById(R.id.screenStack);
44
         mScreenStack = (ScreenStack) mContentView.findViewById(R.id.screenStack);
46
-
47
         setContentView(mContentView);
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
             @Override
48
             @Override
53
             public void onDisplayed() {
49
             public void onDisplayed() {
54
                 Animation animation = AnimationUtils.loadAnimation(context, R.anim.slide_up);
50
                 Animation animation = AnimationUtils.loadAnimation(context, R.anim.slide_up);
61
         if (SdkSupports.lollipop()) {
57
         if (SdkSupports.lollipop()) {
62
             Window window = getWindow();
58
             Window window = getWindow();
63
             window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
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
     public void push(Screen screen) {
64
     public void push(Screen screen) {
69
         mScreenStack.push(screen);
65
         mScreenStack.push(screen);
66
+        mToolBar.update(screen);
70
     }
67
     }
71
 
68
 
72
     public Screen pop() {
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
     @Override
79
     @Override
77
     public void onBackPressed() {
80
     public void onBackPressed() {
78
-        if (mScreenStack.getStackSize() > 1) {
79
-            mScreenStack.pop();
80
-        } else {
81
+        if (mScreenStack.isEmpty()) {
81
             ModalController.getInstance().remove();
82
             ModalController.getInstance().remove();
82
             super.onBackPressed();
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 Vedi File

5
 import android.content.res.Resources;
5
 import android.content.res.Resources;
6
 import android.graphics.drawable.Drawable;
6
 import android.graphics.drawable.Drawable;
7
 import android.os.AsyncTask;
7
 import android.os.AsyncTask;
8
+import android.support.annotation.UiThread;
8
 import android.support.v4.content.ContextCompat;
9
 import android.support.v4.content.ContextCompat;
9
 import android.support.v4.content.res.ResourcesCompat;
10
 import android.support.v4.content.res.ResourcesCompat;
10
 import android.support.v7.app.ActionBar;
11
 import android.support.v7.app.ActionBar;
12
+import android.support.v7.app.AppCompatActivity;
11
 import android.support.v7.widget.Toolbar;
13
 import android.support.v7.widget.Toolbar;
12
 import android.util.AttributeSet;
14
 import android.util.AttributeSet;
13
 import android.view.Menu;
15
 import android.view.Menu;
21
 import com.reactnativenavigation.utils.ImageUtils;
23
 import com.reactnativenavigation.utils.ImageUtils;
22
 
24
 
23
 import java.lang.ref.WeakReference;
25
 import java.lang.ref.WeakReference;
24
-import java.util.Collections;
25
 import java.util.HashMap;
26
 import java.util.HashMap;
26
 import java.util.List;
27
 import java.util.List;
27
 import java.util.Map;
28
 import java.util.Map;
70
         } else {
71
         } else {
71
             resetTitleTextColor();
72
             resetTitleTextColor();
72
         }
73
         }
74
+        
75
+        if (screen.toolBarHidden != null && screen.toolBarHidden) {
76
+            hideToolbar();
77
+        } else {
78
+            showToolbar();
79
+        }
73
     }
80
     }
74
 
81
 
75
     private void resetBackground() {
82
     private void resetBackground() {
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
     @SuppressWarnings({"ConstantConditions"})
119
     @SuppressWarnings({"ConstantConditions"})
99
     public void showBackButton(Screen screen) {
120
     public void showBackButton(Screen screen) {
100
         ActionBar actionBar = ContextProvider.getActivityContext().getSupportActionBar();
121
         ActionBar actionBar = ContextProvider.getActivityContext().getSupportActionBar();
126
         ContextProvider.getActivityContext().getSupportActionBar().setDisplayHomeAsUpEnabled(false);
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
     private static class SetupToolbarButtonsTask extends AsyncTask<Void, Void, Map<String, Drawable>> {
163
     private static class SetupToolbarButtonsTask extends AsyncTask<Void, Void, Map<String, Drawable>> {
130
         private final List<Button> mOldButtons;
164
         private final List<Button> mOldButtons;
131
         private final List<Button> mNewButtons;
165
         private final List<Button> mNewButtons;

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

28
             componentRight={params.drawer.right ? params.drawer.right.screen : undefined}
28
             componentRight={params.drawer.right ? params.drawer.right.screen : undefined}
29
             passPropsRight={{navigatorID: navigatorID}}
29
             passPropsRight={{navigatorID: navigatorID}}
30
             disableOpenGesture={params.drawer.disableOpenGesture}
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
             {this.renderBody()}
34
             {this.renderBody()}
33
           </DrawerControllerIOS>
35
           </DrawerControllerIOS>