React-native-snap-carousel: single direction scroll

Created on 10 Feb 2019  路  5Comments  路  Source: meliorence/react-native-snap-carousel

Feature Request:

Adding a property something like "ScrollDirection = LeftOnly|RightOnly|Both(default)"

I've read in some old threads of several ways to handle this:

  1. enableScroll = false (but then scrolling is completely disabled)
  2. check onScroll = but by the time I check that use would already scroll to undesired direction which gives bad user experience
  3. Another option is to remove previous items. However, that works but there's only one aesthetic glitch - You don't see a partially visible previous card and also pagination might mess up (user should still see the step they are on)

Why is such a feature important?
Imagine you want users to fill a sectioned form where they should not go to previous ones or maybe a game where you don't want user to peek previous cards.

thanks

Most helpful comment

+1
I feel this is important

All 5 comments

+1
I feel this is important

Did you ever find a workaround to this?

Hello everybody
Just end with some hacky workaround
I have tried to work with dynamic data array (according to some business logic, I need to block swipe to the first page). It also works for cases, when you are blocked with some actions on the current page (agreements, fields validation, etc), so you are not allowed to move forward.
So at first active page my data list looks like:

[
  { index: 0, page: 'Disclamer' },
  { index: 1, page: 'Title 1' },
  { index: 2, page: 'Title 2' },
  { index: 3, page: 'Title 3' },
  ....
]

When on second page it will be slice(1):

[
  { index: 1, page: 'Title 1' },
  { index: 2, page: 'Title 2' },
  { index: 3, page: 'Title 3' },
  ....
]

It works absolutely as expected for iOS builds, but as for Android you will not be able to see correct render, as the second page will disappear till you click on page once again.
So it should be added another approach to render first (limited element). I've added another wrapper ScrollView to Carousel and lock scrollEnabled right after swiping to second page:

        <ScrollView
          horizontal
          pagingEnabled
          showsHorizontalScrollIndicator={false}
          onScrollBeginDrag={this.handleChangeLayout}
          scrollEnabled={activePageIndex === 0}
        >
          <CarouselItem {...data} />
          <Carousel
            data={data.slice(1)}
            renderItem={this.renderItem}
          />
        </ScrollView>

Hope it will handle someone's problem

+1

+1

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Murena7 picture Murena7  路  3Comments

krisidmisso picture krisidmisso  路  4Comments

Dr1992 picture Dr1992  路  4Comments

AndrePech picture AndrePech  路  4Comments

littlehome-eugene picture littlehome-eugene  路  3Comments