recyclerlistview icon indicating copy to clipboard operation
recyclerlistview copied to clipboard

fix(rtl): fixed render element when languages is right to left

Open Matergi opened this issue 4 years ago • 10 comments

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

Matergi avatar Jul 14 '21 16:07 Matergi

resolve: #502 #322

Matergi avatar Jul 15 '21 08:07 Matergi

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

please merge it if everything is good

fai9al7dad avatar Jun 09 '22 13:06 fai9al7dad

+1. @naqvitalha can this be merged?

demedos avatar Aug 03 '22 07:08 demedos

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

bestori avatar Dec 11 '22 17:12 bestori

@bestori rebase done feel free to merge

Matergi avatar Mar 01 '23 15:03 Matergi

@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 avatar Mar 16 '23 13:03 Budaa

@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!

bestori avatar May 03 '23 10:05 bestori

@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 avatar May 10 '23 20:05 1nspir3d

@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?

1nspir3d avatar May 11 '23 16:05 1nspir3d

@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>
    );
  }
);

Budaa avatar May 11 '23 16:05 Budaa