Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for foregroundTint and foregroundTintMode #169

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions paris/src/main/java/com/airbnb/paris/proxies/ViewProxy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.annotation.Px
import androidx.annotation.RequiresApi
import androidx.core.view.ViewCompat
import com.airbnb.paris.R2
import com.airbnb.paris.R2.attr.tintMode
import com.airbnb.paris.annotations.AfterStyle
import com.airbnb.paris.annotations.Attr
import com.airbnb.paris.annotations.LayoutDimension
Expand Down Expand Up @@ -294,6 +295,19 @@ class ViewProxy(view: View) : BaseProxy<ViewProxy, View>(view) {
view.foreground = drawable
}

@Attr(R2.styleable.Paris_View_android_foregroundTint)
@RequiresApi(Build.VERSION_CODES.M)
fun setForegroundTint(colorStateList: ColorStateList?) {
view.foregroundTintList = colorStateList
}

@Attr(R2.styleable.Paris_View_android_foregroundTintMode)
@RequiresApi(Build.VERSION_CODES.M)
fun setForegroundTintMode(tintMode: Int) {
view.foregroundTintMode = parseTintMode(tintMode)
}


@Attr(R2.styleable.Paris_View_android_minHeight)
fun setMinHeight(@Px minHeight: Int) {
view.minimumHeight = minHeight
Expand Down
6 changes: 4 additions & 2 deletions paris/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<attr name="android:elevation" />
<attr name="android:focusable" />
<attr name="android:foreground" />
<attr name="android:foregroundTint" />
<attr name="android:foregroundTintMode" />
<attr name="android:layout_width" />
<attr name="android:layout_height" />
<attr name="android:layout_gravity" />
Expand All @@ -23,7 +25,7 @@
<attr name="android:layout_marginStart" />
<attr name="android:layout_marginTop" />
<attr name="android:layout_marginVertical" />
<attr name="android:layout_weight"/>
<attr name="android:layout_weight" />
<attr name="android:minHeight" />
<attr name="android:minWidth" />
<attr name="android:padding" />
Expand Down Expand Up @@ -60,7 +62,7 @@
<attr name="android:fontFamily" />
<attr name="android:gravity" />
<attr name="android:letterSpacing" />
<attr name="android:lineHeight"/>
<attr name="android:lineHeight" />
<attr name="android:lines" />
<attr name="android:lineSpacingExtra" />
<attr name="android:lineSpacingMultiplier" />
Expand Down
22 changes: 22 additions & 0 deletions paris/src/testDebug/java/com/airbnb/paris/proxies/ViewProxyTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,28 @@ class ViewProxyTest {
assertEquals(null, view.foreground)
}

@Test
fun setForegroundTint() {
// First set the tint to something else
view.foregroundTintList = ContextCompat.getColorStateList(context, android.R.color.black)
proxy.setForegroundTint(ContextCompat.getColorStateList(context, android.R.color.holo_red_dark))
assertEquals(
ContextCompat.getColorStateList(context, android.R.color.holo_red_dark),
view.foregroundTintList
)
}

@Test
fun setForegroundTintMode() {
// First set the porterduff mode to something else
view.foregroundTintMode = PorterDuff.Mode.SRC_OVER
proxy.setForegroundTintMode(ViewProxy.PORTERDUFF_MODE_ADD)
assertEquals(
PorterDuff.Mode.ADD,
view.foregroundTintMode
)
}

@Test
fun setVisibility_visibleProgrammatic() {
// Since visible is the default first set the visibility to something else
Expand Down