race604 / react-native-viewpager

[Deprecated] ViewPager component for React Native
1.41k stars 373 forks source link

undefined is note an object(evaluating 'React.propTypes.func') #167

Open JxSx opened 7 years ago

JxSx commented 7 years ago

image

Who can help me,please

my code:

import React from 'react';
import {View, Text, StyleSheet, Image, ViewPagerAndroid, Dimensions} from 'react-native';
import {requestLatestNews} from '../api/ZhiHuApi';

import ViewPager from 'react-native-viewpager';
const {width, height} = Dimensions.get('window');

export default class FindScreen extends React.Component{

  static navigationOptions = {
    tabBarLabel:'发现',
    tabBarIcon: ({ tintColor }) => (
      <Image
        source={require('../img/ic_tab_navi_normal.png')}
        style={[styles.icon, {tintColor: tintColor}]}
      />
    ),
  };

  constructor(props) {
    super(props);
    var dataSource = new ViewPager.DataSource({
      pageHasChanged: (p1, p2) => p1 !== p2,
    });
    this.state = {
      dataSource: dataSource.cloneWithPages([]),
    }
  }

  componentDidMount() {
    requestLatestNews().then(result => {
      this.setState({
        dataSource: this.state.dataSource.cloneWithPages(result.top_stories)
      });
    });
  }

  render(){
    return(
      <View style={{flex: 1}}>
        <ViewPager
          style={{flex:1}}
          dataSource={this.state.dataSource}
          renderPage={this._renderPage}
          isLoop={false}
          initialPage={0}
          renderPageIndicator={false}
          autoPlay={false}/>
      </View>
    );
  }

  _renderPage = (item) => {
    console.log(item)
    return (<Text>111</Text>);
  }

}

const styles = StyleSheet.create({
  icon: {
    width: 24,
    height: 24,
  },
  pageStyle: {
    alignItems: 'center',
    padding: 20,
    height: 100
  }
});
gooddaddy commented 6 years ago

我也遇到了同样的问题,你使用的react-native是什么版本的,我使用的是0.46.4

bondanherumurti commented 6 years ago

same problem here, i am using "react-native": "0.49.3"

JxSx commented 6 years ago

@bondanherumurti "react-native": "^0.47.2"

JxSx commented 6 years ago

@gooddaddy "react-native": "^0.47.2"

GarveyCalvin commented 6 years ago

@JxSx Same problem here, How to fix it? My react-native version is ''0.49.3"

Jiahonzheng commented 6 years ago
phatnguyenbg commented 6 years ago

I also got an error with it and some guides below hope to help everyone fix it 💯 Reference: https://reactjs.org/blog/2017/04/07/react-v15.5.0.html#migrating-from-react.createclass We take care 2 files: ViewPager.js and DefaultViewPageIndicator.js The first one, we need to install more a package: npm install create-react-class --save After that import 2 files like this: var createReactClass = require("create-react-class"); Also import: import PropTypes from "prop-types"; Replace ....createClass = createReactClass

DefaultViewPageIndicator.propTypes = { goToPage: PropTypes.func.isRequired, activePage: PropTypes.number.isRequired, pageCount: PropTypes.number.isRequired }; => DefaultViewPageIndicator.js And got it 👯‍♂️

fastalks commented 6 years ago

这个问题作者不更新修复吗?

zhaoqigang commented 6 years ago

I fork and fix it https://github.com/zhaoqigang/react-native-viewpager

HS3 commented 6 years ago

听说是:这个组建已经过期了,很多api已经更新了,如果想继续用,那就等作者更新最新版本,rn项目中PropType的问题。等不了的朋友可以换 react native swiper

spalanci commented 4 years ago

import PropTypes from 'prop-types';

joshington commented 4 years ago

same problem i already have prop-types installed