-
-
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.
[a11y] Changing logic of how reduce motion options are set to match i…
…t with lottie iOS (#2536) This PR introduces a new way to determine if reduce motion is enabled or not. It matches iOS Lottie API airbnb/lottie-ios#2110. This change provides the ability for apps integrating Lottie to have custom reduce motion behavior which doesn't need to rely solely on system settings. This change also allows reduce motion to work regardless of usage of LottieAnimationView, LottieAnimation in compose or straight LottieDrawable. Testing Verified that the default ReducedMotionOptionProvider is correctly used when none is provided. Ensured that custom implementations of ReducedMotionOption can be set and used. Updated existing test for LottieDrawable reduce motion. Co-authored-by: Pranay Airan <[email protected]>
- Loading branch information
1 parent
f328222
commit 733999b
Showing
12 changed files
with
180 additions
and
8 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
14 changes: 14 additions & 0 deletions
14
...a/com/airbnb/lottie/configurations/reducemotion/IgnoreDisabledSystemAnimationsOption.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,14 @@ | ||
package com.airbnb.lottie.configurations.reducemotion; | ||
|
||
import android.content.Context; | ||
|
||
/** | ||
* Allows ignoring system animations settings, therefore allowing animations to run even if they are disabled. | ||
*/ | ||
public class IgnoreDisabledSystemAnimationsOption implements ReducedMotionOption { | ||
|
||
@Override | ||
public ReducedMotionMode getCurrentReducedMotionMode(Context context) { | ||
return ReducedMotionMode.STANDARD_MOTION; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
lottie/src/main/java/com/airbnb/lottie/configurations/reducemotion/ReducedMotionMode.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,16 @@ | ||
package com.airbnb.lottie.configurations.reducemotion; | ||
|
||
|
||
public enum ReducedMotionMode { | ||
/** | ||
* The default behavior where Lottie animations play normally with no overrides. | ||
* By default this mode is used when {@link com.airbnb.lottie.utils.Utils#getAnimationScale(Context)} is not 0. | ||
*/ | ||
STANDARD_MOTION, | ||
|
||
/** | ||
* Lottie animations with a "reduced motion" marker will play that marker instead of any other animations. | ||
* By default this mode is used when {@link com.airbnb.lottie.utils.Utils#getAnimationScale(Context)} == 0. | ||
*/ | ||
REDUCED_MOTION | ||
} |
11 changes: 11 additions & 0 deletions
11
lottie/src/main/java/com/airbnb/lottie/configurations/reducemotion/ReducedMotionOption.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,11 @@ | ||
package com.airbnb.lottie.configurations.reducemotion; | ||
|
||
import android.content.Context; | ||
|
||
public interface ReducedMotionOption { | ||
|
||
/** | ||
* Returns the current reduced motion mode. | ||
*/ | ||
ReducedMotionMode getCurrentReducedMotionMode(Context context); | ||
} |
28 changes: 28 additions & 0 deletions
28
...rc/main/java/com/airbnb/lottie/configurations/reducemotion/SystemReducedMotionOption.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,28 @@ | ||
package com.airbnb.lottie.configurations.reducemotion; | ||
|
||
import android.content.Context; | ||
import com.airbnb.lottie.utils.Utils; | ||
|
||
/** | ||
* Lottie animations with a "reduced motion" marker will play that marker instead of any other animations. | ||
* This class uses {@link com.airbnb.lottie.utils.Utils#getAnimationScale(Context)} to determine if animations are disabled | ||
* and if it should play the reduced motion marker. | ||
* | ||
* If the animation is provided a "reduced motion" | ||
* marker name, they will be shown instead of the first or last frame. Supported marker names are case insensitive, and include: | ||
* - reduced motion | ||
* - reducedMotion | ||
* - reduced_motion | ||
* - reduced-motion | ||
*/ | ||
public class SystemReducedMotionOption implements ReducedMotionOption { | ||
|
||
@Override | ||
public ReducedMotionMode getCurrentReducedMotionMode(Context context) { | ||
if (Utils.getAnimationScale(context) != 0f) { | ||
return ReducedMotionMode.STANDARD_MOTION; | ||
} else { | ||
return ReducedMotionMode.REDUCED_MOTION; | ||
} | ||
} | ||
} |
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