浏览代码

Use margin to control component position relative to TopBar

RelativeLayout rules caused excessive CPU usage due to issues with RN's
keyboard detection mechanism (based on global layout listener)
Guy Carmeli 6 年前
父节点
当前提交
409a398da3
共有 1 个文件被更改,包括 2 次插入3 次删除
  1. 2
    3
      lib/android/app/src/main/java/com/reactnativenavigation/views/ComponentLayout.java

+ 2
- 3
lib/android/app/src/main/java/com/reactnativenavigation/views/ComponentLayout.java 查看文件

@@ -16,7 +16,6 @@ import com.reactnativenavigation.views.topbar.TopBar;
16 16
 import com.reactnativenavigation.views.touch.OverlayTouchDelegate;
17 17
 
18 18
 import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
19
-import static android.widget.RelativeLayout.BELOW;
20 19
 
21 20
 @SuppressLint("ViewConstructor")
22 21
 public class ComponentLayout extends FrameLayout implements ReactComponent, TopBarButtonController.OnClickListener {
@@ -84,7 +83,7 @@ public class ComponentLayout extends FrameLayout implements ReactComponent, TopB
84 83
     public void drawBehindTopBar() {
85 84
         if (getParent() instanceof RelativeLayout) {
86 85
             RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) getLayoutParams();
87
-            layoutParams.removeRule(BELOW);
86
+            layoutParams.topMargin = 0;
88 87
             setLayoutParams(layoutParams);
89 88
         }
90 89
     }
@@ -93,7 +92,7 @@ public class ComponentLayout extends FrameLayout implements ReactComponent, TopB
93 92
     public void drawBelowTopBar(TopBar topBar) {
94 93
         if (getParent() instanceof RelativeLayout) {
95 94
             RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) getLayoutParams();
96
-            layoutParams.addRule(BELOW, topBar.getId());
95
+            layoutParams.topMargin = topBar.getHeight();
97 96
             setLayoutParams(layoutParams);
98 97
         }
99 98
     }