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

TextView paris.extensions.style works on Android 12 but crashed on Android 9 with customized style. #171

Open
donlingliang opened this issue Jan 19, 2023 · 0 comments

Comments

@donlingliang
Copy link

Hi Paris developers,

We had an XmlPullParserException crash in Android 9 (API level 28) when using customized style.

The original code snippet below are the code that crashed.

CustomTextView constructor(context: Context): AppCompatTextView() {
    @ModelProp
    @JvmOverloads
    fun setTextStyle(style: TextStyle = TextStyle.BODY) = style(R.style.custom)
}

style resources:

<style name="CustomTextView.custom">
        <item name="android:textSize">12sp</item>
        <item name="android:fontFamily">@font/medium</item>
        <item name="fontFamily">@font/medium</item>
        <item name="android:background">@color/selector_clickable_text</item>
        <item name="android:clickable">true</item>
        <item name="android:focusable">true</item>
</style>

color:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:color="@color/pressed"/>
    <item android:state_selected="true" android:color="@color/pressed"/>
    <item android:state_activated="true" android:color="@color/pressed"/>
    <item android:color="@color/transparent"/>
</selector>

Based on the stacktrace:

LOCATION:
TypedArrayTypedArrayWrapper.java line 45 in com.airbnb.paris.typed_array_wrappers.TypedArrayTypedArrayWrapper.getDrawable()
EXCEPTION:
org.xmlpull.v1.XmlPullParserException
MESSAGE:
Binary XML file line #2: <item> tag requires a 'drawable' attribute or child tag defining a drawable

I think the correct way is change the color resource from android:color with android:drawable like below.

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@color/pressed"/>
    <item android:state_selected="true" android:drawable="@color/pressed"/>
    <item android:drawable="@color/transparent"/>
</selector>

But I don't know why the original code works on Android 12 and no crash, when crashing on Android 9. Try to look into the source code TextViewStyleApplier and etc, don't find anything related to VERSION.SDK_INT and wrong usage on android:color that only cause the Android 9 crash.

Appreciated that anyone has some insights or ideas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant