Browse Source

Cover ScreenImpl to RelativeLayout

Guy Carmeli 8 years ago
parent
commit
9832f92e6f

+ 6
- 5
android/app/src/main/java/com/reactnativenavigation/layouts/ScreenImpl.java View File

@@ -8,7 +8,7 @@ import android.os.Build;
8 8
 import android.util.Log;
9 9
 import android.view.View;
10 10
 import android.view.Window;
11
-import android.widget.LinearLayout;
11
+import android.widget.RelativeLayout;
12 12
 
13 13
 import com.reactnativenavigation.animation.OnScrollAnimator;
14 14
 import com.reactnativenavigation.params.ScreenParams;
@@ -21,7 +21,7 @@ import com.reactnativenavigation.views.TopBar;
21 21
 import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
22 22
 import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
23 23
 
24
-public class ScreenImpl extends LinearLayout implements Screen, ScrollDirectionListener.OnScrollChanged {
24
+public class ScreenImpl extends RelativeLayout implements Screen, ScrollDirectionListener.OnScrollChanged {
25 25
 
26 26
     private final ScreenParams screenParams;
27 27
     private ContentView contentView;
@@ -31,7 +31,6 @@ public class ScreenImpl extends LinearLayout implements Screen, ScrollDirectionL
31 31
     public ScreenImpl(Context context, ScreenParams screenParams) {
32 32
         super(context);
33 33
         this.screenParams = screenParams;
34
-        setOrientation(VERTICAL);
35 34
 
36 35
         createViews();
37 36
         setStyle(screenParams.styleParams);
@@ -50,12 +49,14 @@ public class ScreenImpl extends LinearLayout implements Screen, ScrollDirectionL
50 49
 
51 50
     private void addTopBar() {
52 51
         topBar = new TopBar(getContext());
53
-        addView(topBar, new LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT));
52
+        addView(topBar, new LayoutParams(MATCH_PARENT, WRAP_CONTENT));
54 53
     }
55 54
 
56 55
     private void addContentView() {
57 56
         contentView = new ContentView(getContext(), screenParams, this);
58
-        addView(contentView, new LayoutParams(MATCH_PARENT, MATCH_PARENT));
57
+        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT);
58
+        params.addRule(RelativeLayout.BELOW, topBar.getId());
59
+        addView(contentView, params);
59 60
         contentView.init();
60 61
     }
61 62
 

+ 8
- 0
android/app/src/main/java/com/reactnativenavigation/utils/ViewUtils.java View File

@@ -8,7 +8,11 @@ import android.view.ViewTreeObserver;
8 8
 
9 9
 import com.reactnativenavigation.NavigationApplication;
10 10
 
11
+import java.util.concurrent.atomic.AtomicInteger;
12
+
11 13
 public class ViewUtils {
14
+    private static final AtomicInteger viewId = new AtomicInteger();
15
+
12 16
     public static void runOnPreDraw(final View view, final Runnable task) {
13 17
         view.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
14 18
             @Override
@@ -31,5 +35,9 @@ public class ViewUtils {
31 35
         float scale = NavigationApplication.instance.getResources().getDisplayMetrics().density;
32 36
         return dp * scale + 0.5f;
33 37
     }
38
+
39
+    public static int generateViewId() {
40
+        return viewId.incrementAndGet();
41
+    }
34 42
 }
35 43
 

+ 2
- 0
android/app/src/main/java/com/reactnativenavigation/views/TopBar.java View File

@@ -4,6 +4,7 @@ import android.content.Context;
4 4
 import android.support.design.widget.AppBarLayout;
5 5
 
6 6
 import com.reactnativenavigation.params.TitleBarButtonParams;
7
+import com.reactnativenavigation.utils.ViewUtils;
7 8
 
8 9
 import java.util.List;
9 10
 
@@ -14,6 +15,7 @@ public class TopBar extends AppBarLayout {
14 15
     public TopBar(Context context) {
15 16
         super(context);
16 17
         setFitsSystemWindows(true);
18
+        setId(ViewUtils.generateViewId());
17 19
     }
18 20
 
19 21
     public void addTitleBarAndSetButtons(List<TitleBarButtonParams> buttons, String navigatorEventId) {