Skip to content

Commit

Permalink
fix: resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kubabutkiewicz committed Sep 15, 2023
1 parent 0cc9181 commit fd3e146
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
8 changes: 6 additions & 2 deletions src/libs/cropOrRotateImage/index.native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ const cropOrRotateImage: CropOrRotateImage = (uri, actions, options) =>
new Promise((resolve) => {
RNImageManipulator.manipulate(uri, actions, options).then((result) => {
RNFetchBlob.fs.stat(result.uri.replace('file://', '')).then(({size}) => {
const file = Object.assign(result, {size, type: options.type || 'image/jpeg', name: options.name || 'fileName.jpg'});
resolve(file);
resolve({
...result,
size,
type: options.type || 'image/jpeg',
name: options.name || 'fileName.jpg',
});
});
});
});
Expand Down
8 changes: 3 additions & 5 deletions src/libs/cropOrRotateImage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,9 @@ function convertCanvasToFile(canvas: HTMLCanvasElement, options: CropOrRotateIma
if (!blob) {
return;
}
const file = new File([blob], options.name || 'fileName.jpeg', {type: options.type || 'image/jpeg'});
const fileWithUri = Object.assign(file, {uri: URL.createObjectURL(file)});

resolve(fileWithUri);
const file = new File([blob], options.name || 'fileName.jpeg', {type: options.type || 'image/jpeg'}) as FileWithUri;
file.uri = URL.createObjectURL(file);
resolve(file);
});
});
}
Expand Down Expand Up @@ -122,7 +121,6 @@ const cropOrRotateImage: CropOrRotateImage = (uri, actions, options) =>
}
return canvas;
}, originalCanvas);

return convertCanvasToFile(resultCanvas, options);
});

Expand Down
7 changes: 5 additions & 2 deletions src/libs/cropOrRotateImage/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,25 @@ type CropOrRotateImageOptions = {
name: string;
compress: number;
};

type CropOptions = {
originX: number;
originY: number;
width: number;
height: number;
};

type Action = {
crop?: CropOptions;
rotate?: number;
};

type FileWithUri = File & {
uri: string;
};

type RNManipulator = RNImageManipulatorResult & {size: number; type: string; name: string};
type CustomRNImageManipulatorResult = RNImageManipulatorResult & {size: number; type: string; name: string};

type CropOrRotateImage = (uri: string, actions: Action[], options: CropOrRotateImageOptions) => Promise<FileWithUri | RNManipulator>;
type CropOrRotateImage = (uri: string, actions: Action[], options: CropOrRotateImageOptions) => Promise<FileWithUri | CustomRNImageManipulatorResult>;

export type {CropOrRotateImage, CropOptions, Action, FileWithUri, CropOrRotateImageOptions};

0 comments on commit fd3e146

Please sign in to comment.