Browse Source

Merge branch 'navigation_style'

Guy Carmeli 8 years ago
parent
commit
95d29dcf6f

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

29
 import com.reactnativenavigation.core.objects.Screen;
29
 import com.reactnativenavigation.core.objects.Screen;
30
 import com.reactnativenavigation.packages.RnnPackage;
30
 import com.reactnativenavigation.packages.RnnPackage;
31
 import com.reactnativenavigation.utils.ContextProvider;
31
 import com.reactnativenavigation.utils.ContextProvider;
32
+import com.reactnativenavigation.utils.SdkSupports;
32
 import com.reactnativenavigation.views.RnnToolBar;
33
 import com.reactnativenavigation.views.RnnToolBar;
33
 
34
 
34
 import java.util.Arrays;
35
 import java.util.Arrays;
169
         setContentView(mReactRootView);
170
         setContentView(mReactRootView);
170
     }
171
     }
171
 
172
 
173
+    public void setNavigationColors(Screen screen) {
174
+        if (screen.toolBarColor != null) {
175
+            mToolbar.setBackgroundColor(screen.toolBarColor);
176
+        }
177
+
178
+        if (screen.titleColor != null) {
179
+            mToolbar.setTitleTextColor(screen.titleColor);
180
+        }
181
+
182
+        if (SdkSupports.lollipop()) {
183
+            if (screen.statusBarColor != null) {
184
+                getWindow().setStatusBarColor(screen.statusBarColor);
185
+            }
186
+
187
+            if (screen.navigationBarColor != null) {
188
+                getWindow().setNavigationBarColor(screen.navigationBarColor);
189
+            }
190
+        }
191
+    }
192
+
172
     @Override
193
     @Override
173
     protected void onResume() {
194
     protected void onResume() {
174
         super.onResume();
195
         super.onResume();
209
         if (mToolbar != null &&
230
         if (mToolbar != null &&
210
             getCurrentNavigatorId().equals(screen.navigatorId) &&
231
             getCurrentNavigatorId().equals(screen.navigatorId) &&
211
             getScreenStackSize() >= 1) {
232
             getScreenStackSize() >= 1) {
212
-            mToolbar.showBackButton();
233
+            mToolbar.showBackButton(screen);
213
         }
234
         }
214
     }
235
     }
215
 
236
 

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

1
 package com.reactnativenavigation.activities;
1
 package com.reactnativenavigation.activities;
2
 
2
 
3
-import android.support.v7.widget.Toolbar;
4
 import android.widget.FrameLayout;
3
 import android.widget.FrameLayout;
5
 
4
 
6
 import com.reactnativenavigation.R;
5
 import com.reactnativenavigation.R;
7
 import com.reactnativenavigation.core.RctManager;
6
 import com.reactnativenavigation.core.RctManager;
8
 import com.reactnativenavigation.core.objects.Screen;
7
 import com.reactnativenavigation.core.objects.Screen;
8
+import com.reactnativenavigation.views.RnnToolBar;
9
 import com.reactnativenavigation.views.ScreenStack;
9
 import com.reactnativenavigation.views.ScreenStack;
10
 
10
 
