carouselItem.js 765 B

123456789101112131415161718192021222324252627282930313233343536
  1. //import liraries
  2. import React, { Component } from 'react'
  3. import { TouchableOpacity } from 'react-native'
  4. // create a component
  5. class CarouselItem extends Component {
  6. constructor(props) {
  7. super(props)
  8. this.state = {
  9. width: props.width,
  10. }
  11. }
  12. getwidth(e) {
  13. this.setState({
  14. width: e.width,
  15. })
  16. }
  17. render() {
  18. return (
  19. <TouchableOpacity
  20. style={{ width: this.state.width }}
  21. activeOpacity={this.props.activeOpacity}
  22. onPress={() => {
  23. this.props.imgTouch(this.props.index)
  24. }}
  25. onLayout={e => this.getwidth(e.nativeEvent.layout)}
  26. >
  27. {this.props.item}
  28. </TouchableOpacity>
  29. )
  30. }
  31. }
  32. //make this component available to the app
  33. export default CarouselItem