4. Image #

Created Tue Nov 14, 2023 at 11:44 PM

Custom component for image - uncontrolled and controlled

<Image /> #

import { Image } from 'react-native';

function MyComponent() {

  // local image
  <Image source={require("../flag.png")} />;

  // remote image - need to specify dimensions
  <Image source={{ uri: 'https//site.com/flag', width: 200, height: 100 }} />
}

 

<ImageBackground /> #

A core component for rendering an image in the background with children rendering in the foreground.

Usage

import { ImageBackground } from "react-native";

<ImageBackground 
  styles={{ flex: 1}}
  source={require("../assets/Welcome.jpg")}
>

  <View>Sign in</View>
  <View>Sign up</View>
  <View>Privacy policy</View>
</ImageBackground>