refactor: bring back dimensions

This commit is contained in:
Mary
2024-05-08 12:12:23 +07:00
parent 35ca71e07d
commit e4410a8bad
3 changed files with 12 additions and 1 deletions
+4
View File
@@ -17,6 +17,10 @@ export async function openCropper(opts: CropperOptions): Promise<RNImage> {
unstable__openModal({
name: 'crop-image',
uri: opts.path,
dimensions:
opts.width && opts.height
? {width: opts.width, height: opts.height}
: undefined,
onSelect: (img?: RNImage) => {
if (img) {
resolve(img)
+1
View File
@@ -39,6 +39,7 @@ export interface ListAddRemoveUsersModal {
export interface CropImageModal {
name: 'crop-image'
uri: string
dimensions?: {width: number; height: number}
onSelect: (img?: RNImage) => void
}
+7 -1
View File
@@ -17,9 +17,11 @@ export const snapPoints = ['0%']
export function Component({
uri,
dimensions,
onSelect,
}: {
uri: string
dimensions?: {width: number; height: number}
onSelect: (img?: RNImage) => void
}) {
const pal = usePalette('default')
@@ -31,6 +33,7 @@ export function Component({
const [crop, setCrop] = React.useState<PercentCrop>()
const isEmpty = !crop || (crop.width || crop.height) === 0
const aspect = dimensions ? dimensions.width / dimensions.height : undefined
const onPressCancel = () => {
onSelect(undefined)
@@ -75,7 +78,10 @@ export function Component({
return (
<View>
<View style={[styles.cropper, pal.borderDark]}>
<ReactCrop crop={crop} onChange={(_, next) => setCrop(next)}>
<ReactCrop
aspect={aspect}
crop={crop}
onChange={(_, next) => setCrop(next)}>
<img ref={imageRef} src={uri} style={{maxHeight: '75vh'}} />
</ReactCrop>
</View>