Skip to content
New issue

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

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

Already on GitHub? # to your account

Compatibility with react-modal on iOS #219

Closed
tudorpavel opened this issue Nov 14, 2018 · 15 comments
Closed

Compatibility with react-modal on iOS #219

tudorpavel opened this issue Nov 14, 2018 · 15 comments

Comments

@tudorpavel
Copy link

I couldn't find any previous discussion on this, so I will start one here.

Our use case involves adding ReactCrop inside a react-modal and we noticed that ReactCrop does not work properly on iOS when placed inside a modal. Basically, the crop rectangle disappears.

I'm not sure what could be causing this, but my guess is that on iOS Safari the getElementOffset code works unexpectedly because of the way the modal is positioned? I'm going to try to debug this further tomorrow.

I've modified the demo to include a modal for debugging purposes:
https://github.com/Camversity/react-image-crop/tree/debug-modal

Any thoughts on this?

@dominictobias
Copy link
Owner

Hi, are you running this on a mobile phone from a server by any chance?

@tudorpavel
Copy link
Author

The demo? Yep, I'm using serve to open the demo on a mobile phone:

yarn global add serve
cd react-image-crop
serve -s .

And then using my local IP and port 5000 on the device.

@dominictobias
Copy link
Owner

dominictobias commented Nov 14, 2018

Then please pull the latest master and npm install, otherwise you don't get ReactCrop.css because the relative path to it ../dist/ReactCrop.css in the demo index.html doesn't work when running a server. After that it should be fine in a modal.

@tudorpavel
Copy link
Author

I did have that problem initially because I used serve with just the demo/ folder, but after that I made sure the CSS is loaded properly by serving the entire repo folder. The crop rectangle appears initially but the problems start when trying to move/resize it.

Regardless, we first noticed these issues in our app which uses create-react-app.

@dominictobias
Copy link
Owner

dominictobias commented Nov 14, 2018

Hm strange, your fork works fine for me if I npm start and then open demo/index.html (without a server), even after moving, resizing etc

@tudorpavel
Copy link
Author

Did you try it on an iPhone with Safari? It works fine everywhere else, as is usually the case with Safari... 😢

@dominictobias
Copy link
Owner

dominictobias commented Nov 14, 2018

I did just try updating your branch against master so that it has the change in demo.js at the top import '../dist/ReactCrop.css'; and then I ran a simply python server python -m SimpleHTTPServer 3636 inside the demo folder. I moved it around and resized it etc:

ios

@tudorpavel
Copy link
Author

Hmm, interesting... It's true I tested it with 6.0.7 earlier when I was still in the office but now I don't have an iPhone with me.

I will check again tomorrow morning, thanks!

We can close this for now.

@tudorpavel
Copy link
Author

To follow up, I have it working as expected in the demo. The popup in our app still behaves strangely on small screen (iPhone) even though it works as in the demo on large screen (iPad). I will have to investigate it further in our setup.

@tudorpavel
Copy link
Author

I've finally gotten to the bottom of this... The weird behavior was in fact due to 2 issues:

  1. My mistake from Wrong aspect ratio when setting all width, height and aspect #220: I was setting all width, height and crop. The solution was to set initial values only for width and crop, while setting height: null.

  2. Issues with EXIF orientation discussed in rotate 90deg crop image on iPhone #205 and mentioned in the README (I should've RTFD), I was calculating the image width and height in memory with the uploaded File/Blob using this naive approach. I needed to do this before rendering ReactCrop. My photo was landscape in memory and portrait in ReactCrop due to EXIF orientation. The solution was to use blueimp-load-image to load the image in memory with orientation: true:

const getImageDimensions = (imageFile) => {
  return new Promise((resolve) => {
    loadImage(
      imageFile,
      (img) => {
        resolve({ width: img.width, height: img.height });
      },
      {
        orientation: true
      }
    );
  });
};

@dominictobias thanks for this library and thanks for your help!

@dominictobias
Copy link
Owner

dominictobias commented Nov 15, 2018 via email

@dominictobias
Copy link
Owner

dominictobias commented Nov 15, 2018 via email

@tudorpavel
Copy link
Author

Ps I’m thinking about maybe making the drag handles slightly larger for touch devices, if you have trouble dragging them let me know.

Sure, I guess it couldn't hurt to have them larger to improve the UX on touch devices. 👍

@osdiab
Copy link

osdiab commented Sep 13, 2019

@dominictobias assuming drag handles aren't larger yet, is there a way to configure them to be larger?

@dominictobias
Copy link
Owner

dominictobias commented Sep 21, 2019

They are larger now but if you want to adjust them further the easiest way is to set some sass variables before? importing the file - https://github.com/DominicTobias/react-image-crop/blob/master/lib/ReactCrop.scss#L11 but you can also just override in CSS too. Probably the experience can be optimised further for mobile as discussed here - #201

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants