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
 import android.util.Log;
8
 import android.util.Log;
9
 import android.view.View;
9
 import android.view.View;
10
 import android.view.Window;
10
 import android.view.Window;
11
-import android.widget.LinearLayout;
11
+import android.widget.RelativeLayout;
12
 
12
 
13
 import com.reactnativenavigation.animation.OnScrollAnimator;
13
 import com.reactnativenavigation.animation.OnScrollAnimator;
14
 import com.reactnativenavigation.params.ScreenParams;
14
 import com.reactnativenavigation.params.ScreenParams;
21
 import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
21
 import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
22
 import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
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
     private final ScreenParams screenParams;
26
     private final ScreenParams screenParams;
27
     private ContentView contentView;
27
     private ContentView contentView;
31
     public ScreenImpl(Context context, ScreenParams screenParams) {
31
     public ScreenImpl(Context context, ScreenParams screenParams) {
32
         super(context);
32
         super(context);
33
         this.screenParams = screenParams;
33
         this.screenParams = screenParams;
34
-        setOrientation(VERTICAL);
35
 
34
 
36
         createViews();
35
         createViews();
37
         setStyle(screenParams.styleParams);
36
         setStyle(screenParams.styleParams);
50
 
49
 
51
     private void addTopBar() {
50
     private void addTopBar() {
52
         topBar = new TopBar(getContext());
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
     private void addContentView() {
55
     private void addContentView() {
57
         contentView = new ContentView(getContext(), screenParams, this);
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
         contentView.init();
60
         contentView.init();
60
     }
61
     }
61
 
62
 

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

8
 
8
 
9
 import com.reactnativenavigation.NavigationApplication;
9
 import com.reactnativenavigation.NavigationApplication;
10
 
10
 
11
+import java.util.concurrent.atomic.AtomicInteger;
12
+
11
 public class ViewUtils {
13
 public class ViewUtils {
14
+    private static final AtomicInteger viewId = new AtomicInteger();
15
+
12
     public static void runOnPreDraw(final View view, final Runnable task) {
16
     public static void runOnPreDraw(final View view, final Runnable task) {
13
         view.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
17
         view.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
14
             @Override
18
             @Override
31
         float scale = NavigationApplication.instance.getResources().getDisplayMetrics().density;
35
         float scale = NavigationApplication.instance.getResources().getDisplayMetrics().density;
32
         return dp * scale + 0.5f;
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
 import android.support.design.widget.AppBarLayout;
4
 import android.support.design.widget.AppBarLayout;
5
 
5
 
6
 import com.reactnativenavigation.params.TitleBarButtonParams;
6
 import com.reactnativenavigation.params.TitleBarButtonParams;
7
+import com.reactnativenavigation.utils.ViewUtils;
7
 
8
 
8
 import java.util.List;
9
 import java.util.List;
9
 
10
 
14
     public TopBar(Context context) {
15
     public TopBar(Context context) {
15
         super(context);
16
         super(context);
16
         setFitsSystemWindows(true);
17
         setFitsSystemWindows(true);
18
+        setId(ViewUtils.generateViewId());
17
     }
19
     }
18
 
20
 
19
     public void addTitleBarAndSetButtons(List<TitleBarButtonParams> buttons, String navigatorEventId) {
21
     public void addTitleBarAndSetButtons(List<TitleBarButtonParams> buttons, String navigatorEventId) {