-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add generalized Lottie Feature Flags API (#2512)
Currently there are individual methods for enabling and disabling Merge Paths in Lottie. This PR aims to generalize these functions as we consider adding more features guarded behind opt-in flags.
- Loading branch information
Showing
8 changed files
with
107 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
lottie/src/main/java/com/airbnb/lottie/LottieFeatureFlag.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.airbnb.lottie; | ||
|
||
import android.os.Build; | ||
|
||
public enum LottieFeatureFlag { | ||
/** | ||
* Merge paths currently don't work if the the operand shape is entirely contained within the | ||
* first shape. If you need to cut out one shape from another shape, use an even-odd fill type | ||
* instead of using merge paths. | ||
*/ | ||
MergePathsApi19(Build.VERSION_CODES.KITKAT); | ||
|
||
public final int minRequiredSdkVersion; | ||
|
||
LottieFeatureFlag(int minRequiredSdkVersion) { | ||
this.minRequiredSdkVersion = minRequiredSdkVersion; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
lottie/src/main/java/com/airbnb/lottie/LottieFeatureFlags.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.airbnb.lottie; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.os.Build; | ||
|
||
import com.airbnb.lottie.utils.Logger; | ||
|
||
import java.util.HashSet; | ||
|
||
class LottieFeatureFlags { | ||
|
||
private final HashSet<LottieFeatureFlag> enabledFlags = new HashSet<>(); | ||
|
||
/** | ||
* Returns true if the flag was changed. | ||
*/ | ||
@SuppressLint("DefaultLocale") | ||
public boolean enableFlag(LottieFeatureFlag flag, boolean enable) { | ||
if (enable) { | ||
if (Build.VERSION.SDK_INT < flag.minRequiredSdkVersion) { | ||
Logger.warning(String.format("%s is not supported pre SDK %d", flag.name(), flag.minRequiredSdkVersion)); | ||
return false; | ||
} | ||
return enabledFlags.add(flag); | ||
} else { | ||
return enabledFlags.remove(flag); | ||
} | ||
} | ||
|
||
public boolean isFlagEnabled(LottieFeatureFlag flag) { | ||
return enabledFlags.contains(flag); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters