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 RTL text support #1145

Open
ArthurVimond opened this issue Mar 6, 2019 · 5 comments
Open

Add RTL text support #1145

ArthurVimond opened this issue Mar 6, 2019 · 5 comments
Labels

Comments

@ArthurVimond
Copy link
Contributor

Hi!
I'm currently working on adding RTL text support, and I have a few questions:

1- Should we detect the direction for each TextLayer input and draw them independently or just getting the device current language setting and apply the same direction for all texts?

2- Regarding the text justification, drawing RTL texts with Justification.LEFT_ALIGN should start from the right (not from the left), right? Also, should we refactor the Justification enums as START_ALIGN, CENTER, END_ALIGN (like layout margin / padding system)?

Thanks.

@gpeal gpeal added the Text label Mar 9, 2019
@gpeal
Copy link
Collaborator

gpeal commented Mar 9, 2019

@ArthurVimond Awesome!
1- What information would you use to detect the direction on a layer by layer basis?
2- That sounds like a good idea! I'm not super familiar with the inner workings with other text systems but that does seem to be parallel to Android's APIs which is good.

@gpeal gpeal mentioned this issue Mar 10, 2019
@ArthurVimond
Copy link
Contributor Author

@gpeal
1- For each layer (and maybe even for each line of a TextLayer), I was thinking about iterating on each character by using Character.getDirectionality(char ch) to determine the direction, and if all characters have the same RTL direction, the line will be RTL, otherwise, it will fallback to LTR.
By watching this video, After Effects' text direction detection is even more powerful as it's also done on words of different directionality.
2- I will then refactor the TextAlign left / right enums to start / end.

@gpeal
Copy link
Collaborator

gpeal commented Mar 11, 2019

@ArthurVimond Sounds good :) Rebase on master as I did some work in TextLayer for unicode support today.

@kartik1225
Copy link

kartik1225 commented Nov 4, 2019

@ArthurVimond Awesome!
1- What information would you use to detect the direction on a layer by layer basis?
2- That sounds like a good idea! I'm not super familiar with the inner workings with other text systems but that does seem to be parallel to Android's APIs which is good.

import java.text.Bidi;

Bidi bidi = new Bidi( title, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT );

if( bidi.isLeftToRight() ) {
   // it's LTR
} else {
   // it's RTL
}

This detects perfectly weather the text is RTL or LTR, So based on that we just need to put the right direction accordingly.
Found from stackoverflow.

@hfeky
Copy link

hfeky commented Mar 29, 2023

For anyone looking for a solution to do that for Lottie with Compose, I flipped the lottie composition by scaling the animation to the other direction like that.

fun Modifier.autoMirror(): Modifier = composed {
    if (LocalLayoutDirection.current == LayoutDirection.Rtl) {
        this.scale(scaleX = -1f, scaleY = 1f)
    } else {
        this
    }
}

and

val composition = rememberLottieComposition(LottieCompositionSpec.RawRes(...))
LottieAnimation(
    composition = bikeComposition.value,
    modifier = Modifier.autoMirror()
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants