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

fix(Android, iOS): Fix AnsiHighlight Style in RTL Layout #47230

Closed
wants to merge 3 commits into from

Conversation

hexboy
Copy link
Contributor

@hexboy hexboy commented Oct 27, 2024

Summary:

This pull request fixes a style bug in the AnsiHighlight component when the application is in Right-To-Left (RTL) mode. The adjustments ensure that text highlighting is visually consistent and functions properly across all layout modes.

Before

Android RTL iOS RTL Android LTR iOS LTR
Before-RTL-Android Before-RTL-iOS Before-LTR-Android Before-LTR-iOS

After

Android RTL iOS RTL Android LTR iOS LTR
After-RTL-Android After-RTL-iOS After-LTR-Android After-LTR-iOS

Changelog:

[GENERAL] [Fixed] - AnsiHighlight style in RTL layout

Test Plan:

To test the changes, open LogBox while the app is in RTL mode. The modifications ensure that any error messages display correctly. I have verified that the changes function properly in both LTR and RTL modes, and all existing functionality remains unaffected.

This is an example component to throw an error to show LogBox.

import React from 'react';
import {Alert, Button, I18nManager, StyleSheet, Text, View} from 'react-native';

function SampleError() {
  return (
    <View>
      <Button
        title="Change to RTL"
        onPress={() => {
          I18nManager.allowRTL(true);
          I18nManager.forceRTL(true);
          Alert.alert('Restart app to apply changes');
        }}
      />
      <Button
        title="Change to LTR"
        onPress={() => {
          I18nManager.allowRTL(false);
          I18nManager.forceRTL(false);
          Alert.alert('Restart app to apply changes');
        }}
      />

      <Text style={styles.text}>
        isRTL: {I18nManager.isRTL ? 'true' : 'false'}
      </Text>

      <Button
        title="Show Error"
        onPress={() => {
          console.error('sample خطا');
        }}
      />
    </View>
  );
}

const styles = StyleSheet.create({
  text: {
    fontSize: 24,
    textAlign: 'center',
    paddingVertical: 20,
  },
});

export default SampleError;

@facebook-github-bot
Copy link
Contributor

Hi @hexboy!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 27, 2024
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Oct 27, 2024
@dnhan1707
Copy link

Hi @hexboy, may I ask when you make the pull request, how did you passed the Run Danger on PR / danger (pull_request_target) check?
I am making PR for other issue but I keep getting error where it says
image

@hexboy
Copy link
Contributor Author

hexboy commented Oct 28, 2024

Hi @hexboy, may I ask when you make the pull request, how did you passed the Run Danger on PR / danger (pull_request_target) check?
I am making PR for other issue but I keep getting error where it says
image

Hi @dnhan1707,
Your pull request needs a description.

Copy link
Contributor

@NickGerleman NickGerleman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great change! Left a couple of questions

</View>
))}
</View>
);
}

const styles = StyleSheet.create({
container: {
minWidth: '100%',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need to force these to be at least 100% now that the direction is forced to be LTR?

An aside, the offsetting here when content length less than container feels like an Android RTL scrollview bug.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#47280 should fix Android bug here

image

Copy link
Contributor Author

@hexboy hexboy Oct 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s added to resolve the iOS bug; if you remove this minWidth: '100%', it becomes misaligned.
image

NickGerleman added a commit to NickGerleman/react-native that referenced this pull request Oct 29, 2024
Summary:
Noticed in the screenshots of facebook#47230 that Android's logic of setting scroll content origin to zero, than right aligning scroll offset, won't correctly handle case where content is smaller than scrolling container. We can fix that by only resetting the origin when content overflows container, since we otherwise are not scrollable, and scroll adjustment will not translate.

Changelog:
[Android][Fixed] - Fix RTL ScrollView position when content smaller than container

Differential Revision: D65136654
NickGerleman added a commit to NickGerleman/react-native that referenced this pull request Oct 29, 2024
…book#47280)

Summary:

Noticed in the screenshots of facebook#47230 that Android's logic of setting scroll content origin to zero, then right aligning scroll offset, won't correctly handle case where content is smaller than scrolling container. We can fix that by only resetting the origin when content overflows container, since we otherwise are not scrollable, and scroll adjustment will not translate.

Changelog:
[Android][Fixed] - Fix RTL ScrollView position when content smaller than container

Differential Revision: D65136654
NickGerleman added a commit to NickGerleman/react-native that referenced this pull request Oct 29, 2024
…book#47280)

Summary:

Noticed in the screenshots of facebook#47230 that Android's logic of setting scroll content origin to zero, then right aligning scroll offset, won't correctly handle case where content is smaller than scrolling container. We can fix that by only resetting the origin when content overflows container, since we otherwise are not scrollable, and scroll adjustment will not translate.

Changelog:
[Android][Fixed] - Fix RTL ScrollView position when content smaller than container

Differential Revision: D65136654
@facebook-github-bot
Copy link
Contributor

@NickGerleman has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot pushed a commit that referenced this pull request Oct 29, 2024
Summary:
Pull Request resolved: #47280

Noticed in the screenshots of #47230 that Android's logic of setting scroll content origin to zero, then right aligning scroll offset, won't correctly handle case where content is smaller than scrolling container. We can fix that by only resetting the origin when content overflows container, since we otherwise are not scrollable, and scroll adjustment will not translate.

Changelog:
[Android][Fixed] - Fix RTL ScrollView position when content smaller than container

Reviewed By: rshest

Differential Revision: D65136654

fbshipit-source-id: 2818ff6360cbfac64d7e57bdcbbe8c0a9b4bbb97
@hexboy
Copy link
Contributor Author

hexboy commented Oct 30, 2024

@NickGerleman, I updated my PR, and the workflow failed link, but I couldn't see any error.
Could you please help me fix it?

@facebook-github-bot
Copy link
Contributor

@NickGerleman has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@NickGerleman merged this pull request in 9a3958a.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Oct 31, 2024
@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @hexboy in 9a3958a

When will my fix make it into a release? | How to file a pick request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants