Sfoglia il codice sorgente

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 anni fa
parent
commit
409a398da3

+ 2
- 3
lib/android/app/src/main/java/com/reactnativenavigation/views/ComponentLayout.java Vedi File

@@ -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
     }