Skip to content

Commit

Permalink
fix(crop-area): recalculate sizes on objectFit change
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruslan Kruchkou committed Dec 14, 2023
1 parent 6e6d984 commit 8e9c779
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Cropper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export type CropperProps = {
type State = {
cropSize: Size | null
hasWheelJustStarted: boolean
mediaObjectFit: String | undefined
}

const MIN_ZOOM = 1
Expand Down Expand Up @@ -121,6 +122,7 @@ class Cropper extends React.Component<CropperProps, State> {
state: State = {
cropSize: null,
hasWheelJustStarted: false,
mediaObjectFit: undefined
}

componentDidMount() {
Expand Down Expand Up @@ -218,6 +220,11 @@ class Cropper extends React.Component<CropperProps, State> {
if (prevProps.video !== this.props.video) {
this.videoRef.current?.load()
}

const objectFit = this.getObjectFit();
if (objectFit !== this.state.mediaObjectFit) {
this.setState({mediaObjectFit: objectFit}, this.computeSizes)
}
}

initResizeObserver = () => {
Expand Down Expand Up @@ -350,8 +357,7 @@ class Cropper extends React.Component<CropperProps, State> {
let renderedMediaSize: Size

if (isMediaScaledDown) {
const objectFit = this.getObjectFit()
switch (objectFit) {
switch (this.state.mediaObjectFit) {
default:
case 'contain':
renderedMediaSize =
Expand Down Expand Up @@ -737,7 +743,7 @@ class Cropper extends React.Component<CropperProps, State> {
classes: { containerClassName, cropAreaClassName, mediaClassName },
} = this.props

const objectFit = this.getObjectFit()
const objectFit = this.state.mediaObjectFit;

return (
<div
Expand Down

0 comments on commit 8e9c779

Please sign in to comment.