Pārlūkot izejas kodu

Merge branch 'navigation_style'

Guy Carmeli 8 gadus atpakaļ
vecāks
revīzija
95d29dcf6f

+ 22
- 1
android/app/src/main/java/com/reactnativenavigation/activities/BaseReactActivity.java Parādīt failu

@@ -29,6 +29,7 @@ import com.reactnativenavigation.core.objects.Button;
29 29
 import com.reactnativenavigation.core.objects.Screen;
30 30
 import com.reactnativenavigation.packages.RnnPackage;
31 31
 import com.reactnativenavigation.utils.ContextProvider;
32
+import com.reactnativenavigation.utils.SdkSupports;
32 33
 import com.reactnativenavigation.views.RnnToolBar;
33 34
 
34 35
 import java.util.Arrays;
@@ -169,6 +170,26 @@ public abstract class BaseReactActivity extends AppCompatActivity implements Def
169 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 193
     @Override
173 194
     protected void onResume() {
174 195
         super.onResume();
@@ -209,7 +230,7 @@ public abstract class BaseReactActivity extends AppCompatActivity implements Def
209 230
         if (mToolbar != null &&
210 231
             getCurrentNavigatorId().equals(screen.navigatorId) &&
211 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 Parādīt failu

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

+ 20
- 1
android/app/src/main/java/com/reactnativenavigation/activities/TabActivity.java Parādīt failu

@@ -38,8 +38,27 @@ public class TabActivity extends BaseReactActivity {
38 38
     }
39 39
 
40 40
     private void setupToolbar(ArrayList<Screen> screens) {
41
-        setSupportActionBar(mToolbar);
41
+        Screen initialScreen = screens.get(0);
42
+        setNavigationColors(initialScreen);
42 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 64
     private void setupViewPager(ArrayList<Screen> screens) {

+ 31
- 5
android/app/src/main/java/com/reactnativenavigation/adapters/ViewPagerAdapter.java Parādīt failu

@@ -21,7 +21,7 @@ import java.util.Map;
21 21
 /**
22 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 26
     private static final String EVENT_ON_TAB_SELECTED = "OnTabSelected";
27 27
 
@@ -30,7 +30,7 @@ public class ViewPagerAdapter extends PagerAdapter implements TabLayout.OnTabSel
30 30
     private final ArrayList<ScreenStack> mScreenStacks;
31 31
     private final ArrayList<String> mNavigatorIds;
32 32
     private final Map<String, ScreenStack> mStackByNavigatorId;
33
-
33
+    private int mCurrentPage = 0;
34 34
 
35 35
     public ViewPagerAdapter(BaseReactActivity context, ViewPager viewPager, RnnToolBar toolbar,
36 36
                             ArrayList<Screen> screens) {
@@ -50,12 +50,17 @@ public class ViewPagerAdapter extends PagerAdapter implements TabLayout.OnTabSel
50 50
 
51 51
     public void push(Screen screen) {
52 52
         ScreenStack stack = mStackByNavigatorId.get(screen.navigatorId);
53
+        Screen prevScreen = mScreenStacks.get(mCurrentPage).peek();
54
+        mToolbar.setupToolbarButtonsAsync(prevScreen, screen);
53 55
         stack.push(screen);
54 56
     }
55 57
 
56 58
     public Screen pop(String navigatorId) {
57 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 66
     public Screen peek(String navigatorId) {
@@ -87,7 +92,7 @@ public class ViewPagerAdapter extends PagerAdapter implements TabLayout.OnTabSel
87 92
 
88 93
     @Override
89 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 98
     @Override
@@ -96,7 +101,13 @@ public class ViewPagerAdapter extends PagerAdapter implements TabLayout.OnTabSel
96 101
         int position = tab.getPosition();
97 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 112
         // Send tab selected event
102 113
         WritableMap params = Arguments.createMap();
@@ -121,4 +132,19 @@ public class ViewPagerAdapter extends PagerAdapter implements TabLayout.OnTabSel
121 132
     public int getStackSizeForNavigatorId(String activeNavigatorID) {
122 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 Parādīt failu

@@ -35,8 +35,8 @@ public class Button extends JsonObject implements Serializable {
35 35
     public String title;
36 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 41
     public Button(ReadableMap button) {
42 42
         id = getString(button, KEY_ID);

+ 10
- 0
android/app/src/main/java/com/reactnativenavigation/core/objects/JsonObject.java Parādīt failu

@@ -1,5 +1,7 @@
1 1
 package com.reactnativenavigation.core.objects;
2 2
 
3
+import android.graphics.Color;
4
+
3 5
 import com.facebook.react.bridge.ReadableMap;
4 6
 
5 7
 /**
@@ -18,4 +20,12 @@ public class JsonObject {
18 20
     protected int getInt(ReadableMap map, String key) {
19 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 Parādīt failu

@@ -1,10 +1,15 @@
1 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 7
 import com.facebook.react.bridge.ReadableArray;
4 8
 import com.facebook.react.bridge.ReadableMap;
5 9
 
6 10
 import java.io.Serializable;
7 11
 import java.util.ArrayList;
12
+import java.util.Collections;
8 13
 import java.util.List;
9 14
 
10 15
 /**
@@ -15,28 +20,60 @@ public class Screen extends JsonObject implements Serializable {
15 20
 
16 21
     private static final String KEY_TITLE = "title";
17 22
     private static final String KEY_SCREEN = "screen";
23
+    private static final String KEY_LABEL = "label";
18 24
     public static final String KEY_SCREEN_INSTANCE_ID = "screenInstanceID";
19 25
     public static final String KEY_NAVIGATOR_ID = "navigatorID";
20 26
     public static final String KEY_NAVIGATOR_EVENT_ID = "navigatorEventID";
21 27
     private static final String KEY_ICON = "icon";
22 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 39
     public String title;
40
+    public String label;
25 41
     public String screenId;
26 42
     public String screenInstanceId;
27 43
     public String navigatorId;
28 44
     public String navigatorEventId;
29 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 63
     public Screen(ReadableMap screen) {
33 64
         title = getString(screen, KEY_TITLE);
65
+        label = getString(screen, KEY_LABEL);
34 66
         screenId = getString(screen, KEY_SCREEN);
35 67
         screenInstanceId = getString(screen, KEY_SCREEN_INSTANCE_ID);
36 68
         navigatorId = getString(screen, KEY_NAVIGATOR_ID);
37 69
         navigatorEventId = getString(screen, KEY_NAVIGATOR_EVENT_ID);
38 70
         icon = getInt(screen, KEY_ICON);
39 71
 
72
+        setButtons(screen);
73
+        setToolbarStyle(screen);
74
+    }
75
+
76
+    private void setButtons(ReadableMap screen) {
40 77
         if (screen.hasKey(KEY_RIGHT_BUTTONS)) {
41 78
             buttons = new ArrayList<>();
42 79
             ReadableArray rightButtons = screen.getArray(KEY_RIGHT_BUTTONS);
@@ -45,4 +82,18 @@ public class Screen extends JsonObject implements Serializable {
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 Parādīt failu

@@ -0,0 +1,16 @@
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 Parādīt failu

@@ -0,0 +1,13 @@
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 Parādīt failu

@@ -1,17 +1,23 @@
1 1
 package com.reactnativenavigation.views;
2 2
 
3
+import android.annotation.SuppressLint;
3 4
 import android.content.Context;
5
+import android.content.res.Resources;
4 6
 import android.graphics.drawable.Drawable;
5 7
 import android.os.AsyncTask;
8
+import android.support.v4.content.res.ResourcesCompat;
9
+import android.support.v7.app.ActionBar;
6 10
 import android.support.v7.widget.Toolbar;
7 11
 import android.util.AttributeSet;
8 12
 import android.view.Menu;
9 13
 import android.view.MenuItem;
10 14
 
15
+import com.reactnativenavigation.R;
11 16
 import com.reactnativenavigation.activities.BaseReactActivity;
12 17
 import com.reactnativenavigation.core.objects.Button;
13 18
 import com.reactnativenavigation.core.objects.Screen;
14 19
 import com.reactnativenavigation.utils.ContextProvider;
20
+import com.reactnativenavigation.utils.ImageUtils;
15 21
 
16 22
 import java.lang.ref.WeakReference;
17 23
 import java.util.Collections;
@@ -44,18 +50,34 @@ public class RnnToolBar extends Toolbar {
44 50
     }
45 51
 
46 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 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 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 83
     @SuppressWarnings({"ConstantConditions"})
@@ -64,12 +86,16 @@ public class RnnToolBar extends Toolbar {
64 86
     }
65 87
 
66 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 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 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 101
         @Override
@@ -80,7 +106,7 @@ public class RnnToolBar extends Toolbar {
80 106
             }
81 107
 
82 108
             Map<String, Drawable> icons = new HashMap<>();
83
-            for (Button button : mButtons) {
109
+            for (Button button : mNewButtons) {
84 110
                 if (button.hasIcon()) {
85 111
                     icons.put(button.id, button.getIcon(context));
86 112
                 }
@@ -97,24 +123,31 @@ public class RnnToolBar extends Toolbar {
97 123
 
98 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 131
             // Add new screen buttons
101 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 135
                 MenuItem item = menu.add(Menu.NONE, button.getItemId(), i, button.title);
105 136
                 if (icons.containsKey(button.id)) {
106 137
                     Drawable icon = icons.get(button.id);
138
+                    if (mTintColor != null) {
139
+                        ImageUtils.tint(icon, mTintColor);
140
+                    }
107 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 145
             RnnToolBar toolBar = mToolbarWR.get();
117 146
             if (toolBar != null) {
147
+                if (mTintColor != null) {
148
+                    ImageUtils.tint(toolBar.getOverflowIcon(), mTintColor);
149
+                }
150
+
118 151
                 toolBar.mSetupToolbarTask = null;
119 152
                 mToolbarWR.clear();
120 153
             }

+ 1
- 1
android/app/src/main/res/layout/single_screen_activity.xml Parādīt failu

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

+ 11
- 0
example-redux/src/screens/FirstTabScreen.js Parādīt failu

@@ -12,6 +12,17 @@ import * as counterActions from '../reducers/counter/actions';
12 12
 
13 13
 // this is a traditional React component connected to the redux store
14 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 26
   static navigatorButtons = {
16 27
     rightButtons: [
17 28
       {

+ 12
- 1
example-redux/src/screens/PushedScreen.js Parādīt failu

@@ -12,6 +12,17 @@ import * as counterActions from '../reducers/counter/actions';
12 12
 
13 13
 // this is a traditional React component connected to the redux store
14 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 26
   constructor(props) {
16 27
     super(props);
17 28
     this.bgColor = this.getRandomColor();
@@ -70,7 +81,7 @@ const styles = StyleSheet.create({
70 81
     textAlign: 'center',
71 82
     fontSize: 18,
72 83
     marginBottom: 10,
73
-    marginTop:10,
84
+    marginTop:10
74 85
   },
75 86
   button: {
76 87
     textAlign: 'center',

+ 8
- 0
src/platformSpecific.android.js Parādīt failu

@@ -21,6 +21,7 @@ function startSingleScreenApp(params) {
21 21
 
22 22
   addNavigatorParams(screen);
23 23
   addNavigatorButtons(screen);
24
+  addToolbarStyleParams(screen);
24 25
   RctActivity.startSingleScreenApp(screen);
25 26
 }
26 27
 
@@ -33,6 +34,7 @@ function startTabBasedApp(params) {
33 34
   params.tabs.forEach(function (tab, idx) {
34 35
     addNavigatorParams(tab, null, idx)
35 36
     addNavigatorButtons(tab);
37
+    addToolbarStyleParams(tab);
36 38
   });
37 39
 
38 40
   RctActivity.startTabBasedApp(params.tabs);
@@ -41,6 +43,7 @@ function startTabBasedApp(params) {
41 43
 function navigatorPush(navigator, params) {
42 44
   addNavigatorParams(params, navigator)
43 45
   addNavigatorButtons(params);
46
+  addToolbarStyleParams(params);
44 47
   RctActivity.navigatorPush(params);
45 48
 }
46 49
 
@@ -71,6 +74,11 @@ function addNavigatorButtons(screen) {
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 82
 export default {
75 83
   startSingleScreenApp,
76 84
   startTabBasedApp,