react-responsive-carousel icon indicating copy to clipboard operation
react-responsive-carousel copied to clipboard

carousel doesn't load when mobile is landscape

Open ercekal opened this issue 8 years ago • 2 comments

so I select images based on the screen width. when mobile is landscape it doesn't load but when it's in portrait orientation it loads in the beginning.

When it is landscape, if I rotate it it loads portrait images and when I re-rotate to landscape, the carousel is seen.

import '../styles/ImageCarousel.scss'
import '../styles/carousel.scss'
import { Carousel } from 'react-responsive-carousel'
import image1 from '../images/Editorial_Mobile_EndlessTruck_480.png'
import image2 from '../images/Editorial_Mobile_Goldblade_480.png'
import image3 from '../images/Editorial_Mobile_SneakyPaperToss_480.png'
import image4 from '../images/Editorial_Mobile_YetiSensation_480.png'
import image5 from '../images/Editorial_Medium_EndlessTruck_768.png'
import image6 from '../images/Editorial_Medium_Goldblade_768.png'
import image7 from '../images/Editorial_Medium_SneakyPaperToss_768.png'
import image8 from '../images/Editorial_Medium_YetiSensation_768.png'
import image9 from '../images/Editorial_Medium_EndlessTruck_1024.png'
import image10 from '../images/Editorial_Medium_Goldblade_1024.png'
import image11 from '../images/Editorial_Medium_SneakyPaperToss_1024.png'
import image12 from '../images/Editorial_Medium_YetiSensation_1024.png'
import image13 from '../images/Editorial_Large_EndlessTruck_1440.png'
import image14 from '../images/Editorial_Large_Goldblade_1440.png'
import image15 from '../images/Editorial_Large_SneakyPaperToss_1440.png'
import image16 from '../images/Editorial_Large_YetiSensation_1440.png'
import CarouselText from './CarouselText'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import * as carouselActions from '../actions/allActions'
import PropTypes from 'prop-types'

const imageDetails = [{
  image: {
    imageSmall: image1,
    imageMedium_768: image5,
    imageMedium_1024: image9,
    imageLarge_1440: image13,
  },
  link: link,
  gameName: 'First game',
},
{
  image: {
    imageSmall: image2,
    imageMedium_768: image6,
    imageMedium_1024: image10,
    imageLarge_1440: image14,
  },
  link: link,
  gameName: 'Second game'
},
{
  image: {
    imageSmall: image3,
    imageMedium_768: image7,
    imageMedium_1024: image11,
    imageLarge_1440: image15,
  },
  link: link,
  gameName: 'Third game'
},
{
  image: {
    imageSmall: image4,
    imageMedium_768: image8,
    imageMedium_1024: image12,
    imageLarge_1440: image16,
  },
  link: link,
  gameName: 'Fourth game'
}]

class ImageCarousel extends Component {
  constructor(props) {
    super(props)
    this.state = {
      width: window.innerWidth,
    }
  }
  renderImages() {
    const {width} = this.state
    const imageSelect = item => {
      let image = item['image']['imageSmall']
      if (width > 1439 ) {
        image = item['image']['imageLarge_1440']
      } else if (width > 1000) {
        image = item['image']['imageMedium_1024']
      } else if (width > 767) {
        image = item['image']['imageMedium_768']
      }
      return image
    }
    if (width) {
      return imageDetails.map((item, i) => {
        return (
          <div key={i}>
            <img src={imageSelect(item)}/>
          </div>
        )
      })
    }
  }

  _checkOrientation = () => {
    if ('onorientationchange' in window) {
      window.addEventListener('orientationchange', () => {
        this.setState({
          width: window.innerWidth,
        })
        this.forceUpdate()
      }, false)
    }
  }

  _onClick = item => {
    this.props.actions.selectCarouselItem(item)
  }

  _gameNames () {
    let list = []
    imageDetails.map(item => {
      list.push(item['gameName'])
    })
    return list
  }

  _gameLinks () {
    let list = []
    imageDetails.map(item => {
      list.push(item['link'])
    })
    return list
  }

  render() {
    return (
      <div className='ImageCarousel'>
        <div className='ImageCarousel-carousel'>
          <Carousel
            showArrows={false}
            showThumbs={false}
            showStatus={false}
            onChange={this._onClick}
            infiniteLoop
            useKeyboardArrows
            autoPlay
            stopOnHover
            swipeable
          >
            {this.renderImages()}
          </Carousel>
        </div>
        <div className='ImageCarousel-box'>
          <CarouselText gameNames={this._gameNames()} gameLinks={this._gameLinks()}/>
        </div>
        {this._checkOrientation()}
      </div>
    )
  }
}

function mapDispatchToProps(dispatch) {
  return {
    actions: bindActionCreators(carouselActions, dispatch)
  }
}
ImageCarousel.propTypes = {
  actions: PropTypes.any,
}
export default connect(null, mapDispatchToProps)(ImageCarousel)

ercekal avatar Apr 12 '18 15:04 ercekal

https://www.youtube.com/watch?v=A6HHbigmIVU

ercekal avatar Apr 12 '18 15:04 ercekal

this is an issue about the thumbnails. I had to showThumbs and hide them by css. Really weird.

ercekal avatar Apr 13 '18 09:04 ercekal