refactor: bring back dimensions
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
Reference in New Issue
Block a user