Copy images for Android and iOS in React Native, use image from local project.
- Create folder scripts/ from root project.
mkdir scripts
- Clone project:
cd scripts
git clone https://github.com/tuantvk/react-native-copy-image.git;
cd react-native-copy-image;rm -rf .git;
Make sure folder images in rootProject/assets/images/
Add script in package.json
"scripts": {
....
"copy-image": "bash scripts/react-native-copy-image/copy_image.sh" // add here
}
Finally, from root project run:
yarn run copy-image
# or
# npm run copy-image
Check all images in path:
- Android: android/app/src/main/res/drawable/
- iOS: ios/[AppName]/Images.xcassets
Note:
Rebuild app for update resource !
Warning
Images has format to snake_case
Ex: Apple.png -> apple.png | Apple Computer.jpg -> apple_computer.jpg
This is example for image name apple.png
import React from 'react';
import { View, Image } from 'react-native';
const Example = () => (
<View>
<Image
source={{ uri: 'apple' }}
style={{ width: 50, height: 50 }}
/>
</View>
);
export default Example;