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({ unstable__openModal({
name: 'crop-image', name: 'crop-image',
uri: opts.path, uri: opts.path,
dimensions:
opts.width && opts.height
? {width: opts.width, height: opts.height}
: undefined,
onSelect: (img?: RNImage) => { onSelect: (img?: RNImage) => {
if (img) { if (img) {
resolve(img) resolve(img)
+1
View File
@@ -39,6 +39,7 @@ export interface ListAddRemoveUsersModal {
export interface CropImageModal { export interface CropImageModal {
name: 'crop-image' name: 'crop-image'
uri: string uri: string
dimensions?: {width: number; height: number}
onSelect: (img?: RNImage) => void onSelect: (img?: RNImage) => void
} }
+7 -1
View File
@@ -17,9 +17,11 @@ export const snapPoints = ['0%']
export function Component({ export function Component({
uri, uri,
dimensions,
onSelect, onSelect,
}: { }: {
uri: string uri: string
dimensions?: {width: number; height: number}
onSelect: (img?: RNImage) => void onSelect: (img?: RNImage) => void
}) { }) {
const pal = usePalette('default') const pal = usePalette('default')
@@ -31,6 +33,7 @@ export function Component({
const [crop, setCrop] = React.useState<PercentCrop>() const [crop, setCrop] = React.useState<PercentCrop>()
const isEmpty = !crop || (crop.width || crop.height) === 0 const isEmpty = !crop || (crop.width || crop.height) === 0
const aspect = dimensions ? dimensions.width / dimensions.height : undefined
const onPressCancel = () => { const onPressCancel = () => {
onSelect(undefined) onSelect(undefined)
@@ -75,7 +78,10 @@ export function Component({
return ( return (
<View> <View>
<View style={[styles.cropper, pal.borderDark]}> <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'}} /> <img ref={imageRef} src={uri} style={{maxHeight: '75vh'}} />
</ReactCrop> </ReactCrop>
</View> </View>