Skip to content

Commit bb04979

Browse files
authored
Issue 328 ios fix image loading using uri or path (#381)
* feat(example): load image using react-native-vision-camera * fix(ios): fix image loading Use RCTConvert & RCTUmageLoader in order to load images correctly with path and uri * feat(example): load image from url * feat(example): load image using react-native-camera-roll * fix(example): display image correctly on android * docs: specify with which library uri parameter has been tested
1 parent 9def035 commit bb04979

File tree

9 files changed

+349
-120
lines changed

9 files changed

+349
-120
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,12 @@ A basic, sample app is available in [the `example` folder](https://github.com/ba
6464

6565
```javascript
6666
createResizedImage(
67-
path,
67+
/**
68+
* uri parameter accepts`path` or `uri`.
69+
* This property has been tested with the output of @bam.tech/react-native-image-picker,
70+
* react-native-vision-camera, @react-native-camera-roll/camera-roll and http link
71+
**/
72+
uri,
6873
maxWidth,
6974
maxHeight,
7075
compressFormat,
@@ -91,6 +96,10 @@ The promise resolves with an object containing: `path`, `uri`, `name`, `size` (b
9196
| options.mode | Similar to [react-native Image's resizeMode](https://reactnative.dev/docs/image#resizemode): either `contain` (the default), `cover`, or `stretch`. `contain` will fit the image within `width` and `height`, preserving its ratio. `cover` preserves the aspect ratio, and makes sure the image is at least `width` wide or `height` tall. `stretch` will resize the image to exactly `width` and `height`. |
9297
| options.onlyScaleDown | If `true`, will never enlarge the image, and will only make it smaller. |
9398

99+
# Limitations
100+
101+
- If you are using `@react-native-camera-roll/camera-roll` **with new architecture enabled this library is not going to work**. If you try to display an image with the `uri` of the library using `<Image />` you are going to have the following error: `No suitable image URL loader found for ph://...`. This error come from the ReactNative `ImageLoader`, which is the one we are currently using. Help/PR for solving this are welcome. Until then, we recommend using `react-native-image-picker`.
102+
94103
## 👉 About Bam
95104

96105
We are a 100 people company developing and designing multiplatform applications with [React Native](https://www.bam.tech/agence-react-native-paris) using the Lean & Agile methodology. To get more information on the solutions that would suit your needs, feel free to get in touch by [email](mailto://[email protected]) or through or [contact form](https://www.bam.tech/en/contact)!

example/android/app/src/main/AndroidManifest.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
22

33
<uses-permission android:name="android.permission.INTERNET" />
4+
<uses-permission android:name="android.permission.CAMERA" />
5+
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
6+
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
7+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
8+
android:maxSdkVersion="32" />
9+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
410

511
<application
612
android:name=".MainApplication"

example/android/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ buildscript {
66
minSdkVersion = 21
77
compileSdkVersion = 33
88
targetSdkVersion = 33
9+
kotlinVersion = "1.6.20"
910

1011
// We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.
1112
ndkVersion = "23.1.7779620"

example/ios/Podfile.lock

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,8 @@ PODS:
329329
- React-jsinspector (0.71.8)
330330
- React-logger (0.71.8):
331331
- glog
332+
- react-native-cameraroll (5.7.2):
333+
- React-Core
332334
- react-native-image-picker (4.10.3):
333335
- React-Core
334336
- react-native-image-resizer (3.0.5):
@@ -418,6 +420,10 @@ PODS:
418420
- React-logger (= 0.71.8)
419421
- React-perflogger (= 0.71.8)
420422
- SocketRocket (0.6.0)
423+
- VisionCamera (2.15.6):
424+
- React
425+
- React-callinvoker
426+
- React-Core
421427
- Yoga (1.14.0)
422428
- YogaKit (1.18.1):
423429
- Yoga (~> 1.14)
@@ -468,6 +474,7 @@ DEPENDENCIES:
468474
- React-jsiexecutor (from `../node_modules/react-native/ReactCommon/jsiexecutor`)
469475
- React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`)
470476
- React-logger (from `../node_modules/react-native/ReactCommon/logger`)
477+
- "react-native-cameraroll (from `../node_modules/@react-native-camera-roll/camera-roll`)"
471478
- react-native-image-picker (from `../node_modules/react-native-image-picker`)
472479
- react-native-image-resizer (from `../..`)
473480
- React-perflogger (from `../node_modules/react-native/ReactCommon/reactperflogger`)
@@ -483,6 +490,7 @@ DEPENDENCIES:
483490
- React-RCTVibration (from `../node_modules/react-native/Libraries/Vibration`)
484491
- React-runtimeexecutor (from `../node_modules/react-native/ReactCommon/runtimeexecutor`)
485492
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
493+
- VisionCamera (from `../node_modules/react-native-vision-camera`)
486494
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)
487495

488496
SPEC REPOS:
@@ -544,6 +552,8 @@ EXTERNAL SOURCES:
544552
:path: "../node_modules/react-native/ReactCommon/jsinspector"
545553
React-logger:
546554
:path: "../node_modules/react-native/ReactCommon/logger"
555+
react-native-cameraroll:
556+
:path: "../node_modules/@react-native-camera-roll/camera-roll"
547557
react-native-image-picker:
548558
:path: "../node_modules/react-native-image-picker"
549559
react-native-image-resizer:
@@ -574,13 +584,15 @@ EXTERNAL SOURCES:
574584
:path: "../node_modules/react-native/ReactCommon/runtimeexecutor"
575585
ReactCommon:
576586
:path: "../node_modules/react-native/ReactCommon"
587+
VisionCamera:
588+
:path: "../node_modules/react-native-vision-camera"
577589
Yoga:
578590
:path: "../node_modules/react-native/ReactCommon/yoga"
579591

580592
SPEC CHECKSUMS:
581-
boost: 57d2868c099736d80fcd648bf211b4431e51a558
593+
boost: a7c83b31436843459a1961bfd74b96033dc77234
582594
CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
583-
DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54
595+
DoubleConversion: 831926d9b8bf8166fd87886c4abab286c2422662
584596
FBLazyVector: f637f31eacba90d4fdeff3fa41608b8f361c173b
585597
FBReactNativeSpec: 0d9a4f4de7ab614c49e98c00aedfd3bfbda33d59
586598
Flipper: 26fc4b7382499f1281eb8cb921e5c3ad6de91fe0
@@ -593,7 +605,7 @@ SPEC CHECKSUMS:
593605
Flipper-RSocket: d9d9ade67cbecf6ac10730304bf5607266dd2541
594606
FlipperKit: cbdee19bdd4e7f05472a66ce290f1b729ba3cb86
595607
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
596-
glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b
608+
glog: 476ee3e89abb49e07f822b48323c51c57124b572
597609
hermes-engine: 47986d26692ae75ee7a17ab049caee8864f855de
598610
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
599611
OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c
@@ -611,6 +623,7 @@ SPEC CHECKSUMS:
611623
React-jsiexecutor: 747911ab5921641b4ed7e4900065896597142125
612624
React-jsinspector: c712f9e3bb9ba4122d6b82b4f906448b8a281580
613625
React-logger: 342f358b8decfbf8f272367f4eacf4b6154061be
626+
react-native-cameraroll: 134805127580aed23403b8c2cb1548920dd77b3a
614627
react-native-image-picker: 60f4246eb5bb7187fc15638a8c1f13abd3820695
615628
react-native-image-resizer: 00ceb0e05586c7aadf061eea676957a6c2ec60fa
616629
React-perflogger: d21f182895de9d1b077f8a3cd00011095c8c9100
@@ -627,9 +640,10 @@ SPEC CHECKSUMS:
627640
React-runtimeexecutor: 7c51ae9d4b3e9608a2366e39ccaa606aa551b9ed
628641
ReactCommon: 85c98ab0a509e70bf5ee5d9715cf68dbf495b84c
629642
SocketRocket: fccef3f9c5cedea1353a9ef6ada904fde10d6608
643+
VisionCamera: 523b49054bee9dace64189ab6631cb41e8b83fe0
630644
Yoga: 065f0b74dba4832d6e328238de46eb72c5de9556
631645
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a
632646

633647
PODFILE CHECKSUM: d12e6625eb5869c057639e02d65105cb9b470445
634648

635-
COCOAPODS: 1.12.0
649+
COCOAPODS: 1.12.1

example/ios/ReactNativeImageResizerExample/Info.plist

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,11 @@
5151
</array>
5252
<key>UIViewControllerBasedStatusBarAppearance</key>
5353
<false/>
54+
<key>NSCameraUsageDescription</key>
55+
<string>$(PRODUCT_NAME) needs access to your Camera.</string>
56+
<key>NSPhotoLibraryUsageDescription</key>
57+
<string>$(PRODUCT_NAME) needs access your photo library.</string>
58+
<key>NSPhotoLibraryAddUsageDescription</key>
59+
<string>$(PRODUCT_NAME) needs access your photo library.</string>
5460
</dict>
5561
</plist>

example/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@
99
"pods": "pod-install --quiet"
1010
},
1111
"dependencies": {
12+
"@react-native-camera-roll/camera-roll": "^5.7.2",
1213
"react": "18.2.0",
1314
"react-native": "0.71.8",
14-
"react-native-image-picker": "^4.8.4"
15+
"react-native-image-picker": "^4.8.4",
16+
"react-native-vision-camera": "^2.15.6"
1517
},
1618
"devDependencies": {
1719
"@babel/core": "^7.20.0",
1820
"@babel/preset-env": "^7.20.0",
1921
"@babel/runtime": "^7.20.0",
20-
"metro-react-native-babel-preset": "0.73.9",
21-
"babel-plugin-module-resolver": "^4.1.0"
22+
"babel-plugin-module-resolver": "^4.1.0",
23+
"metro-react-native-babel-preset": "0.73.9"
2224
}
2325
}

0 commit comments

Comments
 (0)