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

FlatList onRefresh not called on pull up. #14756

Closed
dmr07 opened this issue Jun 27, 2017 · 9 comments
Closed

FlatList onRefresh not called on pull up. #14756

dmr07 opened this issue Jun 27, 2017 · 9 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@dmr07
Copy link

dmr07 commented Jun 27, 2017

Is this a bug report?

Yes

Have you read the Bugs section of the Contributing to React Native Guide?

Yes

Environment

  1. react-native -v: 0.4.5
  2. node -v: 7.4.0
  3. npm -v: 5.0.3
  4. yarn --version (if you use Yarn): 0.24.5

Then, specify:

  1. Target Platform (e.g. iOS, Android): iOS
  2. Development Operating System (e.g. macOS Sierra, Windows 10): macOs Sierra
  3. Build tools (Xcode or Android Studio version, iOS or Android SDK version, if relevant): XCode 8.3.3

Steps to Reproduce

  1. Implement React-Native FlatList in a module.
  2. Render a component in renderItems prop
  3. nest FlatList inside <ScrollView> element
  4. Pull up on device to attempt to refresh

Expected Behavior

Call onRefresh function on pull up.

Actual Behavior

onRefresh function is not called.

Reproducible Demo

Snack Link: https://snack.expo.io/HJYx3Kx4W

...
  constructor(props) {
    super(props);
    this.state = {
      stories: [],
      isFetching: false,
    };
  }
  componentDidMount() { this.fetchData() }
  onRefresh() {
    this.setState({ isFetching: true }, function() { this.fetchData() });
  }
  fetchData() {
    var that = this;
    axios.get('http://192.168.0.13:3000/api/story/get/by/geo')
      .then((res) => {
        that.setState({ stories: res.data, isFetching: false });
        that.props.dispatch(StoryActions.setStories(res.data))
      })
  }
  render() {
    return (
      <ScrollView>
        <FlatList
          onRefresh={() => this.onRefresh()}
          refreshing={this.state.isFetching}
          data={this.state.stories}
          keyExtractor={(item, index) => item.id}
          renderItem={({item}) => (<StoryFeed story={item} id={item.id} /> )}
          />
      </ScrollView>
    )
  }

@hramos
Copy link
Contributor

hramos commented Jun 27, 2017

Can you set this up as a Snack? Should be pretty straightforward, no need to make a network request in the refresh call either.

@dmr07
Copy link
Author

dmr07 commented Jun 28, 2017

@hramos Here's a link: https://snack.expo.io/HJYx3Kx4W

Issue is that FlatList onRefresh does not work when it is nested inside ScrollView. In the Snack, if you change the ScrollView to View, then it works okay.

@hramos
Copy link
Contributor

hramos commented Jun 28, 2017

Gotcha, can you update your description at the top to make that clarification?

@dmr07
Copy link
Author

dmr07 commented Jun 28, 2017

updated.

@hramos
Copy link
Contributor

hramos commented Jun 28, 2017

@sahrens is this intended to work? I'm not sure how prevalent the use of a FlatList within a ScrollView is.

@dmr07
Copy link
Author

dmr07 commented Jul 2, 2017

@hramos @sahrens I'm running into a couple situations where having ScrollView support would be helpful. For example, if I need to detect a scroll event in order to hide the header, according to the FlatList docs this is not possible. Furthermore, if a content filter bar is to be placed above a FlatList, it would be rendered fixed above the scrollable content and take up screen space, an issue that would not otherwise occur when using ScrollView.

UPDATE: Just tried attaching onScroll to FlatList. It works; would be nice to see this documented when you guys have a chance. Regarding the header bar, there's a prop that I missed the first time around. I see now that the intent of FlatList is a super ScrollView, and I suppose nesting would be bad design.

@dmr07
Copy link
Author

dmr07 commented Jul 10, 2017

I'm closing this issue as the original problem was caused by bad design / inadequate understanding of FlatList. Better documentation would be helpful though.

@ghoshabhi
Copy link

@dmr07 : Could you post your solution/changes here? I too have a situation where I have a fixed header with filter options and a FlatList (which needs pull-to-refresh) within a scroll view.

@ghoshabhi
Copy link

Note: I too fixed the problem by using <View style={{ flex: 1 }}> instead of ScrollView

@facebook facebook locked as resolved and limited conversation to collaborators Jun 15, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

4 participants