React Native Tutorial
- React Native Tutorial
- React Native Environment Setups
- React Native First Application Hello World
- React Native View
- React Native State
- React Native Props
- React Native Style
- React Native Height and Width
- React Native Button
- React Native Layout and Flexbox
- React Native Positioning Element with Flex
- React Native ScrollView
- React Native ListView
- React Native FlatList
- React Native SectionList
- React Native Touchables
- React Native Text Input
- React Native ActivityIndicator
- React Native Picker
- React Native StatusBar
- React Native Switch
- React Native WebView
- React Native ProgressBarAndroid
- React Native ProgressBar With Animated
Navigation
- React Native Navigation
- React Native Configuring Header Bar
- React Native Moving Between Screens
- React Native Passing Value between Screen
- React Native Tab Navigation
- React Native Adding Icons at the Bottom of Tab Navigation
- React Native Create Material Bottom Tab Navigator
- React Native Top Tab Navigator
- React Native Drawer Navigation
Storage
React Misc
- React Native Google Map
- React Native Modal
- React Native Vector Icons
- React Native Splash Screen
- React Native vs. Ionic
- React Native vs. Xamarin
- React Native vs Flutter
- React Native vs React
- React Native vs Swift
- Box shadow in React Native
- React Native IAP
- React-Native Localization
- React Native Toast
- React Native Sound
React Native Image
The Image component is used to display the image on the screen. The image can be loaded from different source such as static resources, temporary local files, local disc, network images, etc.
Static Image Resources
The static images are added in app by placing it in somewhere in the source code directory and provide its path as:
In the above syntax, the packager will look for icon_name.png in the same folder as the component that requires it. To load the image on a specific platform, it should be named by specifying the platform as extensions such as icon_name.ios.png and icon_name.android.png.
Images from Hybrid App's Resources
The hybrid app which is built (UI) by using both React Native and platform code can also uses the image which is bundled into the app.
The image included through Xcode asset catalogs or in Android drawable folder are consumes without their extension.
The images within the Android assets folder, use the scheme: asset:/ with image extension.
Network Images
The dynamic and network images are also be displayed in the Image component. To access the network image, it is required to specify the dimensions of image manually.
It is recommended to use https in order to satisfy the App Transport Security requirements on iOS.
style={{width: 60, height: 60}} />
// BAD
Uri Data Images
The encoded image data use the "data:" uri scheme in the image component. The data image also required to specify the dimension of the image.
source={{uri: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADMAAAAzCAYAAAA6oTAqAAAAEXRFWHRTb2Z0d2FyZQBwbmdjcnVzaEB1SfMAAABQSURBVGje7dSxCQBACARB+2/ab8BEeQNhFi6WSYzYLYudDQYGBgYGBgYGBgYGBgYGBgZmcvDqYGBgmhivGQYGBgYGBgYGBgYGBgYGBgbmQw+P/eMrC5UTVAAAAABJRU5ErkJggg=='}}
/>
Background Image via Nesting
The background image is set using the ImageBackground component. It is also the same props as Image. We can add any component as children on the top of it.
Inside
);
React Native Image Example
App.js
import {StyleSheet, AppRegistry,Text, View, Image,ImageBackground } from 'react-native';
export default class DisplayAnImage extends Component {
render() {
return (
style={{width: '100%', height: '100%'}}>
source={require('/ReactNative/MyReactNativeApp/img/favicon.png')}
/>
source={require('MyReactNativeApp/img/favicon.png')}
/>
style = {{ width: '80%', height: 70 }}
/>
style={{width: 60, height: 60}}
source={{uri: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADMAAAAzCAYAAAA6oTAqAAAAEXRFWHRTb2Z0d2FyZQBwbmdjcnVzaEB1SfMAAABQSURBVGje7dSxCQBACARB+2/ab8BEeQNhFi6WSYzYLYudDQYGBgYGBgYGBgYGBgYGBgZmcvDqYGBgmhivGQYGBgYGBgYGBgYGBgYGBgbmQw+P/eMrC5UTVAAAAABJRU5ErkJggg=='}}
/>
);
}
}
// skip this line if using Create React Native App
AppRegistry.registerComponent('DisplayAnImage', () => DisplayAnImage);
Output: