React-native-image-viewer: Landscape Orientation

Created on 1 Jun 2017  路  10Comments  路  Source: ascoders/react-native-image-viewer

Will this library have Landscape Orientation support? Is it still maintained?

Most helpful comment

Really love this component, so I thought I would add my two cents here if people are confused about implementing this.

I used a similar method to @nosshar by using react-native-orientation to manage the orientation changes in my application.

I first lock the orientation to portrait in the componentDidMount of my root app component.
To display the image I created a modal overlay that is hooked into redux. By calling a specific redux action I can pass an image uri to the modal overlay and tell it to become visible.

In the ImageModal I use ImageView to display the image that is passed to it. In the ImageModal

  • componentWillReceiveProps: I check to see if the modal has been told to become visible if it has I unlock the orientations and I add a listener to orientation updates, Orientation.addOrientationListener. This allows me to set the state of the key on orientation changes.
  • ImageView: I pass the key as a prop to the ImageView, by changing the key on each orientation change it forces the ImageView to re-render. (there is probably a better way to do this)
  • closeModal: This method is called when the modal is closed. It tells the ImageModal to close, it removes any listeners that I have set up, and locks the orientation back to portrait.

All 10 comments

Sorry, this library is not support Landscape Orientation yet, but welcome pr!
You can building this project by this command:

yarn
npm start

I would develop Landscape support if I knew :( i can't seem to find any library with landscape support

I used:
...
"react-native-orientation": "3.1.0"
...
in my project and trigger this component redraw on orientation change.
Mostly because I have a lot of dependencies and can't migrate easily from ReactNative 0.42 (later versions have orientation change support in Dimensions class).
But of course it would be nice to have this feature implemented by awesome guys.

Thanks for this component!

Really love this component, so I thought I would add my two cents here if people are confused about implementing this.

I used a similar method to @nosshar by using react-native-orientation to manage the orientation changes in my application.

I first lock the orientation to portrait in the componentDidMount of my root app component.
To display the image I created a modal overlay that is hooked into redux. By calling a specific redux action I can pass an image uri to the modal overlay and tell it to become visible.

In the ImageModal I use ImageView to display the image that is passed to it. In the ImageModal

  • componentWillReceiveProps: I check to see if the modal has been told to become visible if it has I unlock the orientations and I add a listener to orientation updates, Orientation.addOrientationListener. This allows me to set the state of the key on orientation changes.
  • ImageView: I pass the key as a prop to the ImageView, by changing the key on each orientation change it forces the ImageView to re-render. (there is probably a better way to do this)
  • closeModal: This method is called when the modal is closed. It tells the ImageModal to close, it removes any listeners that I have set up, and locks the orientation back to portrait.

@andrewmarmion

Which key are you changing to trigger re rendering?

@vvavepacket as simply as this

<ImageViewer 
  key={this.state.render}
  ...
/>

So in my orientationDidChange, I set the state of render with a random number, that way it will always force a render. It may not be the best way of doing it but it is working quite nicely.

Supposedly this PR was merged into master but when I open the image viewer it shows only in portrait. Was this fixed or is still in development?
Thanks.

Edit:
Actually it works in real devices, it just doesn't work in the emulator.

<Modal supportedOrientations={['landscape', 'portrait']} visible={imageVisible}>
        <ImageViewer
        saveToLocalByLongPress={false}
          onSwipeDown={() => setIsImageVisible(false)}
          onCancel={() => setIsImageVisible(false)}
          enableSwipeDown
          imageUrls={[
            {
              url: '',
              props: {
                // Or you can set source directory.
                source: IMAGE.DUMMY_QUESTION,
              },
            },
          ]}
        />
 </Modal>
Was this page helpful?
0 / 5 - 0 ratings

Related issues

koswarabilly picture koswarabilly  路  7Comments

sfatih picture sfatih  路  7Comments

paolospag picture paolospag  路  4Comments

ganeshhfs picture ganeshhfs  路  3Comments

jvaclavik picture jvaclavik  路  6Comments