about summary refs log tree commit diff
path: root/src/state/models
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2023-09-27 09:08:21 -0700
committerGitHub <noreply@github.com>2023-09-27 09:08:21 -0700
commitd87c232660f215608c26280f4cfbd5af3948f9d1 (patch)
treefc5ac5782e48128650293d92e83ae41b8c4a9c03 /src/state/models
parent6325eff938495b88a3808aef3c772e9fe93d5550 (diff)
downloadvoidsky-d87c232660f215608c26280f4cfbd5af3948f9d1.tar.zst
Improve image cropping on android and introduce aspect ratio field (#1525)
* Fix image cropping on android

* Store and use aspect ratio field in post images (close #1392)
Diffstat (limited to 'src/state/models')
-rw-r--r--src/state/models/media/image.ts13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/state/models/media/image.ts b/src/state/models/media/image.ts
index 844ecb778..10aef0ff4 100644
--- a/src/state/models/media/image.ts
+++ b/src/state/models/media/image.ts
@@ -8,6 +8,7 @@ import {openCropper} from 'lib/media/picker'
 import {ActionCrop, FlipType, SaveFormat} from 'expo-image-manipulator'
 import {Position} from 'react-avatar-editor'
 import {Dimensions} from 'lib/media/types'
+import {isIOS} from 'platform/detection'
 
 export interface ImageManipulationAttributes {
   aspectRatio?: '4:3' | '1:1' | '3:4' | 'None'
@@ -164,8 +165,13 @@ export class ImageModel implements Omit<RNImage, 'size'> {
   // Mobile
   async crop() {
     try {
-      // openCropper requires an output width and height hence
-      // getting upload dimensions before cropping is necessary.
+      // NOTE
+      // on ios, react-native-image-cropper gives really bad quality
+      // without specifying width and height. on android, however, the
+      // crop stretches incorrectly if you do specify it. these are
+      // both separate bugs in the library. we deal with that by
+      // providing width & height for ios only
+      // -prf
       const {width, height} = this.getUploadDimensions({
         width: this.width,
         height: this.height,
@@ -175,8 +181,7 @@ export class ImageModel implements Omit<RNImage, 'size'> {
         mediaType: 'photo',
         path: this.path,
         freeStyleCropEnabled: true,
-        width,
-        height,
+        ...(isIOS ? {width, height} : {}),
       })
 
       runInAction(() => {