Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content doesn't stretch when rotate (portrait mode) #16

Open
DanilloCorvalan opened this issue May 20, 2015 · 10 comments
Open

Content doesn't stretch when rotate (portrait mode) #16

DanilloCorvalan opened this issue May 20, 2015 · 10 comments

Comments

@DanilloCorvalan
Copy link

Does anyone know how to solve this problem ?

@mkascel
Copy link

mkascel commented Jul 20, 2015

I'm seeing this also, the inspector shows that the calculated width is always 375 regardless of content or orientation. If I take away the Swiper element, the content expands as expected. Any ideas? Wonder if this is related to the fact that this is interpreted/rendered as an <index> element rather than Swiper or some other expected element...

screen shot 2015-07-19 at 16 28 10

@mkascel
Copy link

mkascel commented Jul 20, 2015

Not quite sure what the automaticallyAdjustContentInsets property does per the docs, I tried setting this to true thinking it might affect layout but no luck.

@rt2zz
Copy link

rt2zz commented Sep 15, 2015

the swiper take in a width and height parameter which can make it work in landscape, but it bugs out if a transition occurs.

@maxx-coffee
Copy link

Hopefully this helps if someone comes across this issue. I used https://github.com/yamill/react-native-orientation to add an event when orientation changes. I then get the dimensions and change the state to those dimensions re-rendering screen.

@esutton
Copy link

esutton commented Nov 22, 2016

Thanks @joshualcoffee

It sounds like the best solution may be to modify react-native-swiper to include react-native-orientation.

https://github.com/yamill/react-native-orientation

@jamealg
Copy link

jamealg commented Dec 13, 2016

@esutton You don't need to modify react-native-swiper directly. The Swiper component will listen for changes to the width prop so using react-native-orientation's orientation change event, you can pass the updated Dimensions.get('window').width.

@cosivox
Copy link

cosivox commented Mar 20, 2017

@joshualcoffee Could you please explain how did you do that?

@maxx-coffee
Copy link

maxx-coffee commented Mar 20, 2017

@cosivox Sure thing!

This has not been tested but you should be able to get the idea from the example. This would be the internal slide component that you would include for each item in your slider.

In my code I found setting the view to be absolute and setting left, right, top, and bottom to 0 achieved the result I wanted.

import React, {Component} from 'react'
import Orientation from 'react-native-orientation'
const {
  View,
  Dimensions
} from 'react-native'
let window = Dimensions.get('window')
class Foo extend Component {
  constructor(_){
    super(_)
    this._orientationDidChange = this._orientationDidChange.bind(this)
    this.state = {
      width: window.width,
      height: window.height
    }
  }

  _orientationDidChange(orientation) {
    let window = Dimensions.get('window')
    this.setState({
      width: window.width,
      height: window.height
    })
  }

  componentDidMount() {
    Orientation.addOrientationListener(this._orientationDidChange);
  }

  render(){
    <View style={{width: this.state.width, height: this.state.height, position: 'absolute', left: 0, top:0, right: 0, bottom: 0}}>
  }
}

@khrykin
Copy link

khrykin commented Aug 22, 2017

Setting width prop to Dimensions.get('window').width solved problem for me

@sankar9659
Copy link

@khrykin Does it working for you with vertical and horizontal mode?
Could you send your code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants