| 16 | symbolRotateEffect = ImageSymbolEffects.Rotate; |
| 17 | |
| 18 | pickImage() { |
| 19 | const context = create({ |
| 20 | mode: 'single', |
| 21 | mediaType: ImagePickerMediaType.Image, |
| 22 | }); |
| 23 | |
| 24 | context |
| 25 | .authorize() |
| 26 | .then(() => { |
| 27 | return context.present(); |
| 28 | }) |
| 29 | .then((selections) => { |
| 30 | const selection = selections.length > 0 ? selections[0] : null; |
| 31 | if (selection) { |
| 32 | this.addingPhoto = true; |
| 33 | const imageAsset = selection.asset; |
| 34 | |
| 35 | ImageSource.fromAsset(imageAsset).then( |
| 36 | (savedImage) => { |
| 37 | const folder = knownFolders.documents(); |
| 38 | const filePath = path.join(folder.path, `assets-${Date.now()}.jpg`); |
| 39 | console.log('filePath:', filePath); |
| 40 | |
| 41 | const saved = savedImage.saveToFile(filePath, 'jpg'); |
| 42 | if (saved) { |
| 43 | console.log(`file saved:`, filePath); |
| 44 | } else { |
| 45 | console.log('file not saved!'); |
| 46 | } |
| 47 | this.addingPhoto = false; |
| 48 | }, |
| 49 | (err) => { |
| 50 | this.addingPhoto = false; |
| 51 | }, |
| 52 | ); |
| 53 | } |
| 54 | }) |
| 55 | .catch((e) => { |
| 56 | console.log(e); |
| 57 | }); |
| 58 | } |
| 59 | } |