11
 /**
11
 /**
15
 
15
 
16
     public static final String EXTRA_SCREEN = "extraScreen";
16
     public static final String EXTRA_SCREEN = "extraScreen";
17
 
17
 
18
-    private Toolbar mToolbar;
19
     private ScreenStack mScreenStack;
18
     private ScreenStack mScreenStack;
20
     private String mNavigatorId;
19
     private String mNavigatorId;
21
 
20
 
24
         mReactInstanceManager = RctManager.getInstance().getReactInstanceManager();
23
         mReactInstanceManager = RctManager.getInstance().getReactInstanceManager();
25
 
24
 
26
         setContentView(R.layout.single_screen_activity);
25
         setContentView(R.layout.single_screen_activity);
27
-        mToolbar = (Toolbar) findViewById(R.id.toolbar);
26
+        mToolbar = (RnnToolBar) findViewById(R.id.toolbar);
28
 
27
 
29
         Screen screen = (Screen) getIntent().getSerializableExtra(EXTRA_SCREEN);
28
         Screen screen = (Screen) getIntent().getSerializableExtra(EXTRA_SCREEN);
30
         mNavigatorId = screen.navigatorId;
29
         mNavigatorId = screen.navigatorId;
31
-        setupToolbar(screen.title);
30
+        setupToolbar(screen);
32
 
31
 
33
         mScreenStack = new ScreenStack(this);
32
         mScreenStack = new ScreenStack(this);
34
         FrameLayout contentFrame = (FrameLayout) findViewById(R.id.contentFrame);
33
         FrameLayout contentFrame = (FrameLayout) findViewById(R.id.contentFrame);
36
         mScreenStack.push(screen);
35
         mScreenStack.push(screen);
37
     }
36
     }
38
 
37
 
39
-    private void setupToolbar(String title) {
40
-        mToolbar.setTitle(title);
38
+    protected void setupToolbar(Screen screen) {
39
+        setNavigationColors(screen);
40
+        mToolbar.setTitle(screen.title);
41
         setSupportActionBar(mToolbar);
41
         setSupportActionBar(mToolbar);
42
     }
42
     }
43
     
43
     

+ 20
- 1
android/app/src/main/java/com/reactnativenavigation/activities/TabActivity.java View File

38
     }
38
     }
39
 
39
 
40
     private void setupToolbar(ArrayList<Screen> screens) {
40
     private void setupToolbar(ArrayList<Screen> screens) {
41
-        setSupportActionBar(mToolbar);
41
+        Screen initialScreen = screens.get(0);
42
+        setNavigationColors(initialScreen);
42
         mToolbar.setScreens(screens);
43
         mToolbar.setScreens(screens);
44
+        mToolbar.setTitle(initialScreen.title == null ? "" : initialScreen.title);
45
+        setSupportActionBar(mToolbar);
46
+    }
47
+
48
+    @Override
49
+    public void setNavigationColors(Screen screen) {
50
+        super.setNavigationColors(screen);
51
+        if (screen.toolBarColor != null) {
52
+            mTabLayout.setBackgroundColor(screen.toolBarColor);
53
+        }
54
+
55
+        if (screen.tabNormalTextColor != null && screen.tabSelectedTextColor != null) {
56
+            mTabLayout.setTabTextColors(screen.tabNormalTextColor, screen.tabSelectedTextColor);
57
+        }
58
+
59
+        if (screen.tabIndicatorColor != null) {
60
+            mTabLayout.setSelectedTabIndicatorColor(screen.tabIndicatorColor);
61
+        }
43
     }
62
     }
44
 
63
 
45
     private void setupViewPager(ArrayList<Screen> screens) {
64
     private void setupViewPager(ArrayList<Screen> screens) {

+ 31
- 5
android/app/src/main/java/com/reactnativenavigation/adapters/ViewPagerAdapter.java View File

21
 /**
21
 /**
22
  * Created by guyc on 02/04/16.
22
  * Created by guyc on 02/04/16.
23
  */
23
  */
