react-native-viewpager icon indicating copy to clipboard operation
react-native-viewpager copied to clipboard

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

Open JxSx opened this issue 7 years ago • 12 comments

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
  }
});

JxSx avatar Sep 08 '17 08:09 JxSx

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

gooddaddy avatar Sep 27 '17 11:09 gooddaddy

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

bondanherumurti avatar Oct 18 '17 08:10 bondanherumurti

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

JxSx avatar Oct 24 '17 06:10 JxSx

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

JxSx avatar Oct 24 '17 06:10 JxSx

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

GarveyCalvin avatar Nov 08 '17 10:11 GarveyCalvin

  • DefaultViewPageIndicator.js and ViewPager.js are using "React.PropTypes" instead of "PropTypes" imported from "prop-types". Issues 164
  • After we fixed the above trouble, we may encounter another error "React.createClass is not a function". If so, try to use "create-react-class" library. Hope it works for you!

Jiahonzheng avatar Nov 15 '17 10:11 Jiahonzheng

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 👯‍♂️

phatnguyenbg avatar Dec 01 '17 07:12 phatnguyenbg

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

fastalks avatar Dec 06 '17 12:12 fastalks

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

zhaoqigang avatar Feb 08 '18 03:02 zhaoqigang

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

HS3 avatar Sep 08 '18 05:09 HS3

import PropTypes from 'prop-types';

spalanci avatar Jun 23 '20 06:06 spalanci

same problem i already have prop-types installed

joshington avatar Aug 27 '20 15:08 joshington