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 defStyleAttr to LottieAnimationView #1523

Closed
ataulm opened this issue Feb 24, 2020 · 1 comment · Fixed by #1524
Closed

Add support for defStyleAttr to LottieAnimationView #1523

ataulm opened this issue Feb 24, 2020 · 1 comment · Fixed by #1524

Comments

@ataulm
Copy link
Contributor

ataulm commented Feb 24, 2020

Is your feature request related to a problem? Please describe.

LottieAnimationView provides the 3-arg view constructor, which allows passing a defStyleAttr from a subclass (e.g. MyLoadingSpinnerView), but doesn't use it.

This means that any LottieAnimationView-specific attributes will not be read from a default style.

Describe the solution you'd like

Pass the defStyleAttr to the init function, and pass it when obtaining styled attributes:

private void init(@Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
    TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.LottieAnimationView, defStyleAttr, 0);
    if (!isInEditMode()) {
        boolean hasRawRes = ta.hasValue(R.styleable.LottieAnimationView_lottie_rawRes);
        ...

Describe alternatives you've considered

Applying the style explicitly in the layout every time:

<MyLoadingSpinnerView
    style="@style/Widget.MyApp.MyLoadingSpinnerView"
    android:layout_width="40dp"
    android:layout_height="40dp" />

Additional context

Happy to do a PR if this issue is accepted!

Lottie is supported and developed on nights and weekends. Please consider sponsoring Lottie to prioritize this issue and help support this issue as well as future investments.

@gpeal
Copy link
Collaborator

gpeal commented Feb 27, 2020

@ataulm I would accept a PR for this!

gpeal pushed a commit that referenced this issue Mar 2, 2020
nihad92 pushed a commit to nihad92/lottie-android that referenced this issue May 19, 2020
nihad92 pushed a commit to nihad92/lottie-android that referenced this issue May 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants