From 5128eb5a6202b281846a477d3c367f4f4a935203 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz?= Date: Thu, 1 Nov 2018 16:26:38 +0100 Subject: [PATCH] =?UTF-8?q?Apply=20elevation=20attribute=20only=20when=20r?= =?UTF-8?q?unning=20on=20devices=20that=20support=20i=E2=80=A6=20(#86)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Apply elevation attribute only when running on devices that support it (5.0+) This prevents crashes on some Android 4.4 devices due to invalid attribute value parsed as elevation value. Fixes issue #73. * Add explanation on android:elevation support and pre-API 21 issues --- .../main/java/com/airbnb/paris/proxies/ViewProxy.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/paris/src/main/java/com/airbnb/paris/proxies/ViewProxy.kt b/paris/src/main/java/com/airbnb/paris/proxies/ViewProxy.kt index e4c4319f..49add5a0 100644 --- a/paris/src/main/java/com/airbnb/paris/proxies/ViewProxy.kt +++ b/paris/src/main/java/com/airbnb/paris/proxies/ViewProxy.kt @@ -233,10 +233,16 @@ class ViewProxy(view: View) : BaseProxy(view) { view.contentDescription = contentDescription } - // TODO Fix Samsung bug, see https://github.com/airbnb/paris/issues/70#issuecomment-421332864 + /** + * android:elevation attribute and View.setElevation() method are supported since Lollipop. ViewCompat version of setElevation() method is + * available, but currently doesn't have any effect on pre-Lollipop devices. Also, requesting android:elevation attribute value gives some + * unpredicted values on some Kitkat-based Samsung devices (see https://github.com/airbnb/paris/issues/73). That's why we're parsing + * android:elevation attribute only when running Lollipop and use View.setElevation() for now. + */ @Attr(R2.styleable.Paris_View_android_elevation) + @RequiresApi(Build.VERSION_CODES.LOLLIPOP) fun setElevation(@Px elevation: Int) { - ViewCompat.setElevation(view, elevation.toFloat()) + view.elevation = elevation.toFloat() } @Attr(R2.styleable.Paris_View_android_foreground)