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

Dragging cannot make the image fully inside the cropping box. #540

Open
powerseed opened this issue May 21, 2024 · 8 comments
Open

Dragging cannot make the image fully inside the cropping box. #540

powerseed opened this issue May 21, 2024 · 8 comments

Comments

@powerseed
Copy link

Screenshot_1

@ValentinH
Copy link
Owner

Did you change any CSS to reach this result?

@powerseed
Copy link
Author

Did you change any CSS to reach this result?

The way I use this component:

                <Cropper
                    image={props.mediaUrl}
                    crop={crop}
                    zoom={zoom}
                    aspect={1 / 1}
                    onCropChange={setCrop}
                    onCropComplete={onCropComplete}
                    onZoomChange={setZoom}
                    minZoom={1}
                    objectFit='horizontal-cover'
                    style={{
                        containerStyle: {
                            position: 'relative',
                            width: '100%',
                            height: '100%',
                            overflow: 'hidden',
                            borderRadius: '0rem 0rem 1rem 1rem'
                        },
                        mediaStyle: {
                            height: '100%',
                            width: 'auto',
                            maxWidth: 'unset'
                        }
                    }}
                />

Plus custom CSS:

.reactEasyCrop_CropArea {
    width: 100% !important;
    height: 100% !important;
}

I think they are all css changes that I made.

@ValentinH
Copy link
Owner

Yes so this is expected. The internal logic doesn't know anything about the style overrides so the positioning doesn't match anymore.

What are you trying to achieve? Why using these overrides?

@powerseed
Copy link
Author

Yes so this is expected. The internal logic doesn't know anything about the style overrides so the positioning doesn't match anymore.

What are you trying to achieve? Why using these overrides?

Simply put, it is the exact effect at Instagram.
If you open Instagram and try to create a new post, upload an image large enough, you will see it.

I want the image to be displayed taking the full height of the container, which may lead to its width overflowing, and the overflowing parts are hidden, but they can be reached by dragging to the left or right.

Now the bold part above is not achieveable.

I think it should be doable, because the lib knows the container's border and that of the image, so it just needs to calculate the value for translation to make them overlapped.

Now the max limit in my case is translating by 98px, which leads to the narrow strip.
If I change it to 130px-ish in Dev Tool manually, then the effect is correct.

@powerseed
Copy link
Author

powerseed commented May 21, 2024

Yes so this is expected. The internal logic doesn't know anything about the style overrides so the positioning doesn't match anymore.

What are you trying to achieve? Why using these overrides?

If I zoom in the image (make it bigger), the problem gets worse, and I can reach a even smaller portion of the image.

@ValentinH
Copy link
Owner

Have you tried using the vertical-cover value for objectFit?

@powerseed
Copy link
Author

Have you tried using the vertical-cover value for objectFit?

Ah... It is my fault..

It should be vertical-cover in the first place... because I want the image to take the full height, which is vertically fill the cropper as the doc says...

I tried the wrong one (horizontal), then used the CSS

mediaStyle: {
    height: '100%',
    width: 'auto',
    ...
}

to make it look like it worked, but caused some internal conflicts which lead to the issue.

Sorry about taking your time!

@ValentinH
Copy link
Owner

No worries, I'm here to help 🙂

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

No branches or pull requests

2 participants