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

correctly handle orientation on android #2058

Conversation

GiovanniVisentiniCasavo
Copy link
Contributor

Thanks for submitting a PR! Please read these instructions carefully:

  • [ x] Explain the motivation for making this change.
  • [x ] Provide a test plan demonstrating that the code is solid.
  • [x ] Match the code formatting of the rest of the codebase.
  • [x ] Target the main branch, NOT a "stable" branch.

Motivation (required)

the width / height returned by the library is swapped if the image is on portrait mode on some device (tested with Sony zx1 compact, and see also in some samsung device)

this because the library do not look on the image orientation when computing the w/h this is a problem also if the set the maxHight/Width since you are currently compare maxWidth with height and maxHeight with width

fix #1901 #1689

Test Plan (required)

run the example app, take the photo on portrait, check that the height > width
take a photo on landscape and check that width > height

@GiovanniVisentiniCasavo GiovanniVisentiniCasavo changed the title Android orientation correctly handle orientation on android Nov 30, 2022
@VitoMars
Copy link

@Johan-dutoit I don't know who is actively working on this project, so I may have tagged the wrong person, but can you please merge this pull request?

@ulpcan
Copy link

ulpcan commented Jul 25, 2023

We need this change immediately!

@VitoMars
Copy link

Guys I urgently need this pull request to be merged, still today in many devices if you take a vertical photo width and height are reversed. Could any of the project admins please respond? @Johan-dutoit

@VitoMars
Copy link

VitoMars commented Aug 21, 2023

We need this change immediately!

@ulpcan
I managed to solve the problem by using the "react-native-image-size" library to understand the image orientation and fix the problem.. (Although it's a bad solution to use another library to fix the bug of this library) .
I tell you the solution I made to solve the problem if no one answers here

this is how i solved it:

Imports:

import { launchCamera } from 'react-native-image-picker';
import ImageSize from 'react-native-image-size';

launchCamera:

 launchCamera(options, response => {
     if (response.didCancel) {
       console.log('Image selection cancelled');
     } else if (response.errorCode) {
       console.log(
         'Error selecting images:',
         response.errorMessage,
       );
     } else {
       const { uri, fileName, type, width, height } = response.assets[0];
       const { rotation } = await ImageSize.getSize(uri);

       const isVertical = rotation === 90 || rotation === 270;

       const normalizedWidth = isVertical ? height : width;
       const normalizedHeight = isVertical ? width : height;
     }
   });

@xaiamov
Copy link

xaiamov commented Sep 13, 2023

@GiovanniVisentiniCasavo, thank you very much for the patch. Worked for me with the patch-package.

@GiovanniVisentiniCasavo
Copy link
Contributor Author

thanks @xaiamov
@Johan-dutoit do you have intention to merge it? if yes I can resolve the conflict, otherwise you can close this pr and explain way you don't accept this code.

@Johan-dutoit
Copy link
Collaborator

thanks @xaiamov
@Johan-dutoit do you have intention to merge it? if yes I can resolve the conflict, otherwise you can close this pr and explain way you don't accept this code.

Hi, if this genuinely solves an issue, I'll happily merge it. If you can resolve conflicts, I'll run it on the test app and take it from there.

@GiovanniVisentiniCasavo
Copy link
Contributor Author

@Johan-dutoit rebase done!

@GiovanniVisentiniCasavo
Copy link
Contributor Author

@Johan-dutoit can you merge it?

@Johan-dutoit Johan-dutoit merged commit 13cdc7c into react-native-image-picker:main Oct 23, 2023
1 check passed
Johan-dutoit pushed a commit that referenced this pull request Oct 23, 2023
## [7.0.2](v7.0.1...v7.0.2) (2023-10-23)

### Bug Fixes

* correctly handle orientation on android ([#2058](#2058)) ([13cdc7c](13cdc7c))
@Johan-dutoit
Copy link
Collaborator

🎉 This PR is included in version 7.0.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

dibyendu added a commit to dibyendu/react-native-image-picker that referenced this pull request Dec 27, 2023
…ve-image-picker#2058)

2 orientations were NOT handled on Android:
    - ORIENTATION_TRANSPOSE (5)
    - ORIENTATION_TRANSVERSE (7)
* Added checks for the missing orientations before swapping dimensions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[🐛] wrong height and width in android real device
6 participants