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

Scroll to a specific item position #6

Open
RatFou opened this issue Jan 22, 2017 · 3 comments
Open

Scroll to a specific item position #6

RatFou opened this issue Jan 22, 2017 · 3 comments

Comments

@RatFou
Copy link

RatFou commented Jan 22, 2017

Hi, I'm trying to scroll to a specific item but I'm stucked.

In my last test I used a modified scroll function (without the callback):
this.refs.scrollingMenu.scrollToIndex(i);
but it seems that the widths state is empty (this.state.widths[itemNum]).

I understand that this state is pushed in the loop function and the width is calculated with onLayout. I just don't get how to reproduce this onLayout in another function.

Any lead?

@bradbyte
Copy link

bradbyte commented May 8, 2017

@thathirsch any thoughts?

@arminsal1
Copy link

I have this use case as well. @thathirsch

@xstable
Copy link

xstable commented Sep 28, 2018

You can do it as follow:

<ScrollingMenu
                  defaultIndex={0}
                  ref={(c) => this.scrollingMenu = c}
                  items={items}
                  itemStyle={styles.yourItemStyle}
                  selectedItemStyle={styles.yourSelectedItemStyle}
                  containerStyle={styles.yourContainerStyle}
                  onSelect={(index) => {
                   ... do this and that
                  }}
                />

And then to scroll to a given Item:

<TouchableOpacity onPress={index => this.scrollingMenu.select(index) ) }>
      <Icon type="FontAwesome" style={{ color: config.fontLight, fontSize: 18, paddingTop: 10 }} name="chevron-left" />
</TouchableOpacity>

Here you can use the Methods which are allready declared in ScrollMenu Component, like select() or scrollTo().

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

No branches or pull requests

4 participants