Skip to content

Commit

Permalink
Add lottieAnimationViewStyle attribute to set a default style in them…
Browse files Browse the repository at this point in the history
…es (#1524)

Fixes #1523, with an enhancement.
  • Loading branch information
ataulm authored Mar 2, 2020
1 parent 1330634 commit 708b54b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import android.util.Log;
import android.view.View;

import androidx.annotation.AttrRes;
import androidx.annotation.DrawableRes;
import androidx.annotation.FloatRange;
import androidx.annotation.MainThread;
Expand Down Expand Up @@ -122,21 +123,21 @@ public void onResult(Throwable result) {

public LottieAnimationView(Context context) {
super(context);
init(null);
init(null, R.attr.lottieAnimationViewStyle);
}

public LottieAnimationView(Context context, AttributeSet attrs) {
super(context, attrs);
init(attrs);
init(attrs, R.attr.lottieAnimationViewStyle);
}

public LottieAnimationView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(attrs);
init(attrs, defStyleAttr);
}

private void init(@Nullable AttributeSet attrs) {
TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.LottieAnimationView);
private void init(@Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.LottieAnimationView, defStyleAttr, 0);
if (!isInEditMode()) {
cacheComposition = ta.getBoolean(R.styleable.LottieAnimationView_lottie_cacheComposition, true);
boolean hasRawRes = ta.hasValue(R.styleable.LottieAnimationView_lottie_rawRes);
Expand Down
2 changes: 2 additions & 0 deletions lottie/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="lottieAnimationViewStyle" format="reference" />

<declare-styleable name="LottieAnimationView">
<attr name="lottie_fileName" format="string" />
<attr name="lottie_rawRes" format="reference" />
Expand Down

0 comments on commit 708b54b

Please sign in to comment.