24
-public class ViewPagerAdapter extends PagerAdapter implements TabLayout.OnTabSelectedListener {
24
+public class ViewPagerAdapter extends PagerAdapter implements TabLayout.OnTabSelectedListener, ViewPager.OnPageChangeListener {
25
 
25
 
26
     private static final String EVENT_ON_TAB_SELECTED = "OnTabSelected";
26
     private static final String EVENT_ON_TAB_SELECTED = "OnTabSelected";
27
 
27
 
30
     private final ArrayList<ScreenStack> mScreenStacks;
30
     private final ArrayList<ScreenStack> mScreenStacks;
31
     private final ArrayList<String> mNavigatorIds;
31
     private final ArrayList<String> mNavigatorIds;
32
     private final Map<String, ScreenStack> mStackByNavigatorId;
32
     private final Map<String, ScreenStack> mStackByNavigatorId;
33
-
33
+    private int mCurrentPage = 0;
34
 
34
 
35
     public ViewPagerAdapter(BaseReactActivity context, ViewPager viewPager, RnnToolBar toolbar,
35
     public ViewPagerAdapter(BaseReactActivity context, ViewPager viewPager, RnnToolBar toolbar,
36
                             ArrayList<Screen> screens) {
36
                             ArrayList<Screen> screens) {
50
 
50
 
51
     public void push(Screen screen) {
51
     public void push(Screen screen) {
52
         ScreenStack stack = mStackByNavigatorId.get(screen.navigatorId);
52
         ScreenStack stack = mStackByNavigatorId.get(screen.navigatorId);
53
+        Screen prevScreen = mScreenStacks.get(mCurrentPage).peek();
54
+        mToolbar.setupToolbarButtonsAsync(prevScreen, screen);
53
         stack.push(screen);
55
         stack.push(screen);
54
     }
56
     }
55
 
57
 
56
     public Screen pop(String navigatorId) {
58
     public Screen pop(String navigatorId) {
57
         ScreenStack stack = mStackByNavigatorId.get(navigatorId);
59
         ScreenStack stack = mStackByNavigatorId.get(navigatorId);
58
-        return stack != null ? stack.pop() : null;
60
+        Screen oldScreen =  stack != null ? stack.pop() : null;
61
+        Screen newScreen = stack.peek();
62
+        mToolbar.setupToolbarButtonsAsync(oldScreen, newScreen);
63
+        return oldScreen;
59
     }
64
     }
60
 
65
 
61
     public Screen peek(String navigatorId) {
66
     public Screen peek(String navigatorId) {
87
 
92
 
88
     @Override
93
     @Override
89
     public CharSequence getPageTitle(int position) {
94
     public CharSequence getPageTitle(int position) {
90
-        return mScreenStacks.get(position).peek().title;
95
+        return mScreenStacks.get(position).peek().label;
91
     }
96
     }
92
 
97
 
93
     @Override
98
     @Override
96
         int position = tab.getPosition();
101
         int position = tab.getPosition();
97
         mViewPager.setCurrentItem(position);
102
         mViewPager.setCurrentItem(position);
98
 
103
 
99
-        mToolbar.setupToolbarButtonsAsync(mScreenStacks.get(position).peek());
104
+        // Set screen buttons
105
+        Screen prevScreen = mScreenStacks.get(mCurrentPage).peek();
106
+        Screen newScreen = mScreenStacks.get(position).peek();
107
+        mToolbar.setupToolbarButtonsAsync(prevScreen, newScreen);
108
+
109
+        // Set title
110
+        mToolbar.setTitle(newScreen.title == null ? "" : newScreen.title);
100
 
111
 
101
         // Send tab selected event
112
         // Send tab selected event
102
         WritableMap params = Arguments.createMap();
113
         WritableMap params = Arguments.createMap();
121
     public int getStackSizeForNavigatorId(String activeNavigatorID) {
132
     public int getStackSizeForNavigatorId(String activeNavigatorID) {
122
         return mStackByNavigatorId.get(activeNavigatorID).getStackSize();
133
         return mStackByNavigatorId.get(activeNavigatorID).getStackSize();
123
     }
134
     }
135
+
136
+    @Override
137
+    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
138
+
139
+    }
140
+
141
+    @Override
142
+    public void onPageSelected(int position) {
143
+        mCurrentPage = position;
144
+    }
145
+
146
+    @Override
147
+    public void onPageScrollStateChanged(int state) {
148
+
149
+    }
124
 }
150
 }

+ 2
- 2
android/app/src/main/java/com/reactnativenavigation/core/objects/Button.java View File

35
     public String title;
35
     public String title;
36
     private String mIconSource;
36
     private String mIconSource;
37
 
37
 
38
-    private static AtomicInteger sAtomicIdGenerator = new AtomicInteger();
39
-    private static Map<String, Integer> sStringToNumericId = new HashMap<>();
38
+    private static final AtomicInteger sAtomicIdGenerator = new AtomicInteger();
39
+    private static final Map<String, Integer> sStringToNumericId = new HashMap<>();
40
 
40
 
41
     public Button(ReadableMap button) {
41
     public Button(ReadableMap button) {
42
         id = getString(button, KEY_ID);
42
         id = getString(button, KEY_ID);

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

1
 package com.reactnativenavigation.core.objects;
1
 package com.reactnativenavigation.core.objects;
2
 
2
 
3
+import android.graphics.Color;
4
+
3
 import com.facebook.react.bridge.ReadableMap;
5
 import com.facebook.react.bridge.ReadableMap;
4
 
6
 
5
 /**
7
 /**
18
     protected int getInt(ReadableMap map, String key) {
20
     protected int getInt(ReadableMap map, String key) {
19
         return map.hasKey(key) ? map.getInt(key) : -1;
21
         return map.hasKey(key) ? map.getInt(key) : -1;
20
     }
22
     }
23
+
24
+    protected ReadableMap getMap(ReadableMap map, String key) {
25
+        return map.hasKey(key) ? map.getMap(key) : null;
26
+    }
27
+
28
+    protected Integer getColor(ReadableMap map, String key) {
29
+        return map.hasKey(key) ? Color.parseColor(map.getString(key)) : null;
30
+    }
21
 }
31
 }

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

1
 package com.reactnativenavigation.core.objects;
1
 package com.reactnativenavigation.core.objects;
2
 
2
 
3
+import android.support.annotation.ColorInt;
4
+import android.support.annotation.NonNull;
5
+import android.support.annotation.Nullable;
6
+
3
 import com.facebook.react.bridge.ReadableArray;
7
 import com.facebook.react.bridge.ReadableArray;
4
 import com.facebook.react.bridge.ReadableMap;
8
 import com.facebook.react.bridge.ReadableMap;
5
 
9
 
6
 import java.io.Serializable;
10
 import java.io.Serializable;
7
 import java.util.ArrayList;
11
 import java.util.ArrayList;
12
+import java.util.Collections;
8
 import java.util.List;
13
 import java.util.List;
9
 
14
 
10
 /**
15
 /**
15
 
20
 
16
     private static final String KEY_TITLE = "title";
21
     private static final String KEY_TITLE = "title";
17
     private static final String KEY_SCREEN = "screen";
22
     private static final String KEY_SCREEN = "screen";
23
+    private static final String KEY_LABEL = "label";
18
     public static final String KEY_SCREEN_INSTANCE_ID = "screenInstanceID";
24
     public static final String KEY_SCREEN_INSTANCE_ID = "screenInstanceID";
19
     public static final String KEY_NAVIGATOR_ID = "navigatorID";
25
     public static final String KEY_NAVIGATOR_ID = "navigatorID";
20
     public static final String KEY_NAVIGATOR_EVENT_ID = "navigatorEventID";
26
     public static final String KEY_NAVIGATOR_EVENT_ID = "navigatorEventID";
21
     private static final String KEY_ICON = "icon";
27
     private static final String KEY_ICON = "icon";
22
     private static final String KEY_RIGHT_BUTTONS = "rightButtons";
28
     private static final String KEY_RIGHT_BUTTONS = "rightButtons";
29
+    private static final String KEY_TOOL_BAR_STYLE = "navigatorStyle";
30
+    private static final String KEY_STATUS_BAR_COLOR = "statusBarColor";
31
+    private static final String KEY_TOOL_BAR_COLOR = "toolBarColor";
32
+    private static final String KEY_NAVIGATION_BAR_COLOR = "navigationBarColor";
33
+    private static final String KEY_BUTTONS_TINT_COLOR = "buttonsTint";
34
+    private static final String KEY_TITLE_COLOR = "titleColor";
35
+    private static final String KEY_TAB_NORMAL_TEXT_COLOR = "tabNormalTextColor";
36
+    private static final String KEY_TAB_SELECTED_TEXT_COLOR = "tabSelectedTextColor";
37
+    private static final String KEY_TAB_INDICATOR_COLOR = "tabIndicatorColor";
23
 
38
 
24
     public String title;
39
     public String title;
40
+    public String label;
25
     public String screenId;
41
     public String screenId;
26
     public String screenInstanceId;
42
     public String screenInstanceId;
27
     public String navigatorId;
43
     public String navigatorId;
28
     public String navigatorEventId;
44
     public String navigatorEventId;
29
     public int icon;
45
     public int icon;
30
-    public List<Button> buttons;
46
+    public ArrayList<Button> buttons;
47
+
48
+    // Navigation styling
49
+    @Nullable @ColorInt public Integer toolBarColor;
50
+    @Nullable @ColorInt public Integer statusBarColor;
51
+    @Nullable @ColorInt public Integer navigationBarColor;
52
+    @Nullable @ColorInt public Integer buttonsTintColor;
53
+    @Nullable @ColorInt public Integer titleColor;
54
+    @Nullable @ColorInt public Integer tabNormalTextColor;
55
+    @Nullable @ColorInt public Integer tabSelectedTextColor;
56
+    @Nullable @ColorInt public Integer tabIndicatorColor;
57
+
58
+    @NonNull
59
+    public List<Button> getButtons() {
60
+        return buttons == null ? Collections.EMPTY_LIST : buttons;
61
+    }
31
 
62
 
32
     public Screen(ReadableMap screen) {
63
     public Screen(ReadableMap screen) {
33
         title = getString(screen, KEY_TITLE);
64
         title = getString(screen, KEY_TITLE);
65
+        label = getString(screen, KEY_LABEL);
34
         screenId = getString(screen, KEY_SCREEN);
66
         screenId = getString(screen, KEY_SCREEN);
35
         screenInstanceId = getString(screen, KEY_SCREEN_INSTANCE_ID);
67
         screenInstanceId = getString(screen, KEY_SCREEN_INSTANCE_ID);
36
         navigatorId = getString(screen, KEY_NAVIGATOR_ID);
68
         navigatorId = getString(screen, KEY_NAVIGATOR_ID);
37
         navigatorEventId = getString(screen, KEY_NAVIGATOR_EVENT_ID);
69
         navigatorEventId = getString(screen, KEY_NAVIGATOR_EVENT_ID);
38
         icon = getInt(screen, KEY_ICON);
70
         icon = getInt(screen, KEY_ICON);
39
 
71
 
72
+        setButtons(screen);
73
+        setToolbarStyle(screen);
74
+    }
75
+
76
+    private void setButtons(ReadableMap screen) {
40
         if (screen.hasKey(KEY_RIGHT_BUTTONS)) {
77
         if (screen.hasKey(KEY_RIGHT_BUTTONS)) {
41
             buttons = new ArrayList<>();
78
             buttons = new ArrayList<>();
42
             ReadableArray rightButtons = screen.getArray(KEY_RIGHT_BUTTONS);
79
             ReadableArray rightButtons = screen.getArray(KEY_RIGHT_BUTTONS);
45
             }
82
             }
46
         }
83
         }
47
     }
84
     }
85
+
86
+    public void setToolbarStyle(ReadableMap screen) {
87
+        ReadableMap style = getMap(screen, KEY_TOOL_BAR_STYLE);
88
+        if (style != null) {
89
+            toolBarColor = getColor(style, KEY_TOOL_BAR_COLOR);
90
+            statusBarColor = getColor(style, KEY_STATUS_BAR_COLOR);
91
+            navigationBarColor = getColor(style, KEY_NAVIGATION_BAR_COLOR);
92
+            buttonsTintColor = getColor(style, KEY_BUTTONS_TINT_COLOR);
93
+            titleColor = getColor(style, KEY_TITLE_COLOR);
94
+            tabNormalTextColor = getColor(style, KEY_TAB_NORMAL_TEXT_COLOR);
95
+            tabSelectedTextColor = getColor(style, KEY_TAB_SELECTED_TEXT_COLOR);
96
+            tabIndicatorColor = getColor(style, KEY_TAB_INDICATOR_COLOR);
97
+        }
98
+    }
48
 }
99
 }

+ 16
- 0
android/app/src/main/java/com/reactnativenavigation/utils/ImageUtils.java View File

1
+package com.reactnativenavigation.utils;
2
+
3
+import android.graphics.PorterDuff;
4
+import android.graphics.PorterDuffColorFilter;
5
+import android.graphics.drawable.Drawable;
6
+
7
+/**
8
+ * Created by guyc on 23/04/16.
9
+ */
10
+public class ImageUtils {
11
+
12
+    public static void tint(Drawable drawable, int tint) {
13
+        drawable.setColorFilter(new PorterDuffColorFilter(tint, PorterDuff.Mode.SRC_IN));
14
+    }
15
+
16
+}

+ 13
- 0
android/app/src/main/java/com/reactnativenavigation/utils/SdkSupports.java View File

1
+package com.reactnativenavigation.utils;
2
+
3
+import android.os.Build;
4
+
5
+/**
6
+ * Created by guyc on 23/04/16.
7
+ */
8
+public class SdkSupports {
9
+
10
+    public static boolean lollipop() {
11
+        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
12
+    }
13
+}

+ 49
- 16
android/app/src/main/java/com/reactnativenavigation/views/RnnToolBar.java View File

1
 package com.reactnativenavigation.views;
1
 package com.reactnativenavigation.views;
2
 
2
 
3
+import android.annotation.SuppressLint;
3
 import android.content.Context;
4
 import android.content.Context;
5
+import android.content.res.Resources;
4
 import android.graphics.drawable.Drawable;
6
 import android.graphics.drawable.Drawable;
5
 import android.os.AsyncTask;
7
 import android.os.AsyncTask;
8
+import android.support.v4.content.res.ResourcesCompat;
9
+import android.support.v7.app.ActionBar;
6
 import android.support.v7.widget.Toolbar;
10
 import android.support.v7.widget.Toolbar;
7
 import android.util.AttributeSet;
11
 import android.util.AttributeSet;
8
 import android.view.Menu;
12
 import android.view.Menu;
9
 import android.view.MenuItem;
13
 import android.view.MenuItem;
10
 
14
 
15
+import com.reactnativenavigation.R;
11
 import com.reactnativenavigation.activities.BaseReactActivity;
16
 import com.reactnativenavigation.activities.BaseReactActivity;
12
 import com.reactnativenavigation.core.objects.Button;
17
 import com.reactnativenavigation.core.objects.Button;
13
 import com.reactnativenavigation.core.objects.Screen;
18
 import com.reactnativenavigation.core.objects.Screen;
14
 import com.reactnativenavigation.utils.ContextProvider;
19
 import com.reactnativenavigation.utils.ContextProvider;
20
+import com.reactnativenavigation.utils.ImageUtils;
15
 
21
 
16
 import java.lang.ref.WeakReference;
22
 import java.lang.ref.WeakReference;
17
 import java.util.Collections;
23
 import java.util.Collections;
44
     }
50
     }
45
 
51
 
46
     public void handleOnCreateOptionsMenuAsync() {
52
     public void handleOnCreateOptionsMenuAsync() {
47
-        setupToolbarButtonsAsync(mScreens.get(0));
53
+        setupToolbarButtonsAsync(null, mScreens.get(0));
48
     }
54
     }
49
 
55
 
50
-    public void setupToolbarButtonsAsync(Screen screen) {
56
+    public void setupToolbarButtonsAsync(Screen oldScreen, Screen newScreen) {
51
         if (mSetupToolbarTask == null) {
57
         if (mSetupToolbarTask == null) {
52
-            mSetupToolbarTask = new SetupToolbarButtonsTask(this, screen).execute();
58
+            mSetupToolbarTask = new SetupToolbarButtonsTask(this, oldScreen, newScreen).execute();
53
         }
59
         }
54
     }
60
     }
55
 
61
 
56
     @SuppressWarnings({"ConstantConditions"})
62
     @SuppressWarnings({"ConstantConditions"})
57
-    public void showBackButton() {
58
-        ContextProvider.getActivityContext().getSupportActionBar().setDisplayHomeAsUpEnabled(true);
63
+    @SuppressLint("PrivateResource")
64
+    public void showBackButton(Screen screen) {
65
+        ActionBar actionBar = ContextProvider.getActivityContext().getSupportActionBar();
66
+
67
+        Resources resources = getResources();
68
+        final Drawable backButton;
69
+        if (screen.buttonsTintColor != null) {
70
+            backButton = ResourcesCompat.getDrawable(resources,
71
+                    R.drawable.abc_ic_ab_back_mtrl_am_alpha,
72
+                    null);
73
+            ImageUtils.tint(backButton, screen.buttonsTintColor);
74
+        } else {
75
+            backButton = ResourcesCompat.getDrawable(resources,
76
+                    R.drawable.abc_ic_ab_back_mtrl_am_alpha,
77
+                    ContextProvider.getActivityContext().getTheme());
78
+        }
79
+        actionBar.setHomeAsUpIndicator(backButton);
80
+        actionBar.setDisplayHomeAsUpEnabled(true);
59
     }
81
     }
60
 
82
 
61
     @SuppressWarnings({"ConstantConditions"})
83
     @SuppressWarnings({"ConstantConditions"})
64
     }
86
     }
65
 
87
 
66
     private static class SetupToolbarButtonsTask extends AsyncTask<Void, Void, Map<String, Drawable>> {
88
     private static class SetupToolbarButtonsTask extends AsyncTask<Void, Void, Map<String, Drawable>> {
67
-        private final List<Button> mButtons;
89
+        private final List<Button> mOldButtons;
90
+        private final List<Button> mNewButtons;
68
         private final WeakReference<RnnToolBar> mToolbarWR;
91
         private final WeakReference<RnnToolBar> mToolbarWR;
92
+        private final Integer mTintColor;
69
 
93
 
70
-        public SetupToolbarButtonsTask(RnnToolBar toolBar, Screen newScreen) {
94
+        public SetupToolbarButtonsTask(RnnToolBar toolBar, Screen oldScreen, Screen newScreen) {
71
             mToolbarWR = new WeakReference<>(toolBar);
95
             mToolbarWR = new WeakReference<>(toolBar);
72
-            mButtons = newScreen.buttons == null ? Collections.EMPTY_LIST : newScreen.buttons;
96
+            mOldButtons = oldScreen == null ? Collections.EMPTY_LIST : oldScreen.getButtons();
97
+            mNewButtons = newScreen.getButtons();
98
+            mTintColor = newScreen.buttonsTintColor;
73
         }
99
         }
74
 
100
 
75
         @Override
101
         @Override
80
             }
106
             }
81
 
107
 
82
             Map<String, Drawable> icons = new HashMap<>();
108
             Map<String, Drawable> icons = new HashMap<>();
83
-            for (Button button : mButtons) {
109
+            for (Button button : mNewButtons) {
84
                 if (button.hasIcon()) {
110
                 if (button.hasIcon()) {
85
                     icons.put(button.id, button.getIcon(context));
111
                     icons.put(button.id, button.getIcon(context));
86
                 }
112
                 }
97
 
123
 
98
             Menu menu = ((BaseReactActivity) context).getMenu();
124
             Menu menu = ((BaseReactActivity) context).getMenu();
99
 
125
 
126
+            // Remove prev screen buttons
127
+            for (Button btn : mOldButtons) {
128
+                menu.removeItem(btn.getItemId());
129
+            }
130
+
100
             // Add new screen buttons
131
             // Add new screen buttons
101
             int i;
132
             int i;
102
-            for (i = 0; i < mButtons.size(); i++) {
103
-                Button button = mButtons.get(i);
133
+            for (i = 0; i < mNewButtons.size(); i++) {
134
+                Button button = mNewButtons.get(i);
104
                 MenuItem item = menu.add(Menu.NONE, button.getItemId(), i, button.title);
135
                 MenuItem item = menu.add(Menu.NONE, button.getItemId(), i, button.title);
105
                 if (icons.containsKey(button.id)) {
136
                 if (icons.containsKey(button.id)) {
106
                     Drawable icon = icons.get(button.id);
137
                     Drawable icon = icons.get(button.id);
138
+                    if (mTintColor != null) {
139
+                        ImageUtils.tint(icon, mTintColor);
140
+                    }
107
                     item.setIcon(icon).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
141
                     item.setIcon(icon).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
108
                 }
142
                 }
109
             }
143
             }
110
 
144
 
111
-            // Remove prev screen buttons
112
-            for (int j = i; j < menu.size(); j++) {
113
-                menu.removeItem(j);
114
-            }
115
-
116
             RnnToolBar toolBar = mToolbarWR.get();
145
             RnnToolBar toolBar = mToolbarWR.get();
117
             if (toolBar != null) {
146
             if (toolBar != null) {
147
+                if (mTintColor != null) {
148
+                    ImageUtils.tint(toolBar.getOverflowIcon(), mTintColor);
149
+                }
150
+
118
                 toolBar.mSetupToolbarTask = null;
151
                 toolBar.mSetupToolbarTask = null;
119
                 mToolbarWR.clear();
152
                 mToolbarWR.clear();
120
             }
153
             }

+ 1
- 1
android/app/src/main/res/layout/single_screen_activity.xml View File

10
         android:layout_width="match_parent"
10
         android:layout_width="match_parent"
11
         android:layout_height="wrap_content"
11
         android:layout_height="wrap_content"
12
         android:fitsSystemWindows="true">
12
         android:fitsSystemWindows="true">
13
-        <android.support.v7.widget.Toolbar
13
+        <com.reactnativenavigation.views.RnnToolBar
14
             android:id="@+id/toolbar"
14
             android:id="@+id/toolbar"
15
             android:layout_width="match_parent"
15
             android:layout_width="match_parent"
16
             android:layout_height="?attr/actionBarSize"
16
             android:layout_height="?attr/actionBarSize"

+ 11
- 0
example-redux/src/screens/FirstTabScreen.js View File

12
 
12
 
13
 // this is a traditional React component connected to the redux store
13
 // this is a traditional React component connected to the redux store
14
 class FirstTabScreen extends Component {
14
 class FirstTabScreen extends Component {
15
+  static navigatorStyle = {
16
+    statusBarColor: '#303F9F',
17
+    toolBarColor: '#3F51B5',
18
+    navigationBarColor: '#303F9F',
19
+    buttonsTint: '#FFFFFF',
20
+    titleColor: '#FFFFFF',
21
+    tabSelectedTextColor: '#FFA000',
22
+    tabNormalTextColor: '#FFC107',
23
+    tabIndicatorColor: '#FFA000'
24
+  };
25
+
15
   static navigatorButtons = {
26
   static navigatorButtons = {
16
     rightButtons: [
27
     rightButtons: [
17
       {
28
       {

+ 12
- 1
example-redux/src/screens/PushedScreen.js View File

12
 
12
 
13
 // this is a traditional React component connected to the redux store
13
 // this is a traditional React component connected to the redux store
14
 class PushedScreen extends Component {
14
 class PushedScreen extends Component {
15
+  static navigatorStyle = {
16
+    statusBarColor: '#303F9F',
17
+    toolBarColor: '#3F51B5',
18
+    navigationBarColor: '#303F9F',
19
+    buttonsTint: '#FFFFFF',
20
+    titleColor: '#FFFFFF',
21
+    tabSelectedTextColor: '#FFA000',
22
+    tabNormalTextColor: '#FFC107',
23
+    tabIndicatorColor: '#FF4081'
24
+  };
25
+
15
   constructor(props) {
26
   constructor(props) {
16
     super(props);
27
     super(props);
17
     this.bgColor = this.getRandomColor();
28
     this.bgColor = this.getRandomColor();
70
     textAlign: 'center',
81
     textAlign: 'center',
71
     fontSize: 18,
82
     fontSize: 18,
72
     marginBottom: 10,
83
     marginBottom: 10,
73
-    marginTop:10,
84
+    marginTop:10
74
   },
85
   },
75
   button: {
86
   button: {
76
     textAlign: 'center',
87
     textAlign: 'center',

+ 8
- 0
src/platformSpecific.android.js View File

21
 
21
 
22
   addNavigatorParams(screen);
22
   addNavigatorParams(screen);
23
   addNavigatorButtons(screen);
23
   addNavigatorButtons(screen);
24
+  addToolbarStyleParams(screen);
24
   RctActivity.startSingleScreenApp(screen);
25
   RctActivity.startSingleScreenApp(screen);
25
 }
26
 }
26
 
27
 
33
   params.tabs.forEach(function (tab, idx) {
34
   params.tabs.forEach(function (tab, idx) {
34
     addNavigatorParams(tab, null, idx)
35
     addNavigatorParams(tab, null, idx)
35
     addNavigatorButtons(tab);
36
     addNavigatorButtons(tab);
37
+    addToolbarStyleParams(tab);
36
   });
38
   });
37
 
39
 
38
   RctActivity.startTabBasedApp(params.tabs);
40
   RctActivity.startTabBasedApp(params.tabs);
41
 function navigatorPush(navigator, params) {
43
 function navigatorPush(navigator, params) {
42
   addNavigatorParams(params, navigator)
44
   addNavigatorParams(params, navigator)
43
   addNavigatorButtons(params);
45
   addNavigatorButtons(params);
46
+  addToolbarStyleParams(params);
44
   RctActivity.navigatorPush(params);
47
   RctActivity.navigatorPush(params);
45
 }
48
 }
46
 
49
 
71
   }
74
   }
72
 }
75
 }
73
 
76
 
77
+function addToolbarStyleParams(screen) {
78
+  const Screen = Navigation.getRegisteredScreen(screen.screen);
79
+  screen.navigatorStyle = Screen.navigatorStyle;
80
+}
81
+
74
 export default {
82
 export default {
75
   startSingleScreenApp,
83
   startSingleScreenApp,
76
   startTabBasedApp,
84
   startTabBasedApp,