-
-
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 support for text range selectors (#2518)
This adds support for the [text range selector](https://lottiefiles.github.io/lottie-docs/text/#text-range-selector) type, which allows a [text style](https://lottiefiles.github.io/lottie-docs/text/#text-style) to be applied to a certain range of the text, defined by a start, end, and offset. The text range selector implementation currently has the following limitations: - Only text layers drawn using a Font are supported. Adding support for the glyph draw path may be possible, but I don't have a sample Lottie file. - Only one text range is currently supported per text layer, as the parser [drops all other entries in the array](https://github.com/airbnb/lottie-android/blob/c4cb2254eca3c70199f1de5e39e3872c8c42e473/lottie/src/main/java/com/airbnb/lottie/parser/LayerParser.java#L194-L196). - Only index-based ranges are supported - percentage-based ranges are also allowed in the spec. - Only ranges based on characters are supported. The [spec](https://lottiefiles.github.io/lottie-docs/constants/#text-based) allows characters, characters excluding spaces, words, and lines. - Other options like easing (allows styling characters that are partially inside the range), randomize, and [shape](https://lottiefiles.github.io/lottie-docs/constants/#text-shape) of the range are not currently supported. This also adds support for the opacity as an animatable text property which is applied multiplicatively with the transform opacity and the parent's alpha. Partially addresses #485. https://github.com/user-attachments/assets/bcfad060-482d-48d9-a578-297c4f143ba9 https://github.com/user-attachments/assets/211dc574-5ea1-4fa3-9f78-f87ee104ce85 Co-authored-by: Allen Chen <[email protected]>
- Loading branch information
1 parent
328fc72
commit 71c1622
Showing
10 changed files
with
3,800 additions
and
55 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
25 changes: 25 additions & 0 deletions
25
lottie/src/main/java/com/airbnb/lottie/model/animatable/AnimatableTextRangeSelector.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,25 @@ | ||
package com.airbnb.lottie.model.animatable; | ||
|
||
import androidx.annotation.Nullable; | ||
import com.airbnb.lottie.model.content.TextRangeUnits; | ||
|
||
/** | ||
* Defines an animated range of text that should have an [AnimatableTextProperties] applied to it. | ||
*/ | ||
public class AnimatableTextRangeSelector { | ||
@Nullable public final AnimatableIntegerValue start; | ||
@Nullable public final AnimatableIntegerValue end; | ||
@Nullable public final AnimatableIntegerValue offset; | ||
public final TextRangeUnits units; | ||
|
||
public AnimatableTextRangeSelector( | ||
@Nullable AnimatableIntegerValue start, | ||
@Nullable AnimatableIntegerValue end, | ||
@Nullable AnimatableIntegerValue offset, | ||
TextRangeUnits units) { | ||
this.start = start; | ||
this.end = end; | ||
this.offset = offset; | ||
this.units = units; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
lottie/src/main/java/com/airbnb/lottie/model/animatable/AnimatableTextStyle.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,25 @@ | ||
package com.airbnb.lottie.model.animatable; | ||
|
||
import androidx.annotation.Nullable; | ||
|
||
public class AnimatableTextStyle { | ||
|
||
@Nullable public final AnimatableColorValue color; | ||
@Nullable public final AnimatableColorValue stroke; | ||
@Nullable public final AnimatableFloatValue strokeWidth; | ||
@Nullable public final AnimatableFloatValue tracking; | ||
@Nullable public final AnimatableIntegerValue opacity; | ||
|
||
public AnimatableTextStyle( | ||
@Nullable AnimatableColorValue color, | ||
@Nullable AnimatableColorValue stroke, | ||
@Nullable AnimatableFloatValue strokeWidth, | ||
@Nullable AnimatableFloatValue tracking, | ||
@Nullable AnimatableIntegerValue opacity) { | ||
this.color = color; | ||
this.stroke = stroke; | ||
this.strokeWidth = strokeWidth; | ||
this.tracking = tracking; | ||
this.opacity = opacity; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
lottie/src/main/java/com/airbnb/lottie/model/content/TextRangeUnits.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,6 @@ | ||
package com.airbnb.lottie.model.content; | ||
|
||
public enum TextRangeUnits { | ||
PERCENT, | ||
INDEX | ||
} |
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
Oops, something went wrong.