react-native-image-viewer icon indicating copy to clipboard operation
react-native-image-viewer copied to clipboard

Landscape Orientation

Open andreecosta opened this issue 8 years ago • 11 comments

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

andreecosta avatar Jun 01 '17 16:06 andreecosta

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

yarn
npm start

ascoders avatar Jun 28 '17 03:06 ascoders

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

andreecosta avatar Jun 30 '17 11:06 andreecosta

@itswaze you could give a chance to https://github.com/ldn0x7dc/react-native-transformable-image

tugorez avatar Aug 15 '17 17:08 tugorez

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!

nosshar avatar Nov 28 '17 16:11 nosshar

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 avatar Mar 23 '18 10:03 andrewmarmion

@andrewmarmion

Which key are you changing to trigger re rendering?

vvavepacket avatar Apr 27 '18 13:04 vvavepacket

@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.

andrewmarmion avatar Apr 27 '18 13:04 andrewmarmion

Please see my PR for this issue: https://github.com/ascoders/react-native-image-viewer/pull/178

bradsolves avatar May 01 '18 20:05 bradsolves

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.

nbastoWM avatar Sep 12 '18 09:09 nbastoWM

<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>

ialisyed avatar Jan 21 '21 14:01 ialisyed

<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>

thanks for the answer you saved the day dude

chandrabuw avatar Jun 23 '21 15:06 chandrabuw