react native image local file path code example
Example 1: react native image file path variable
const images = {
profile: {
profile: require('./profile/profile.png'),
comments: require('./profile/comments.png'),
},
image1: require('./image1.jpg'),
image2: require('./image2.jpg'),
};
return (
<View>
{
props.profile ? <Image source={images.profile.profile} /> : <Image source={images.profile.comments} />
}
</View>
)
Example 2: react native preload local images
import { Image } from 'react-native';
import FastImage from 'react-native-fast-image';
export function preloadImages() {
const images = [
require('../assets/images/graphic1.webp'),
require('../assets/images/graphic2.jpg'),
require('../assets/images/graphic3.webp')
];
const uris = images.map(image => ({
uri: Image.resolveAssetSource(image).uri
}));
FastImage.preload(uris);
}