Browse Source

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 years ago
parent
commit
409a398da3

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

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