question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug layout='stack' in rtl

See original GitHub issue

Hello, great library. but when I try to use the ‘stack’ layout in rtl mode, the cards seems to cover the wrong way. I’m using version 4.0.0-beta.5 in android, in react native 0.62.2

RTL Mod Screenshot_1597083458

LTR Screenshot_1597083704

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:6

github_iconTop GitHub Comments

2reactions
mm1221uucommented, Oct 8, 2020

this my solution for IOS RTL and android issues:

passed this function to Carousel prop (slideInterpolatedStyle)

function stackAnimatedStyles(
    index,
    animatedValue,
    carouselProps,
    cardOffset,
  ) {
    const sizeRef = carouselProps.vertical
      ? carouselProps.itemHeight
      : carouselProps.itemWidth;
    const translateProp = carouselProps.vertical ? 'translateY' : 'translateX';
    const card1Scale = 0.9;
    const card2Scale = 0.8;
    
    cardOffset = !cardOffset && cardOffset !== 0 ? 18 : cardOffset;

    const getTranslateFromScale = (cardIndex, scale) => {
      const centerFactor = (1 / scale) * cardIndex;
      const centeredPosition = -Math.round(sizeRef * centerFactor);
      const edgeAlignment = Math.round((sizeRef - sizeRef * scale) / 2);
      const offset = Math.round((cardOffset * Math.abs(cardIndex)) / scale);

      return IS_ANDROID
        ? centeredPosition - edgeAlignment - offset
        : centeredPosition + edgeAlignment + offset;
    };

    const cardScreenPostion = () => {
      const IOS_RTL = IS_RTL && !IS_ANDROID;
      const factor = IOS_RTL ? -1 : 1;
      return [
        factor * (IOS_RTL ? -sizeRef - 15 : -sizeRef * 0.5),
        0,
        factor * getTranslateFromScale(1, card1Scale),
        factor * getTranslateFromScale(2, card2Scale),
        factor * getTranslateFromScale(3, card2Scale),
      ];
    };
    const opacityOutputRange =
      carouselProps.inactiveSlideOpacity === 1
        ? [1, 1, 1, 0]
        : [1, 0.75, 0.5, 0];
    return IS_ANDROID
      ? {
          elevation: IS_RTL ? carouselProps.data.length - index : null, // fix zIndex bug visually, but not from a logic point of view
          opacity: animatedValue.interpolate({
            inputRange: [-3, -2, -1, 0],
            outputRange: opacityOutputRange.reverse(),
            extrapolate: 'clamp',
          }),
          transform: [
            {
              scale: animatedValue.interpolate({
                inputRange: [-2, -1, 0, 1],
                outputRange: [card2Scale, card1Scale, 1, card1Scale],
                extrapolate: 'clamp',
              }),
            },
            {
              [translateProp]: animatedValue.interpolate({
                inputRange: [-3, -2, -1, 0, 1],
                outputRange: [
                  getTranslateFromScale(-3, card2Scale),
                  getTranslateFromScale(-2, card2Scale),
                  getTranslateFromScale(-1, card1Scale),
                  0,
                  sizeRef * 0.5,
                ],
                extrapolate: 'clamp',
              }),
            },
          ],
        }
      : {
          zIndex: carouselProps.data.length - index,
          opacity: animatedValue.interpolate({
            inputRange: [0, 1, 2, 3],
            outputRange: opacityOutputRange,
            extrapolate: 'clamp',
          }),
          transform: [
            {
              scale: animatedValue.interpolate({
                inputRange: [-1, 0, 1, 2],
                outputRange: [card1Scale, 1, card1Scale, card2Scale],
                extrapolate: 'clamp',
              }),
            },
            {
              [translateProp]: animatedValue.interpolate({
                inputRange: [-1, 0, 1, 2, 3],
                outputRange: cardScreenPostion(),
                extrapolate: 'clamp',
              }),
            },
          ],
        };
  }
0reactions
dohooocommented, Oct 8, 2021

Sorry, please allow me to advertise for my open source library! ~ I think this library react-native-reanimated-carousel will solve your problem. It is a high performance and very simple component, complete with React-Native reanimated 2

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bug layout='stack' in rtl · Issue #739 · meliorence/react- ...
Hello, great library. but when I try to use the 'stack' layout in rtl mode, the cards seems to cover the wrong way....
Read more >
Guidline is ignored in RTL-Layout (Android Constraint- ...
I've heard of some bugs with Guidelines and RTL in Constraint-Layout. But none of the methods helped me. I have Guidelines on both...
Read more >
V2.9.0.beta13 totally breaks the RTL layout - bug
We use Discourse for our Arabic-speaking community, unfortunately the latest update totally broke the RTL layout. Unlike last time, Main CSS ...
Read more >
Boxed Layout - Stack Responsive Bootstrap 4 Admin ...
This table contains all classes related to the boxed layout, by using these layout specific classes you can apply its css. All these...
Read more >
Possible bug in text rtl layout
Using Sciter.js, I need to create a label where the text gets cropped with ellipsis on the left if it exceeds the maximum...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found