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(rtl): fixed render element when languages is right to left #629

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Matergi
Copy link

@Matergi Matergi commented Jul 14, 2021

Only for Android when the device is in RTL language and is in horizontal mode the items not rendering

@Matergi
Copy link
Author

Matergi commented Jul 15, 2021

resolve: #502 #322

@fai9al7dad
Copy link

thanks tried it on dist.. this did fix the bug

please merge it if everything is good

@demedos
Copy link

demedos commented Aug 3, 2022

+1. @naqvitalha can this be merged?

demedos
demedos previously approved these changes Aug 4, 2022
bestori
bestori previously approved these changes Dec 11, 2022
Copy link

@bestori bestori left a comment

Choose a reason for hiding this comment

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

Works great for me, recommend merge

@bestori
Copy link

bestori commented Dec 11, 2022

@Matergi don't forger to rebase with main..! :)

@Matergi
Copy link
Author

Matergi commented Mar 1, 2023

@bestori rebase done feel free to merge

@Budaa
Copy link

Budaa commented Mar 16, 2023

@Matergi Are there any prerequisites for it to work? Do I need to set any other props on the list, apart from horizontal?
I'm trying it on the FlashList and it doesn't help unfortunately. It only renders the first and last element of the list and has blank space in between.

@bestori
Copy link

bestori commented May 3, 2023

@Matergi Are there any prerequisites for it to work? Do I need to set any other props on the list, apart from horizontal? I'm trying it on the FlashList and it doesn't help unfortunately. It only renders the first and last element of the list and has blank space in between.

@Budaa can you share non-working code sample?

@Matergi once we have this sorted out I will continue. Thank you!

@1nspir3d
Copy link

@Matergi Are there any prerequisites for it to work? Do I need to set any other props on the list, apart from horizontal? I'm trying it on the FlashList and it doesn't help unfortunately. It only renders the first and last element of the list and has blank space in between.

how about min reproduce repo/snack?

@1nspir3d
Copy link

@Budaa @bestori I can confirm that this fix is indeed fixes a problem with horizontal RTL list. Just tried it out on my project and everything seems to work fine.

However, I had to apply this fix directly into recyclerlistview/dist/reactnative/core/VirtualRenderer.js. Applying this to recyclerlistview/src/core/VirtualRenderer.ts has no effect whatsoever.

Are there any additional steps required when you apply this fix to recyclerlistview/src/core/VirtualRenderer.ts?

@Budaa
Copy link

Budaa commented May 11, 2023

@1nspir3d @bestori
My team managed to fix the issue on FlashList by applying 2 patches to rlv and one to FlashList and then editing rendering of FlashList for RTL

const PATCHES = [
  // https://github.com/Flipkart/recyclerlistview/pull/629/files - Fixes RTL for FlashList
  {
    filePath:
      "../node_modules/@shopify/flash-list/node_modules/recyclerlistview/dist/reactnative/core/VirtualRenderer.js",
    operation: insertAtInFile,
    args: {
      lineNumber: 9,
      content: `var react_native_1 = require("react-native");`,
    },
  },
  {
    filePath:
      "../node_modules/@shopify/flash-list/node_modules/recyclerlistview/dist/reactnative/core/VirtualRenderer.js",
    operation: insertAtInFile,
    args: {
      lineNumber: 76,
      content: `var isRTLAndroid = react_native_1.I18nManager.isRTL && react_native_1.Platform.OS === "android";`,
    },
  },
  {
    filePath:
      "../node_modules/@shopify/flash-list/node_modules/recyclerlistview/dist/reactnative/core/VirtualRenderer.js",
    operation: replaceStringInFile,
    args: {
      lookUpString:
        "var offset = this._params && this._params.isHorizontal ? offsetX : offsetY;",
      correctString:
        "var offset = this._params && this._params.isHorizontal ? isRTLAndroid ? this.getLayoutDimension().width - offsetX : offsetX : offsetY;",
    },
  },
];

And then we needed to change FlashList rendering for RTL:

        {isRTL ? (
          cellLayoutMeasurements?.height ? (
            <FlashList
              {...sharedProps}
              renderScrollComponent={ScrollComponent}
              estimatedItemSize={calculatedCellWidth + styles.horizontalGutter}
              estimatedListSize={{
                width: screenWidth,
                height: cellLayoutMeasurements?.height,
              }}
              disableAutoLayout
              disableHorizontalListHeightMeasurement
            />
          ) : null
        ) : (
          <FlashList {...sharedProps} estimatedItemSize={calculatedCellWidth} />

And here is the custom scrollView component

const ScrollComponent = React.forwardRef<ScrollView, {}>(
  (
    {
      children,
      removeClippedSubviews,
      onScroll,
      contentContainerStyle,
      onLayout: _,
      ...restProps
    }: ScrollViewProps,
    ref
  ) => {
    const { width } = useDimensions("screen", {
      fullDimensions: true,
    });

    return (
      <ScrollView
        ref={ref}
        horizontal
        onScroll={onScroll}
        removeClippedSubviews={removeClippedSubviews}
        contentContainerStyle={[
          contentContainerStyle,
          scrollViewStyles.flexZero,
          { minWidth: width },
        ]}
        {...restProps}
      >
        <View style={[scrollViewStyles.flexZero, scrollViewStyles.fullWidth]}>
          {children}
        </View>
      </ScrollView>
    );
  }
);

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

Successfully merging this pull request may close these issues.

None yet

8 participants