Skip to content

Commit

Permalink
Apply elevation attribute only when running on devices that support i… (
Browse files Browse the repository at this point in the history
#86)

* 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
  • Loading branch information
plnice authored and ngsilverman committed Nov 1, 2018
1 parent 8d18192 commit 5128eb5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions paris/src/main/java/com/airbnb/paris/proxies/ViewProxy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,16 @@ class ViewProxy(view: View) : BaseProxy<ViewProxy, View>(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)
Expand Down

0 comments on commit 5128eb5

Please sign in to comment.