Browse Source

Add paddingTop to android ToolBar. (#2266)

* Add paddingTop to android ToolBar.

* Update documentation
Chaitanya Bhagvan 6 years ago
parent
commit
5a2bc27ef4

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/params/StyleParams.java View File

@@ -123,6 +123,7 @@ public class StyleParams {
123 123
     public int titleBarHeight;
124 124
     public boolean backButtonHidden;
125 125
     public Font titleBarButtonFontFamily;
126
+    public int titleBarTopPadding;
126 127
 
127 128
     public Color topTabTextColor;
128 129
     public Font topTabTextFontFamily;

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/params/parsers/StyleParamsParser.java View File

@@ -69,6 +69,7 @@ public class StyleParamsParser {
69 69
         result.titleBarHeight = getInt("titleBarHeight", getDefaultTitleBarHeight());
70 70
         result.backButtonHidden = getBoolean("backButtonHidden", getDefaultBackButtonHidden());
71 71
         result.topTabsHidden = getBoolean("topTabsHidden", getDefaultTopTabsHidden());
72
+        result.titleBarTopPadding = getInt("titleBarTopPadding", getTitleBarTopPadding());
72 73
 
73 74
         result.topTabTextColor = getColor("topTabTextColor", getDefaultTopTabTextColor());
74 75
         result.topTabTextFontFamily = getFont("topTabTextFontFamily", getDefaultTopTabTextFontFamily());
@@ -328,6 +329,10 @@ public class StyleParamsParser {
328 329
         return AppStyle.appStyle == null ? -1 : AppStyle.appStyle.titleBarHeight;
329 330
     }
330 331
 
332
+    private int getTitleBarTopPadding() {
333
+        return AppStyle.appStyle == null ? 0 : AppStyle.appStyle.titleBarTopPadding;
334
+    }
335
+
331 336
     private boolean getBoolean(String key, boolean defaultValue) {
332 337
         return params.containsKey(key) ? params.getBoolean(key) : defaultValue;
333 338
     }

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/views/TitleBar.java View File

@@ -85,6 +85,7 @@ public class TitleBar extends Toolbar {
85 85
         colorOverflowButton(params);
86 86
         setBackground(params);
87 87
         centerTitle(params);
88
+        setTopPadding(params);
88 89
     }
89 90
 
90 91
     public void setVisibility(boolean titleBarHidden) {
@@ -134,6 +135,10 @@ public class TitleBar extends Toolbar {
134 135
         });
135 136
     }
136 137
 
138
+    private void setTopPadding(final StyleParams params) {
139
+        setPadding(0, params.titleBarTopPadding, 0,0);
140
+    }
141
+
137 142
     private void colorOverflowButton(StyleParams params) {
138 143
         Drawable overflowIcon = actionMenuView.getOverflowIcon();
139 144
         if (shouldColorOverflowButton(params, overflowIcon)) {

+ 1
- 0
docs/styling-the-navigator.md View File

@@ -107,6 +107,7 @@ this.props.navigator.setStyle({
107 107
   collapsingToolBarCollapsedColor: '#0f2362', // Collapsing Toolbar scrim color.
108 108
   navBarTextFontBold: false, // Optional. Set the title to bold.
109 109
   navBarHeight: 70, // Optional, set the navBar height in pixels.
110
+  navBarTopPadding: 24, // Optional, set navBar top padding in pixels. Useful when StatusBar.translucent=true on Android Lollipop and above.
110 111
   topTabsHeight: 70, // Optional, set topTabs height in pixels.
111 112
   topBarBorderColor: 'red', Optional, set a flat border under the TopBar.
112 113
   topBarBorderWidth: 5.5, // Optional, set the width of the border.

+ 1
- 0
src/deprecated/platformSpecificDeprecated.android.js View File

@@ -181,6 +181,7 @@ function convertStyleParams(originalStyleObject) {
181 181
     titleBarTitleFontBold: originalStyleObject.navBarTextFontBold,
182 182
     titleBarTitleTextCentered: originalStyleObject.navBarTitleTextCentered,
183 183
     titleBarHeight: originalStyleObject.navBarHeight,
184
+    titleBarTopPadding: originalStyleObject.navBarTopPadding,
184 185
     backButtonHidden: originalStyleObject.backButtonHidden,
185 186
     topTabsHidden: originalStyleObject.topTabsHidden,
186 187
     contextualMenuStatusBarColor: processColor(originalStyleObject.contextualMenuStatusBarColor),