瀏覽代碼

Implement layout.topMargin

This option property lets us set a top margin to a component which can be useful sometimes
when using statusBar.drawBehind.
Guy Carmeli 6 年之前
父節點
當前提交
c57fcf2c79

+ 5
- 2
lib/android/app/src/main/java/com/reactnativenavigation/presentation/OptionsPresenter.java 查看文件

@@ -4,7 +4,7 @@ import android.app.Activity;
4 4
 import android.graphics.Color;
5 5
 import android.os.Build;
6 6
 import android.view.View;
7
-import android.view.ViewGroup;
7
+import android.view.ViewGroup.MarginLayoutParams;
8 8
 
9 9
 import com.reactnativenavigation.parse.Options;
10 10
 import com.reactnativenavigation.parse.OrientationOptions;
@@ -40,6 +40,9 @@ public class OptionsPresenter {
40 40
         if (options.layout.backgroundColor.hasValue()) {
41 41
             view.setBackgroundColor(options.layout.backgroundColor.get());
42 42
         }
43
+        if (options.layout.topMargin.hasValue()) {
44
+            ((MarginLayoutParams) view.getLayoutParams()).topMargin = options.layout.topMargin.get();
45
+        }
43 46
     }
44 47
 
45 48
     public void onViewBroughtToFront(View view, Options options) {
@@ -86,7 +89,7 @@ public class OptionsPresenter {
86 89
     }
87 90
 
88 91
     private void setDrawBehindStatusBar(View view, StatusBarOptions statusBar) {
89
-        ((ViewGroup.MarginLayoutParams) view.getLayoutParams()).topMargin = statusBar.drawBehind.isFalseOrUndefined() ?
92
+        ((MarginLayoutParams) view.getLayoutParams()).topMargin = statusBar.drawBehind.isFalseOrUndefined() ?
90 93
                 UiUtils.getStatusBarHeight(activity) :
91 94
                 0;
92 95
     }

+ 1
- 1
lib/android/app/src/main/java/com/reactnativenavigation/presentation/StackOptionsPresenter.java 查看文件

@@ -79,7 +79,7 @@ public class StackOptionsPresenter {
79 79
                 topBar.show();
80 80
             }
81 81
         }
82
-        if (options.drawBehind.isTrue()) {
82
+        if (options.drawBehind.isTrue() && !componentOptions.layout.topMargin.hasValue()) {
83 83
             component.drawBehindTopBar();
84 84
         } else if (options.drawBehind.isFalseOrUndefined()) {
85 85
             component.drawBelowTopBar(topBar);