Browse Source

Fixes AppBarLayout delayed init of elevation (#3601)

Matheus 6 years ago
parent
commit
c9ebfccb9f

+ 2
- 2
lib/android/app/src/main/java/com/reactnativenavigation/presentation/StackOptionsPresenter.java View File

@@ -73,7 +73,7 @@ public class StackOptionsPresenter {
73 73
 
74 74
     private void applyTopBarOptions(TopBarOptions options, AnimationsOptions animationOptions, Component component, Options componentOptions) {
75 75
         topBar.setHeight(options.height.get(LayoutParams.WRAP_CONTENT));
76
-        topBar.setElevation(options.elevation);
76
+        topBar.setElevation(options.elevation.get(4d));
77 77
 
78 78
         topBar.setTitleHeight(options.title.height.get(LayoutParams.WRAP_CONTENT));
79 79
         topBar.setTitle(options.title.text.get(""));
@@ -172,7 +172,7 @@ public class StackOptionsPresenter {
172 172
 
173 173
     private void mergeTopBarOptions(TopBarOptions options, AnimationsOptions animationsOptions, Component component) {
174 174
         if (options.height.hasValue()) topBar.setHeight(options.height.get());
175
-        if (options.elevation.hasValue()) topBar.setElevation(options.elevation);
175
+        if (options.elevation.hasValue()) topBar.setElevation(options.elevation.get());
176 176
 
177 177
         if (options.title.height.hasValue()) topBar.setTitleHeight(options.title.height.get());
178 178
         if (options.title.text.hasValue()) topBar.setTitle(options.title.text.get());

+ 6
- 6
lib/android/app/src/main/java/com/reactnativenavigation/views/topbar/TopBar.java View File

@@ -20,6 +20,7 @@ import android.widget.RelativeLayout;
20 20
 import android.widget.TextView;
21 21
 
22 22
 import com.reactnativenavigation.BuildConfig;
23
+import com.reactnativenavigation.R;
23 24
 import com.reactnativenavigation.anim.TopBarAnimator;
24 25
 import com.reactnativenavigation.anim.TopBarCollapseBehavior;
25 26
 import com.reactnativenavigation.interfaces.ScrollEventListener;
@@ -29,7 +30,6 @@ import com.reactnativenavigation.parse.BackButton;
29 30
 import com.reactnativenavigation.parse.Component;
30 31
 import com.reactnativenavigation.parse.params.Button;
31 32
 import com.reactnativenavigation.parse.params.Color;
32
-import com.reactnativenavigation.parse.params.Fraction;
33 33
 import com.reactnativenavigation.parse.params.Number;
34 34
 import com.reactnativenavigation.utils.CompatUtils;
35 35
 import com.reactnativenavigation.utils.ImageLoader;
@@ -63,6 +63,7 @@ public class TopBar extends AppBarLayout implements ScrollEventListener.ScrollAw
63 63
 
64 64
     public TopBar(final Context context, ReactViewCreator buttonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewController topBarBackgroundViewController, TopBarButtonController.OnClickListener onClickListener, StackLayout parentView, ImageLoader imageLoader) {
65 65
         super(context);
66
+        context.setTheme(R.style.TopBar);
66 67
         this.imageLoader = imageLoader;
67 68
         collapsingBehavior = new TopBarCollapseBehavior(this);
68 69
         this.topBarBackgroundViewController = topBarBackgroundViewController;
@@ -225,11 +226,10 @@ public class TopBar extends AppBarLayout implements ScrollEventListener.ScrollAw
225 226
         titleBar.setRightButtons(rightButtons);
226 227
     }
227 228
 
228
-    public void setElevation(Fraction elevation) {
229
-        if (elevation.hasValue() &&
230
-            Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP &&
231
-            getElevation() != elevation.get().floatValue()) {
232
-            setElevation(UiUtils.dpToPx(getContext(), elevation.get().floatValue()));
229
+    public void setElevation(Double elevation) {
230
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP &&
231
+                getElevation() != elevation.floatValue()) {
232
+            setElevation(UiUtils.dpToPx(getContext(), elevation.floatValue()));
233 233
         }
234 234
     }
235 235
 

+ 5
- 0
lib/android/app/src/main/res/values/styles.xml View File

@@ -10,4 +10,9 @@
10 10
         <item name="android:windowEnterAnimation">@null</item>
11 11
         <item name="android:windowExitAnimation">@null</item>
12 12
     </style>
13
+
14
+    <style name="TopBar" parent="ThemeOverlay.AppCompat.ActionBar">
15
+        <item name="elevation">0dp</item>
16
+    </style>
17
+
13 18
 </resources>