简体   繁体   English

如何在提供的组件(尤其是带有fetchPopularMovies的部分)上实现这种依赖关系(react-native-pull-to-refresh)?

[英]How to implement this dependency ( react-native-pull-to-refresh) on the provided component, particularly the part with fetchPopularMovies?

// @flow
import React, { Component } from 'react';
import { FlatList, View, StatusBar } from 'react-native';
import { bindActionCreators } from 'redux';
import type { Dispatch as ReduxDispatch } from 'redux';
import { connect } from 'react-redux';
import { fetchPopularMovies } from '../../actions/PopularMovieActions';
import MovieCard from '../../components/movieCard/MovieCard';
type Props = {
  fetchPopularMovies: Function,
  popularMovies: Object,
  navigation: Object,
}
class ListOfPopularContainer extends Component<Props> {
  componentDidMount() {
    this.props.fetchPopularMovies();
  }
  render() {
    const { popularMovies, navigation } = this.props;
    return (
      <View>
        <StatusBar
          translucent
          backgroundColor="transparent"
          barStyle="light-content"
        />
        <FlatList
          data={popularMovies}
          keyExtractor={item => item.title}
          renderItem={({ item }) => (
            <MovieCard navigation={navigation} card={item} />
          )}
        />
      </View>
    );
  }
}
const mapStateToProps = state => ({
  popularMovies: state.movies.popularMovies,
});
const mapDispatchToProps = (dispatch: ReduxDispatch): Function => (
  bindActionCreators({ fetchPopularMovies }, dispatch)
);
export default connect(mapStateToProps, mapDispatchToProps)(ListOfPopularContainer);

How to use it with the this.props.fetchPopularMovies() ? 如何与this.props.fetchPopularMovies()结合使用 Is there some way to combine them, if you know, have any example or some experience with it please don't be shy to give some input on this problem. 有什么方法可以将它们组合起来,如果您知道的话,请提供任何示例或经验,请不要羞于对此问题提供一些意见。 The main thing I wont to do here is refreshing the screen when someone pulls it down. 我在这里要做的主要事情是当有人将其拉下时刷新屏幕。

You can remove funtion _delay() on both android and ios in node_module/react-native-pull-to-refresh/PullToRefreshView , then call funtion _endLoading() after this.props.fetchPopularMovies() success 您可以在node_module / react-native-pull-to-refresh / PullToRefreshView中的 android和ios上删除功能_delay() ,然后在此.props.fetchPopularMovies()成功后调用功能_endLoading()。

_handleOnRefresh() { // remove delay
   this.props.onRefresh()
}

// your component 
import PTRView from 'react-native-pull-to-refresh'
...

class ListOfPopularContainer extends Component<Props> {

   refresh = () => {
      this.props.fetchPopularMovies().then({
         this.PTRView._endLoading()// call end loading
   }}

   render() {
      const { popularMovies, navigation } = this.props;
      return (
         <View>
           <StatusBar
             translucent
             backgroundColor="transparent"
             barStyle="light-content"
           />
           <PTRView
             style={{ backgroundColor: '#F5FCFF' }}
             onRefresh={this.refresh}
             ref={c => this.PTRView = c}
           >
             <FlatList
               data={popularMovies}
               keyExtractor={item => item.title}
               renderItem={({ item }) => (
                 <MovieCard navigation={navigation} card={item} />
           )}
             />
           </PTRView>
         </View>
      )
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM