Skip to content

Commit

Permalink
fix(crop-area): recalculate sizes on media objectFit change (#506)
Browse files Browse the repository at this point in the history
Co-authored-by: Ruslan Kruchkou <ruslan.kruchkou@sap.com>
  • Loading branch information
kruchkou and Ruslan Kruchkou committed Dec 15, 2023
1 parent 6e6d984 commit ff0e9dd
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Cropper.tsx
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 ff0e9dd

Please sign in to comment.