mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
46 lines
63 KiB
HTML
46 lines
63 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
<meta name="generator" content="Docusaurus v2.0.0-alpha.70">
|
|
<link rel="alternate" type="application/rss+xml" href="/blog/rss.xml" title="React Native Blog RSS Feed">
|
|
<link rel="alternate" type="application/atom+xml" href="/blog/atom.xml" title="React Native Blog Atom Feed">
|
|
<link rel="preconnect" href="https://www.google-analytics.com">
|
|
<script>window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)},ga.l=+new Date,ga("create","UA-41298772-2","auto"),ga("send","pageview")</script>
|
|
<script async src="https://www.google-analytics.com/analytics.js"></script>
|
|
<link rel="preconnect" href="https://www.google-analytics.com">
|
|
<link rel="preconnect" href="https://www.googletagmanager.com">
|
|
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-41298772-2"></script>
|
|
<script>function gtag(){dataLayer.push(arguments)}window.dataLayer=window.dataLayer||[],gtag("js",new Date),gtag("config","UA-41298772-2",{})</script>
|
|
<link rel="search" type="application/opensearchdescription+xml" title="React Native" href="/opensearch.xml">
|
|
<script src="https://cdn.jsdelivr.net/npm/focus-visible@5.2.0/dist/focus-visible.min.js" defer="defer"></script>
|
|
<script src="https://snack.expo.io/embed.js" defer="defer"></script><title data-react-helmet="true">Image · React Native</title><meta data-react-helmet="true" name="twitter:image:alt" content="Image for React Native"><meta data-react-helmet="true" name="docsearch:language" content="en"><meta data-react-helmet="true" name="docsearch:version" content="current"><meta data-react-helmet="true" name="docsearch:docusaurus_tag" content="docs-default-current"><meta data-react-helmet="true" property="og:image" content="https://reactnative.dev/img/logo-og.png"><meta data-react-helmet="true" name="twitter:card" content="summary"><meta data-react-helmet="true" name="twitter:image" content="https://reactnative.dev/img/logo-og.png"><meta data-react-helmet="true" property="og:title" content="Image · React Native"><meta data-react-helmet="true" name="description" content="A React component for displaying different types of images, including network images, static resources, temporary local images, and images from local disk, such as the camera roll."><meta data-react-helmet="true" property="og:description" content="A React component for displaying different types of images, including network images, static resources, temporary local images, and images from local disk, such as the camera roll."><meta data-react-helmet="true" property="og:url" content="https://reactnative.dev/docs/next/image"><link data-react-helmet="true" rel="shortcut icon" href="/img/favicon.ico"><link data-react-helmet="true" rel="preconnect" href="https://BH4D9OD16A-dsn.algolia.net" crossorigin="anonymous"><link data-react-helmet="true" rel="canonical" href="https://reactnative.dev/docs/next/image"><link rel="stylesheet" href="/styles.9eb50f2e.css">
|
|
<link rel="stylesheet" href="/main.3de2b5ef.css">
|
|
<link rel="preload" href="/styles.1b71bc8a.js" as="script">
|
|
<link rel="preload" href="/runtime~main.c97aa552.js" as="script">
|
|
<link rel="preload" href="/main.253479d9.js" as="script">
|
|
<link rel="preload" href="/1.4dffec5b.js" as="script">
|
|
<link rel="preload" href="/2.8fcdf5b9.js" as="script">
|
|
<link rel="preload" href="/939.c1f14adb.js" as="script">
|
|
<link rel="preload" href="/935f2afb.63ef0aae.js" as="script">
|
|
<link rel="preload" href="/17896441.81f68a15.js" as="script">
|
|
<link rel="preload" href="/4261946e.aa2b8ad3.js" as="script">
|
|
</head>
|
|
<body>
|
|
<script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}()</script><div id="__docusaurus">
|
|
<nav aria-label="Skip navigation links"><button type="button" tabindex="0" class="skipToContent_3aLp">Skip to main content</button></nav><nav class="navbar navbar--fixed-top navbar--dark"><div class="navbar__inner"><div class="navbar__items"><div aria-label="Navigation bar toggle" class="navbar__toggle" role="button" tabindex="0"><svg aria-label="Menu" width="30" height="30" viewBox="0 0 30 30" role="img" focusable="false"><title>Menu</title><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></div><a class="navbar__brand" href="/"><img src="/img/header_logo.svg" alt="React Native" class="themedImage_phiS themedImage--light_VJaY navbar__logo"><img src="/img/header_logo.svg" alt="React Native" class="themedImage_phiS themedImage--dark_1NF3 navbar__logo"><strong class="navbar__title">React Native</strong></a><div class="navbar__item dropdown dropdown--hoverable dropdown--left"><a class="navbar__item navbar__link" href="/docs/next/getting-started">Next</a><ul class="dropdown__menu"><li><a aria-current="page" class="dropdown__link dropdown__link--active" href="/docs/next/image">Next</a></li><li><a class="dropdown__link" href="/docs/image">0.63</a></li><li><a class="dropdown__link" href="/docs/0.62/image">0.62</a></li><li><a class="dropdown__link" href="/docs/0.61/image">0.61</a></li><li><a class="dropdown__link" href="/docs/0.60/image">0.60</a></li><li><a class="dropdown__link" href="/versions">All versions</a></li></ul></div></div><div class="navbar__items navbar__items--right"><a class="navbar__item navbar__link" href="/docs/next/getting-started">Docs</a><a class="navbar__item navbar__link navbar__link--active" href="/docs/next/components-and-apis">Components</a><a class="navbar__item navbar__link" href="/docs/next/accessibilityinfo">API</a><a class="navbar__item navbar__link" href="/help">Community</a><a class="navbar__item navbar__link" href="/blog">Blog</a><a href="https://github.com/facebook/react-native" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link navbar-github-link" aria-label="GitHub repository"></a><div class="react-toggle react-toggle--disabled displayOnlyInLargeViewport_Bh6k"><div class="react-toggle-track"><div class="react-toggle-track-check"><span class="toggle_1UDy">🌜</span></div><div class="react-toggle-track-x"><span class="toggle_1UDy">🌞</span></div></div><div class="react-toggle-thumb"></div><input type="checkbox" disabled="" aria-label="Dark mode toggle" class="react-toggle-screenreader-only"></div><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><svg width="20" height="20" class="DocSearch-Search-Icon" viewBox="0 0 20 20"><path d="M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z" stroke="currentColor" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"></path></svg><span class="DocSearch-Button-Placeholder">Search</span></span></button></div></div><div role="presentation" class="navbar-sidebar__backdrop"></div><div class="navbar-sidebar"><div class="navbar-sidebar__brand"><a class="navbar__brand" href="/"><img src="/img/header_logo.svg" alt="React Native" class="themedImage_phiS themedImage--light_VJaY navbar__logo"><img src="/img/header_logo.svg" alt="React Native" class="themedImage_phiS themedImage--dark_1NF3 navbar__logo"><strong class="navbar__title">React Native</strong></a></div><div class="navbar-sidebar__items"><div class="menu"><ul class="menu__list"><li class="menu__list-item"><a class="menu__link" href="/docs/next/getting-started">Docs</a></li><li class="menu__list-item"><a class="menu__link navbar__link--active" href="/docs/next/components-and-apis">Components</a></li><li class="menu__list-item"><a class="menu__link" href="/docs/next/accessibilityinfo">API</a></li><li class="menu__list-item"><a class="menu__link" href="/help">Community</a></li><li class="menu__list-item"><a class="menu__link" href="/blog">Blog</a></li><li class="menu__list-item"><a role="button" class="menu__link menu__link--sublist">Versions</a><ul class="menu__list"><li class="menu__list-item"><a aria-current="page" class="menu__link menu__link--active" href="/docs/next/image">Next</a></li><li class="menu__list-item"><a class="menu__link" href="/docs/image">0.63</a></li><li class="menu__list-item"><a class="menu__link" href="/docs/0.62/image">0.62</a></li><li class="menu__list-item"><a class="menu__link" href="/docs/0.61/image">0.61</a></li><li class="menu__list-item"><a class="menu__link" href="/docs/0.60/image">0.60</a></li><li class="menu__list-item"><a class="menu__link" href="/versions">All versions</a></li></ul></li><li class="menu__list-item"><a href="https://github.com/facebook/react-native" target="_blank" rel="noopener noreferrer" class="menu__link navbar-github-link" aria-label="GitHub repository"></a></li></ul></div></div></div></nav><div class="main-wrapper"><div class="docPage_1mVJ"><div class="docSidebarContainer_uPTz" role="complementary"><div class="sidebar_M-Lc"><div class="menu menu--responsive thin-scrollbar menu_tgpy"><button aria-label="Open Menu" aria-haspopup="true" class="button button--secondary button--sm menu__button" type="button"><svg aria-label="Menu" class="sidebarMenuIcon_1e05" width="24" height="24" viewBox="0 0 30 30" role="img" focusable="false"><title>Menu</title><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><ul class="menu__list"><li class="menu__list-item"><a class="menu__link menu__link--sublist menu__link--active" href="#!">Core Components</a><ul class="menu__list"><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/next/components-and-apis">Core Components and APIs</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/next/activityindicator">ActivityIndicator</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/next/button">Button</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/next/flatlist">FlatList</a></li><li class="menu__list-item"><a aria-current="page" class="menu__link menu__link--active active" tabindex="0" href="/docs/next/image">Image</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/next/imagebackground">ImageBackground</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/next/keyboardavoidingview">KeyboardAvoidingView</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/next/modal">Modal</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/next/pressable">Pressable</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/next/refreshcontrol">RefreshControl</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/next/scrollview">ScrollView</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/next/sectionlist">SectionList</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/next/statusbar">StatusBar</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/next/switch">Switch</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/next/text">Text</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/next/textinput">TextInput</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/next/touchablehighlight">TouchableHighlight</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/next/touchableopacity">TouchableOpacity</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/next/touchablewithoutfeedback">TouchableWithoutFeedback</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/next/view">View</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/next/virtualizedlist">VirtualizedList</a></li><li class="menu__list-item"><a class="menu__link menu__link--sublist" href="#!" tabindex="0">Android Components</a><ul class="menu__list"><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/next/drawerlayoutandroid">DrawerLayoutAndroid</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/next/touchablenativefeedback">TouchableNativeFeedback</a></li></ul></li><li class="menu__list-item"><a class="menu__link menu__link--sublist" href="#!" tabindex="0">iOS Components</a><ul class="menu__list"><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/next/inputaccessoryview">InputAccessoryView</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/next/safeareaview">SafeAreaView</a></li></ul></li></ul></li><li class="menu__list-item menu__list-item--collapsed"><a class="menu__link menu__link--sublist" href="#!">Props</a><ul class="menu__list"><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/next/image-style-props">Image Style Props</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/next/layout-props">Layout Props</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/next/shadow-props">Shadow Props</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/next/text-style-props">Text Style Props</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/next/view-style-props">View Style Props</a></li></ul></li><li class="menu__list-item menu__list-item--collapsed"><a class="menu__link menu__link--sublist" href="#!">Object Types</a><ul class="menu__list"><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/next/layoutevent">LayoutEvent Object Type</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/next/pressevent">PressEvent Object Type</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/next/react-node">React Node Object Type</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/next/rect">Rect Object Type</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/next/viewtoken">ViewToken Object Type</a></li></ul></li></ul></div></div></div><main class="docMainContainer_1zi2"><div class="container padding-vert--lg docItemWrapper_1hMI"><div class="row"><div class="col docItemCol_2AGf"><div class="alert alert--warning margin-bottom--md" role="alert"><div>This is unreleased documentation for React Native <strong>Next</strong> version.</div><div class="margin-top--md">For up-to-date documentation, see the <strong><a href="/docs/image">latest version</a></strong> (0.63).</div></div><div class="docItemContainer_1tAC"><article><div><span class="badge badge--secondary">Version: Next</span></div><header><h1 class="docTitle_cWlf">Image</h1></header><div class="markdown"><p>A React component for displaying different types of images, including network images, static resources, temporary local images, and images from local disk, such as the camera roll.</p><p>This example shows fetching and displaying an image from local storage as well as one from network and even from data provided in the <code>'data:'</code> uri scheme.</p><blockquote><p>Note that for network and data images, you will need to manually specify the dimensions of your image!</p></blockquote><h2><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="examples"></a>Examples<a class="hash-link" href="#examples" title="Direct link to heading">#</a></h2><div><ul role="tablist" aria-orientation="horizontal" class="tabs"><li role="tab" tabindex="0" aria-selected="true" class="tabs__item tabItem_2uuE tabs__item--active">Function Component</li><li role="tab" tabindex="0" aria-selected="false" class="tabs__item tabItem_2uuE">Class Component</li></ul><div class="margin-vert--md"><div role="tabpanel"><div class="snack-player" data-snack-name="Function Component Example" data-snack-description="Example usage" data-snack-code="%0Aimport%20React%20from%20'react'%3B%0Aimport%20%7B%20View%2C%20Image%2C%20StyleSheet%20%7D%20from%20'react-native'%3B%0A%0Aconst%20styles%20%3D%20StyleSheet.create(%7B%0A%20%20container%3A%20%7B%0A%20%20%20%20paddingTop%3A%2050%2C%0A%20%20%7D%2C%0A%20%20tinyLogo%3A%20%7B%0A%20%20%20%20width%3A%2050%2C%0A%20%20%20%20height%3A%2050%2C%0A%20%20%7D%2C%0A%20%20logo%3A%20%7B%0A%20%20%20%20width%3A%2066%2C%0A%20%20%20%20height%3A%2058%2C%0A%20%20%7D%2C%0A%7D)%3B%0A%0Aconst%20DisplayAnImage%20%3D%20()%20%3D%3E%20%7B%0A%20%20return%20(%0A%20%20%20%20%3CView%20style%3D%7Bstyles.container%7D%3E%0A%20%20%20%20%20%20%3CImage%0A%20%20%20%20%20%20%20%20style%3D%7Bstyles.tinyLogo%7D%0A%20%20%20%20%20%20%20%20source%3D%7Brequire('%40expo%2Fsnack-static%2Freact-native-logo.png')%7D%0A%20%20%20%20%20%20%2F%3E%0A%20%20%20%20%20%20%3CImage%0A%20%20%20%20%20%20%20%20style%3D%7Bstyles.tinyLogo%7D%0A%20%20%20%20%20%20%20%20source%3D%7B%7B%0A%20%20%20%20%20%20%20%20%20%20uri%3A%20'https%3A%2F%2Freactnative.dev%2Fimg%2Ftiny_logo.png'%2C%0A%20%20%20%20%20%20%20%20%7D%7D%0A%20%20%20%20%20%20%2F%3E%0A%20%20%20%20%20%20%3CImage%0A%20%20%20%20%20%20%20%20style%3D%7Bstyles.logo%7D%0A%20%20%20%20%20%20%20%20source%3D%7B%7B%0A%20%20%20%20%20%20%20%20%20%20uri%3A%20'data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAADMAAAAzCAYAAAA6oTAqAAAAEXRFWHRTb2Z0d2FyZQBwbmdjcnVzaEB1SfMAAABQSURBVGje7dSxCQBACARB%2B2%2Fab8BEeQNhFi6WSYzYLYudDQYGBgYGBgYGBgYGBgYGBgZmcvDqYGBgmhivGQYGBgYGBgYGBgYGBgYGBgbmQw%2BP%2FeMrC5UTVAAAAABJRU5ErkJggg%3D%3D'%2C%0A%20%20%20%20%20%20%20%20%7D%7D%0A%20%20%20%20%20%20%2F%3E%0A%20%20%20%20%3C%2FView%3E%0A%20%20)%3B%0A%7D%0A%0Aexport%20default%20DisplayAnImage%3B" data-snack-dependencies="" data-snack-platform="web" data-snack-supported-platforms="ios,android,web" data-snack-theme="light" data-snack-preview="true" data-snack-loading="lazy"></div></div><div role="tabpanel" hidden=""><div class="snack-player" data-snack-name="Class Component Example" data-snack-description="Example usage" data-snack-code="%0Aimport%20React%2C%20%7B%20Component%20%7D%20from%20'react'%3B%0Aimport%20%7B%20AppRegistry%2C%20View%2C%20Image%2C%20StyleSheet%20%7D%20from%20'react-native'%3B%0A%0Aconst%20styles%20%3D%20StyleSheet.create(%7B%0A%20%20container%3A%20%7B%0A%20%20%20%20paddingTop%3A%2050%2C%0A%20%20%7D%2C%0A%20%20tinyLogo%3A%20%7B%0A%20%20%20%20width%3A%2050%2C%0A%20%20%20%20height%3A%2050%2C%0A%20%20%7D%2C%0A%20%20logo%3A%20%7B%0A%20%20%20%20width%3A%2066%2C%0A%20%20%20%20height%3A%2058%2C%0A%20%20%7D%2C%0A%7D)%3B%0A%0Aclass%20DisplayAnImage%20extends%20Component%20%7B%0A%20%20render()%20%7B%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%3CView%20style%3D%7Bstyles.container%7D%3E%0A%20%20%20%20%20%20%20%20%3CImage%0A%20%20%20%20%20%20%20%20%20%20style%3D%7Bstyles.tinyLogo%7D%0A%20%20%20%20%20%20%20%20%20%20source%3D%7Brequire('%40expo%2Fsnack-static%2Freact-native-logo.png')%7D%0A%20%20%20%20%20%20%20%20%2F%3E%0A%20%20%20%20%20%20%20%20%3CImage%0A%20%20%20%20%20%20%20%20%20%20style%3D%7Bstyles.tinyLogo%7D%0A%20%20%20%20%20%20%20%20%20%20source%3D%7B%7Buri%3A%20'https%3A%2F%2Freactnative.dev%2Fimg%2Ftiny_logo.png'%7D%7D%0A%20%20%20%20%20%20%20%20%2F%3E%0A%20%20%20%20%20%20%20%20%3CImage%0A%20%20%20%20%20%20%20%20%20%20style%3D%7Bstyles.logo%7D%0A%20%20%20%20%20%20%20%20%20%20source%3D%7B%7Buri%3A%20'data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAADMAAAAzCAYAAAA6oTAqAAAAEXRFWHRTb2Z0d2FyZQBwbmdjcnVzaEB1SfMAAABQSURBVGje7dSxCQBACARB%2B2%2Fab8BEeQNhFi6WSYzYLYudDQYGBgYGBgYGBgYGBgYGBgZmcvDqYGBgmhivGQYGBgYGBgYGBgYGBgYGBgbmQw%2BP%2FeMrC5UTVAAAAABJRU5ErkJggg%3D%3D'%7D%7D%0A%20%20%20%20%20%20%20%20%2F%3E%0A%20%20%20%20%20%20%3C%2FView%3E%0A%20%20%20%20)%3B%0A%20%20%7D%0A%7D%0A%0Aexport%20default%20DisplayAnImage%3B" data-snack-dependencies="" data-snack-platform="web" data-snack-supported-platforms="ios,android,web" data-snack-theme="light" data-snack-preview="true" data-snack-loading="lazy"></div></div></div></div><p>You can also add <code>style</code> to an image:</p><div><ul role="tablist" aria-orientation="horizontal" class="tabs"><li role="tab" tabindex="0" aria-selected="true" class="tabs__item tabItem_2uuE tabs__item--active">Function Component</li><li role="tab" tabindex="0" aria-selected="false" class="tabs__item tabItem_2uuE">Class Component</li></ul><div class="margin-vert--md"><div role="tabpanel"><div class="snack-player" data-snack-name="Function Component Example" data-snack-description="Example usage" data-snack-code="%0Aimport%20React%20from%20'react'%3B%0Aimport%20%7B%20View%2C%20Image%2C%20StyleSheet%20%7D%20from%20'react-native'%3B%0A%0Aconst%20styles%20%3D%20StyleSheet.create(%7B%0A%20%20container%3A%20%7B%0A%20%20%20%20paddingTop%3A%2050%2C%0A%20%20%7D%2C%0A%20%20stretch%3A%20%7B%0A%20%20%20%20width%3A%2050%2C%0A%20%20%20%20height%3A%20200%2C%0A%20%20%20%20resizeMode%3A%20'stretch'%2C%0A%20%20%7D%2C%0A%7D)%3B%0A%0Aconst%20DisplayAnImageWithStyle%20%3D%20()%20%3D%3E%20%7B%0A%20%20return%20(%0A%20%20%20%20%3CView%20style%3D%7Bstyles.container%7D%3E%0A%20%20%20%20%20%20%3CImage%0A%20%20%20%20%20%20%20%20style%3D%7Bstyles.stretch%7D%0A%20%20%20%20%20%20%20%20source%3D%7Brequire('%40expo%2Fsnack-static%2Freact-native-logo.png')%7D%0A%20%20%20%20%20%20%2F%3E%0A%20%20%20%20%3C%2FView%3E%0A%20%20)%3B%0A%7D%0A%0Aexport%20default%20DisplayAnImageWithStyle%3B" data-snack-dependencies="" data-snack-platform="web" data-snack-supported-platforms="ios,android,web" data-snack-theme="light" data-snack-preview="true" data-snack-loading="lazy"></div></div><div role="tabpanel" hidden=""><div class="snack-player" data-snack-name="Class Component Example" data-snack-description="Example usage" data-snack-code="%0Aimport%20React%2C%20%7B%20Component%20%7D%20from%20'react'%3B%0Aimport%20%7B%20View%2C%20Image%2C%20StyleSheet%20%7D%20from%20'react-native'%3B%0A%0Aconst%20styles%20%3D%20StyleSheet.create(%7B%0A%20%20stretch%3A%20%7B%0A%20%20%20%20width%3A%2050%2C%0A%20%20%20%20height%3A%20200%2C%0A%20%20%20%20resizeMode%3A%20'stretch'%0A%20%20%7D%0A%7D)%3B%0A%0Aclass%20DisplayAnImageWithStyle%20extends%20Component%20%7B%0A%20%20render()%20%7B%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%3CView%3E%0A%20%20%20%20%20%20%20%20%3CImage%0A%20%20%20%20%20%20%20%20%20%20style%3D%7Bstyles.stretch%7D%0A%20%20%20%20%20%20%20%20%20%20source%3D%7Brequire('%40expo%2Fsnack-static%2Freact-native-logo.png')%7D%0A%20%20%20%20%20%20%20%20%2F%3E%0A%20%20%20%20%20%20%3C%2FView%3E%0A%20%20%20%20)%3B%0A%20%20%7D%0A%7D%0A%0Aexport%20default%20DisplayAnImageWithStyle%3B" data-snack-dependencies="" data-snack-platform="web" data-snack-supported-platforms="ios,android,web" data-snack-theme="light" data-snack-preview="true" data-snack-loading="lazy"></div></div></div></div><h2><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="gif-and-webp-support-on-android"></a>GIF and WebP support on Android<a class="hash-link" href="#gif-and-webp-support-on-android" title="Direct link to heading">#</a></h2><p>When building your own native code, GIF and WebP are not supported by default on Android.</p><p>You will need to add some optional modules in <code>android/app/build.gradle</code>, depending on the needs of your app.</p><div class="mdxCodeBlock_1daz"><div class="codeBlockContent_2es_"><div tabindex="0" class="prism-code language-groovy codeBlock_27aQ thin-scrollbar"><div class="codeBlockLines_2rCb" style="color:#FFFFFF;background:#282C34"><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token plain">dependencies {</span></div><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token plain"> // If your app supports Android versions before Ice Cream Sandwich (API level 14)</span></div><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token plain"> implementation 'com.facebook.fresco:animated-base-support:1.3.0'</span></div><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token plain" style="display:inline-block">
|
|
</span></div><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token plain"> // For animated GIF support</span></div><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token plain"> implementation 'com.facebook.fresco:animated-gif:2.0.0'</span></div><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token plain" style="display:inline-block">
|
|
</span></div><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token plain"> // For WebP support, including animated WebP</span></div><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token plain"> implementation 'com.facebook.fresco:animated-webp:2.1.0'</span></div><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token plain"> implementation 'com.facebook.fresco:webpsupport:2.0.0'</span></div><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token plain" style="display:inline-block">
|
|
</span></div><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token plain"> // For WebP support, without animations</span></div><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token plain"> implementation 'com.facebook.fresco:webpsupport:2.0.0'</span></div><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token plain">}</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_2bml">Copy</button></div></div><hr><h1><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="reference"></a>Reference<a class="hash-link" href="#reference" title="Direct link to heading">#</a></h1><h2><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="props"></a>Props<a class="hash-link" href="#props" title="Direct link to heading">#</a></h2><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="accessible"></a><code>accessible</code><a class="hash-link" href="#accessible" title="Direct link to heading">#</a></h3><p>When true, indicates the image is an accessibility element.</p><table><thead><tr><th>Type</th><th>Default</th></tr></thead><tbody><tr><td>bool</td><td><code>false</code></td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="accessibilitylabel"></a><code>accessibilityLabel</code><a class="hash-link" href="#accessibilitylabel" title="Direct link to heading">#</a></h3><p>The text that's read by the screen reader when the user interacts with the image.</p><table><thead><tr><th>Type</th></tr></thead><tbody><tr><td>string</td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="blurradius"></a><code>blurRadius</code><a class="hash-link" href="#blurradius" title="Direct link to heading">#</a></h3><p>blurRadius: the blur radius of the blur filter added to the image.</p><table><thead><tr><th>Type</th></tr></thead><tbody><tr><td>number</td></tr></tbody></table><blockquote><p>Tip : IOS you will need to increase <code>blurRadius</code> more than <code>5</code></p></blockquote><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="capinsets-ios"></a><code>capInsets</code> <div class="label ios">iOS</div><a class="hash-link" href="#capinsets-ios" title="Direct link to heading">#</a></h3><p>When the image is resized, the corners of the size specified by <code>capInsets</code> will stay a fixed size, but the center content and borders of the image will be stretched. This is useful for creating resizable rounded buttons, shadows, and other resizable assets. More info in the <a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImage_Class/index.html#//apple_ref/occ/instm/UIImage/resizableImageWithCapInsets" target="_blank" rel="noopener noreferrer">official Apple documentation</a>.</p><table><thead><tr><th>Type</th></tr></thead><tbody><tr><td><a href="/docs/next/rect">Rect</a></td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="defaultsource"></a><code>defaultSource</code><a class="hash-link" href="#defaultsource" title="Direct link to heading">#</a></h3><p>A static image to display while loading the image source.</p><table><thead><tr><th>Type</th></tr></thead><tbody><tr><td><a href="/docs/next/image#imagesource">ImageSource</a></td></tr></tbody></table><blockquote><p><strong>Note:</strong> On Android, the default source prop is ignored on debug builds.</p></blockquote><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="fadeduration-android"></a><code>fadeDuration</code> <div class="label android">Android</div><a class="hash-link" href="#fadeduration-android" title="Direct link to heading">#</a></h3><p>Fade animation duration in miliseconds.</p><table><thead><tr><th>Type</th><th>Default</th></tr></thead><tbody><tr><td>number</td><td><code>300</code></td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="loadingindicatorsource"></a><code>loadingIndicatorSource</code><a class="hash-link" href="#loadingindicatorsource" title="Direct link to heading">#</a></h3><p>Similarly to <code>source</code>, this property represents the resource used to render the loading indicator for the image, displayed until image is ready to be displayed, typically after when it got downloaded from network.</p><table><thead><tr><th>Type</th></tr></thead><tbody><tr><td><a href="/docs/next/image#imagesource">ImageSource</a> (<code>uri</code> only), number</td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="onerror"></a><code>onError</code><a class="hash-link" href="#onerror" title="Direct link to heading">#</a></h3><p>Invoked on load error.</p><table><thead><tr><th>Type</th></tr></thead><tbody><tr><td>function(<code>{ nativeEvent: { error } }</code>) => void</td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="onlayout"></a><code>onLayout</code><a class="hash-link" href="#onlayout" title="Direct link to heading">#</a></h3><p>Invoked on mount and on layout changes.</p><table><thead><tr><th>Type</th></tr></thead><tbody><tr><td>function(<a href="/docs/next/layoutevent">LayoutEvent</a>) => void</td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="onload"></a><code>onLoad</code><a class="hash-link" href="#onload" title="Direct link to heading">#</a></h3><p>Invoked when load completes successfully.</p><table><thead><tr><th>Type</th></tr></thead><tbody><tr><td>function(<a href="/docs/next/image#imageloadevent">ImageLoadEvent</a>) => void</td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="onloadend"></a><code>onLoadEnd</code><a class="hash-link" href="#onloadend" title="Direct link to heading">#</a></h3><p>Invoked when load either succeeds or fails.</p><table><thead><tr><th>Type</th></tr></thead><tbody><tr><td>function() => void</td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="onloadstart"></a><code>onLoadStart</code><a class="hash-link" href="#onloadstart" title="Direct link to heading">#</a></h3><p>Invoked on load start.</p><p><strong>Example:</strong> <code>onLoadStart={() => this.setState({loading: true})}</code></p><table><thead><tr><th>Type</th></tr></thead><tbody><tr><td>function() => void</td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="onpartialload-ios"></a><code>onPartialLoad</code> <div class="label ios">iOS</div><a class="hash-link" href="#onpartialload-ios" title="Direct link to heading">#</a></h3><p>Invoked when a partial load of the image is complete. The definition of what constitutes a "partial load" is loader specific though this is meant for progressive JPEG loads.</p><table><thead><tr><th>Type</th></tr></thead><tbody><tr><td>function() => void</td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="onprogress"></a><code>onProgress</code><a class="hash-link" href="#onprogress" title="Direct link to heading">#</a></h3><p>Invoked on download progress.</p><table><thead><tr><th>Type</th></tr></thead><tbody><tr><td>function(<code>{ nativeEvent: { loaded, total } }</code>) => void</td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="progressiverenderingenabled-android"></a><code>progressiveRenderingEnabled</code> <div class="label android">Android</div><a class="hash-link" href="#progressiverenderingenabled-android" title="Direct link to heading">#</a></h3><p>When <code>true</code>, enables progressive jpeg streaming - <a href="https://frescolib.org/docs/progressive-jpegs" target="_blank" rel="noopener noreferrer">https://frescolib.org/docs/progressive-jpegs</a>.</p><table><thead><tr><th>Type</th><th>Default</th></tr></thead><tbody><tr><td>bool</td><td><code>false</code></td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="resizemethod-android"></a><code>resizeMethod</code> <div class="label android">Android</div><a class="hash-link" href="#resizemethod-android" title="Direct link to heading">#</a></h3><p>The mechanism that should be used to resize the image when the image's dimensions differ from the image view's dimensions. Defaults to <code>auto</code>.</p><ul><li><p><code>auto</code>: Use heuristics to pick between <code>resize</code> and <code>scale</code>.</p></li><li><p><code>resize</code>: A software operation which changes the encoded image in memory before it gets decoded. This should be used instead of <code>scale</code> when the image is much larger than the view.</p></li><li><p><code>scale</code>: The image gets drawn downscaled or upscaled. Compared to <code>resize</code>, <code>scale</code> is faster (usually hardware accelerated) and produces higher quality images. This should be used if the image is smaller than the view. It should also be used if the image is slightly bigger than the view.</p></li></ul><p>More details about <code>resize</code> and <code>scale</code> can be found at <a href="http://frescolib.org/docs/resizing" target="_blank" rel="noopener noreferrer">http://frescolib.org/docs/resizing</a>.</p><table><thead><tr><th>Type</th><th>Default</th></tr></thead><tbody><tr><td>enum(<code>'auto'</code>, <code>'resize'</code>, <code>'scale'</code>)</td><td><code>'auto'</code></td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="resizemode"></a><code>resizeMode</code><a class="hash-link" href="#resizemode" title="Direct link to heading">#</a></h3><p>Determines how to resize the image when the frame doesn't match the raw image dimensions. Defaults to <code>cover</code>.</p><ul><li><p><code>cover</code>: Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view (minus padding).</p></li><li><p><code>contain</code>: Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or less than the corresponding dimension of the view (minus padding).</p></li><li><p><code>stretch</code>: Scale width and height independently, This may change the aspect ratio of the src.</p></li><li><p><code>repeat</code>: Repeat the image to cover the frame of the view. The image will keep its size and aspect ratio, unless it is larger than the view, in which case it will be scaled down uniformly so that it is contained in the view.</p></li><li><p><code>center</code>: Center the image in the view along both dimensions. If the image is larger than the view, scale it down uniformly so that it is contained in the view.</p></li></ul><table><thead><tr><th>Type</th><th>Default</th></tr></thead><tbody><tr><td>enum(<code>'cover'</code>, <code>'contain'</code>, <code>'stretch'</code>, <code>'repeat'</code>, <code>'center'</code>)</td><td><code>'cover'</code></td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="source"></a><code>source</code><a class="hash-link" href="#source" title="Direct link to heading">#</a></h3><p>The image source (either a remote URL or a local file resource).</p><p>This prop can also contain several remote URLs, specified together with their width and height and potentially with scale/other URI arguments. The native side will then choose the best <code>uri</code> to display based on the measured size of the image container. A <code>cache</code> property can be added to control how networked request interacts with the local cache. (For more information see <a href="/docs/next/images#cache-control-ios-only">Cache Control for Images</a>).</p><p>The currently supported formats are <code>png</code>, <code>jpg</code>, <code>jpeg</code>, <code>bmp</code>, <code>gif</code>, <code>webp</code>, <code>psd</code> (iOS only). In addition, iOS supports several RAW image formats. Refer to Apple's documentation for the current list of supported camera models (for iOS 12, see <a href="https://support.apple.com/en-ca/HT208967" target="_blank" rel="noopener noreferrer">https://support.apple.com/en-ca/HT208967</a>).</p><table><thead><tr><th>Type</th></tr></thead><tbody><tr><td><a href="/docs/next/image#imagesource">ImageSource</a></td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="style"></a><code>style</code><a class="hash-link" href="#style" title="Direct link to heading">#</a></h3><table><thead><tr><th>Type</th></tr></thead><tbody><tr><td><a href="/docs/next/image-style-props#props">Image Style Props</a>, <a href="/docs/next/layout-props#props">Layout Props</a>, <a href="/docs/next/shadow-props#props">Shadow Props</a>, <a href="/docs/next/transforms#props">Transforms</a></td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="testid"></a><code>testID</code><a class="hash-link" href="#testid" title="Direct link to heading">#</a></h3><p>A unique identifier for this element to be used in UI Automation testing scripts.</p><table><thead><tr><th>Type</th></tr></thead><tbody><tr><td>string</td></tr></tbody></table><h2><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="methods"></a>Methods<a class="hash-link" href="#methods" title="Direct link to heading">#</a></h2><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="abortprefetch-android"></a><code>abortPrefetch()</code> <div class="label android">Android</div><a class="hash-link" href="#abortprefetch-android" title="Direct link to heading">#</a></h3><div class="mdxCodeBlock_1daz"><div class="codeBlockContent_2es_"><div tabindex="0" class="prism-code language-jsx codeBlock_27aQ thin-scrollbar"><div class="codeBlockLines_2rCb" style="color:#FFFFFF;background:#282C34"><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token plain">Image</span><span class="token punctuation" style="color:#657b83">.</span><span class="token function" style="color:#79b6f2">abortPrefetch</span><span class="token punctuation" style="color:#657b83">(</span><span class="token plain">requestId</span><span class="token punctuation" style="color:#657b83">)</span><span class="token punctuation" style="color:#657b83">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_2bml">Copy</button></div></div><p>Abort prefetch request.</p><p><strong>Parameters:</strong></p><table><thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>requestId <div class="label basic required">Required</div></td><td>number</td><td>Request id as returned by <code>prefetch()</code>.</td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="getsize"></a><code>getSize()</code><a class="hash-link" href="#getsize" title="Direct link to heading">#</a></h3><div class="mdxCodeBlock_1daz"><div class="codeBlockContent_2es_"><div tabindex="0" class="prism-code language-jsx codeBlock_27aQ thin-scrollbar"><div class="codeBlockLines_2rCb" style="color:#FFFFFF;background:#282C34"><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token plain">Image</span><span class="token punctuation" style="color:#657b83">.</span><span class="token function" style="color:#79b6f2">getSize</span><span class="token punctuation" style="color:#657b83">(</span><span class="token plain">uri</span><span class="token punctuation" style="color:#657b83">,</span><span class="token plain"> success</span><span class="token punctuation" style="color:#657b83">,</span><span class="token plain"> </span><span class="token punctuation" style="color:#657b83">[</span><span class="token plain">failure</span><span class="token punctuation" style="color:#657b83">]</span><span class="token punctuation" style="color:#657b83">)</span><span class="token punctuation" style="color:#657b83">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_2bml">Copy</button></div></div><p>Retrieve the width and height (in pixels) of an image prior to displaying it. This method can fail if the image cannot be found, or fails to download.</p><p>In order to retrieve the image dimensions, the image may first need to be loaded or downloaded, after which it will be cached. This means that in principle you could use this method to preload images, however it is not optimized for that purpose, and may in future be implemented in a way that does not fully load/download the image data. A proper, supported way to preload images will be provided as a separate API.</p><p><strong>Parameters:</strong></p><table><thead><tr><th><div class="wideColumn">Name</div></th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>uri <div class="label basic required">Required</div></td><td>string</td><td>The location of the image.</td></tr><tr><td>success <div class="label basic required">Required</div></td><td>function</td><td>The function that will be called if the image was successfully found and width and height retrieved.</td></tr><tr><td>failure</td><td>function</td><td>The function that will be called if there was an error, such as failing to retrieve the image.</td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="getsizewithheaders"></a><code>getSizeWithHeaders()</code><a class="hash-link" href="#getsizewithheaders" title="Direct link to heading">#</a></h3><div class="mdxCodeBlock_1daz"><div class="codeBlockContent_2es_"><div tabindex="0" class="prism-code language-jsx codeBlock_27aQ thin-scrollbar"><div class="codeBlockLines_2rCb" style="color:#FFFFFF;background:#282C34"><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token plain">Image</span><span class="token punctuation" style="color:#657b83">.</span><span class="token function" style="color:#79b6f2">getSizeWithHeaders</span><span class="token punctuation" style="color:#657b83">(</span><span class="token plain">uri</span><span class="token punctuation" style="color:#657b83">,</span><span class="token plain"> headers</span><span class="token punctuation" style="color:#657b83">,</span><span class="token plain"> success</span><span class="token punctuation" style="color:#657b83">,</span><span class="token plain"> </span><span class="token punctuation" style="color:#657b83">[</span><span class="token plain">failure</span><span class="token punctuation" style="color:#657b83">]</span><span class="token punctuation" style="color:#657b83">)</span><span class="token punctuation" style="color:#657b83">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_2bml">Copy</button></div></div><p>Retrieve the width and height (in pixels) of an image prior to displaying it with the ability to provide the headers for the request. This method can fail if the image cannot be found, or fails to download. It also does not work for static image resources.</p><p>In order to retrieve the image dimensions, the image may first need to be loaded or downloaded, after which it will be cached. This means that in principle you could use this method to preload images, however it is not optimized for that purpose, and may in future be implemented in a way that does not fully load/download the image data. A proper, supported way to preload images will be provided as a separate API.</p><p><strong>Parameters:</strong></p><table><thead><tr><th><div class="wideColumn">Name</div></th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>uri <div class="label basic required">Required</div></td><td>string</td><td>The location of the image.</td></tr><tr><td>headers <div class="label basic required">Required</div></td><td>object</td><td>The headers for the request.</td></tr><tr><td>success <div class="label basic required">Required</div></td><td>function</td><td>The function that will be called if the image was successfully found and width and height retrieved.</td></tr><tr><td>failure</td><td>function</td><td>The function that will be called if there was an error, such as failing to retrieve the image.</td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="prefetch"></a><code>prefetch()</code><a class="hash-link" href="#prefetch" title="Direct link to heading">#</a></h3><div class="mdxCodeBlock_1daz"><div class="codeBlockContent_2es_"><div tabindex="0" class="prism-code language-jsx codeBlock_27aQ thin-scrollbar"><div class="codeBlockLines_2rCb" style="color:#FFFFFF;background:#282C34"><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token keyword" style="color:#c5a5c5">await</span><span class="token plain"> Image</span><span class="token punctuation" style="color:#657b83">.</span><span class="token function" style="color:#79b6f2">prefetch</span><span class="token punctuation" style="color:#657b83">(</span><span class="token plain">url</span><span class="token punctuation" style="color:#657b83">)</span><span class="token punctuation" style="color:#657b83">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_2bml">Copy</button></div></div><p>Prefetches a remote image for later use by downloading it to the disk cache. Returns a promise which resolves to a boolean.</p><p><strong>Parameters:</strong></p><table><thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>url <div class="label basic required">Required</div></td><td>string</td><td>The remote location of the image.</td></tr><tr><td>callback</td><td>function <div class="label android">Android</div></td><td>The function that will be called with the <code>requestId</code>.</td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="querycache"></a><code>queryCache()</code><a class="hash-link" href="#querycache" title="Direct link to heading">#</a></h3><div class="mdxCodeBlock_1daz"><div class="codeBlockContent_2es_"><div tabindex="0" class="prism-code language-jsx codeBlock_27aQ thin-scrollbar"><div class="codeBlockLines_2rCb" style="color:#FFFFFF;background:#282C34"><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token keyword" style="color:#c5a5c5">await</span><span class="token plain"> Image</span><span class="token punctuation" style="color:#657b83">.</span><span class="token function" style="color:#79b6f2">queryCache</span><span class="token punctuation" style="color:#657b83">(</span><span class="token plain">urls</span><span class="token punctuation" style="color:#657b83">)</span><span class="token punctuation" style="color:#657b83">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_2bml">Copy</button></div></div><p>Perform cache interrogation. Returns a promise which resolves to a mapping from URL to cache status, such as "disk", "memory" or "disk/memory". If a requested URL is not in the mapping, it means it's not in the cache.</p><p><strong>Parameters:</strong></p><table><thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>urls <div class="label basic required">Required</div></td><td>array</td><td>List of image URLs to check the cache for.</td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="resolveassetsource"></a><code>resolveAssetSource()</code><a class="hash-link" href="#resolveassetsource" title="Direct link to heading">#</a></h3><div class="mdxCodeBlock_1daz"><div class="codeBlockContent_2es_"><div tabindex="0" class="prism-code language-jsx codeBlock_27aQ thin-scrollbar"><div class="codeBlockLines_2rCb" style="color:#FFFFFF;background:#282C34"><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token plain">Image</span><span class="token punctuation" style="color:#657b83">.</span><span class="token function" style="color:#79b6f2">resolveAssetSource</span><span class="token punctuation" style="color:#657b83">(</span><span class="token plain">source</span><span class="token punctuation" style="color:#657b83">)</span><span class="token punctuation" style="color:#657b83">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_2bml">Copy</button></div></div><p>Resolves an asset reference into an object which has the properties <code>uri</code>, <code>width</code>, and <code>height</code>.</p><p><strong>Parameters:</strong></p><table><thead><tr><th><div class="wideColumn">Name</div></th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>source <div class="label basic required">Required</div></td><td><a href="/docs/next/image#imagesource">ImageSource</a>, number</td><td>A number (opaque type returned by <code>require('./foo.png')</code>) or an ImageSource.</td></tr></tbody></table><h2><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="type-definitions"></a>Type Definitions<a class="hash-link" href="#type-definitions" title="Direct link to heading">#</a></h2><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="imagecacheenum-ios"></a>ImageCacheEnum <div class="label ios">iOS</div><a class="hash-link" href="#imagecacheenum-ios" title="Direct link to heading">#</a></h3><p>Enum which can be used to set the cache handling or stategy for the potentially cached responses.</p><table><thead><tr><th>Type</th><th>Default</th></tr></thead><tbody><tr><td>enum(<code>'default'</code>, <code>'reload'</code>, <code>'force-cache'</code>, <code>'only-if-cached'</code>)</td><td><code>'default'</code></td></tr></tbody></table><ul><li><code>default</code>: Use the native platforms default strategy.</li><li><code>reload</code>: The data for the URL will be loaded from the originating source. No existing cache data should be used to satisfy a URL load request.</li><li><code>force-cache</code>: The existing cached data will be used to satisfy the request, regardless of its age or expiration date. If there is no existing data in the cache corresponding the request, the data is loaded from the originating source.</li><li><code>only-if-cached</code>: The existing cache data will be used to satisfy a request, regardless of its age or expiration date. If there is no existing data in the cache corresponding to a URL load request, no attempt is made to load the data from the originating source, and the load is considered to have failed.</li></ul><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="imageloadevent"></a>ImageLoadEvent<a class="hash-link" href="#imageloadevent" title="Direct link to heading">#</a></h3><p>Object returned in the <code>onLoad</code> callback.</p><table><thead><tr><th>Type</th></tr></thead><tbody><tr><td>object</td></tr></tbody></table><p><strong>Properties:</strong></p><table><thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>width</td><td>number</td><td>The width of loaded image.</td></tr><tr><td>height</td><td>number</td><td>The height of loaded image.</td></tr><tr><td>uri</td><td>string</td><td>A string representing the resource identifier for the image.</td></tr></tbody></table><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="imagesource"></a>ImageSource<a class="hash-link" href="#imagesource" title="Direct link to heading">#</a></h3><table><thead><tr><th>Type</th></tr></thead><tbody><tr><td>object, array of objects, number</td></tr></tbody></table><p><strong>Properties (if passing as object or array of objects):</strong></p><table><thead><tr><th><div class="wideColumn">Name</div></th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>uri</td><td>string</td><td>A string representing the resource identifier for the image, which could be an http address, a local file path, or the name of a static image resource.</td></tr><tr><td>width</td><td>number</td><td>Can be specified if known at build time, in which case the value will be used to set the default <code><Image/></code> component dimension.</td></tr><tr><td>height</td><td>number</td><td>Can be specified if known at build time, in which case the value will be used to set the default <code><Image/></code> component dimension.</td></tr><tr><td>scale</td><td>number</td><td>Used to indicate the scale factor of the image. Defaults to <code>1.0</code> if unspecified, meaning that one image pixel equates to one display point / DIP.</td></tr><tr><td>bundle<div class="label ios">iOS</div></td><td>string</td><td>The iOS asset bundle which the image is included in. This will default to <code>[NSBundle mainBundle]</code> if not set.</td></tr><tr><td>method</td><td>string</td><td>The HTTP Method to use. Defaults to <code>'GET'</code> if not specified.</td></tr><tr><td>headers</td><td>object</td><td>An object representing the HTTP headers to send along with the request for a remote image.</td></tr><tr><td>body</td><td>string</td><td>The HTTP body to send with the request. This must be a valid UTF-8 string, and will be sent exactly as specified, with no additional encoding (e.g. URL-escaping or base64) applied.</td></tr><tr><td>cache<div class="label ios">iOS</div></td><td><a href="/docs/next/image#imagecacheenum-ios">ImageCacheEnum</a></td><td>Determines how the requests handles potentially cached responses.</td></tr></tbody></table><p><strong>If passing a number:</strong></p><ul><li><code>number</code> - opaque type returned by something like <code>require('./image.jpg')</code>.</li></ul></div></article><div class="docMetadata margin-vert--xl"><div class="row"><div class="col"><a href="https://github.com/facebook/react-native-website/blob/master/website/../docs/image.md" target="_blank" rel="noreferrer noopener"><svg fill="currentColor" height="1.2em" width="1.2em" preserveAspectRatio="xMidYMid meet" role="img" viewBox="0 0 40 40" class="iconEdit_2Hwv"><g><path d="m34.5 11.7l-3 3.1-6.3-6.3 3.1-3q0.5-0.5 1.2-0.5t1.1 0.5l3.9 3.9q0.5 0.4 0.5 1.1t-0.5 1.2z m-29.5 17.1l18.4-18.5 6.3 6.3-18.4 18.4h-6.3v-6.2z"></path></g></svg>Edit this page</a></div><div class="col text--right"><em><small class="docMetadata-updated">Last updated on <time datetime="2021-01-08T11:07:09.000Z" class="docLastUpdatedAt_1gIo">1/8/2021</time></small></em></div></div></div><div class="margin-vert--lg"><nav class="pagination-nav" aria-label="Blog list page navigation"><div class="pagination-nav__item"><a class="pagination-nav__link" href="/docs/next/flatlist"><div class="pagination-nav__sublabel">Previous</div><div class="pagination-nav__label">« FlatList</div></a></div><div class="pagination-nav__item pagination-nav__item--next"><a class="pagination-nav__link" href="/docs/next/imagebackground"><div class="pagination-nav__sublabel">Next</div><div class="pagination-nav__label">ImageBackground »</div></a></div></nav></div></div></div><div class="col col--3"><div class="tableOfContents_1zTD thin-scrollbar"><ul class="table-of-contents table-of-contents__left-border"><li><a href="#examples" class="table-of-contents__link">Examples</a></li><li><a href="#gif-and-webp-support-on-android" class="table-of-contents__link">GIF and WebP support on Android</a></li><li><a href="#props" class="table-of-contents__link">Props</a><ul><li><a href="#accessible" class="table-of-contents__link"><code>accessible</code></a></li><li><a href="#accessibilitylabel" class="table-of-contents__link"><code>accessibilityLabel</code></a></li><li><a href="#blurradius" class="table-of-contents__link"><code>blurRadius</code></a></li><li><a href="#capinsets-ios" class="table-of-contents__link"><code>capInsets</code> <div class="label ios">iOS</div></a></li><li><a href="#defaultsource" class="table-of-contents__link"><code>defaultSource</code></a></li><li><a href="#fadeduration-android" class="table-of-contents__link"><code>fadeDuration</code> <div class="label android">Android</div></a></li><li><a href="#loadingindicatorsource" class="table-of-contents__link"><code>loadingIndicatorSource</code></a></li><li><a href="#onerror" class="table-of-contents__link"><code>onError</code></a></li><li><a href="#onlayout" class="table-of-contents__link"><code>onLayout</code></a></li><li><a href="#onload" class="table-of-contents__link"><code>onLoad</code></a></li><li><a href="#onloadend" class="table-of-contents__link"><code>onLoadEnd</code></a></li><li><a href="#onloadstart" class="table-of-contents__link"><code>onLoadStart</code></a></li><li><a href="#onpartialload-ios" class="table-of-contents__link"><code>onPartialLoad</code> <div class="label ios">iOS</div></a></li><li><a href="#onprogress" class="table-of-contents__link"><code>onProgress</code></a></li><li><a href="#progressiverenderingenabled-android" class="table-of-contents__link"><code>progressiveRenderingEnabled</code> <div class="label android">Android</div></a></li><li><a href="#resizemethod-android" class="table-of-contents__link"><code>resizeMethod</code> <div class="label android">Android</div></a></li><li><a href="#resizemode" class="table-of-contents__link"><code>resizeMode</code></a></li><li><a href="#source" class="table-of-contents__link"><code>source</code></a></li><li><a href="#style" class="table-of-contents__link"><code>style</code></a></li><li><a href="#testid" class="table-of-contents__link"><code>testID</code></a></li></ul></li><li><a href="#methods" class="table-of-contents__link">Methods</a><ul><li><a href="#abortprefetch-android" class="table-of-contents__link"><code>abortPrefetch()</code> <div class="label android">Android</div></a></li><li><a href="#getsize" class="table-of-contents__link"><code>getSize()</code></a></li><li><a href="#getsizewithheaders" class="table-of-contents__link"><code>getSizeWithHeaders()</code></a></li><li><a href="#prefetch" class="table-of-contents__link"><code>prefetch()</code></a></li><li><a href="#querycache" class="table-of-contents__link"><code>queryCache()</code></a></li><li><a href="#resolveassetsource" class="table-of-contents__link"><code>resolveAssetSource()</code></a></li></ul></li><li><a href="#type-definitions" class="table-of-contents__link">Type Definitions</a><ul><li><a href="#imagecacheenum-ios" class="table-of-contents__link">ImageCacheEnum <div class="label ios">iOS</div></a></li><li><a href="#imageloadevent" class="table-of-contents__link">ImageLoadEvent</a></li><li><a href="#imagesource" class="table-of-contents__link">ImageSource</a></li></ul></li></ul></div></div></div></div></main></div></div><footer class="footer footer--dark"><div class="container"><div class="row footer__links"><div class="col footer__col"><h4 class="footer__title">Docs</h4><ul class="footer__items"><li class="footer__item"><a class="footer__link-item" href="/docs/getting-started">Getting Started</a></li><li class="footer__item"><a class="footer__link-item" href="/docs/tutorial">Tutorial</a></li><li class="footer__item"><a class="footer__link-item" href="/docs/components-and-apis">Components and APIs</a></li><li class="footer__item"><a class="footer__link-item" href="/docs/more-resources">More Resources</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">Community</h4><ul class="footer__items"><li class="footer__item"><a class="footer__link-item" href="/help">The React Native Community</a></li><li class="footer__item"><a class="footer__link-item" href="/showcase">Who's using React Native?</a></li><li class="footer__item"><a href="https://stackoverflow.com/questions/tagged/react-native" target="_blank" rel="noopener noreferrer" class="footer__link-item">Ask Questions on Stack Overflow</a></li><li class="footer__item"><a href="https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md" target="_blank" rel="noopener noreferrer" class="footer__link-item">Contributor Guide</a></li><li class="footer__item"><a href="https://dev.to/t/reactnative" target="_blank" rel="noopener noreferrer" class="footer__link-item">DEV Community</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">Find us</h4><ul class="footer__items"><li class="footer__item"><a class="footer__link-item" href="/blog">Blog</a></li><li class="footer__item"><a href="https://twitter.com/reactnative" target="_blank" rel="noopener noreferrer" class="footer__link-item">Twitter</a></li><li class="footer__item"><a href="https://github.com/facebook/react-native" target="_blank" rel="noopener noreferrer" class="footer__link-item">GitHub</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">More</h4><ul class="footer__items"><li class="footer__item"><a href="https://reactjs.org/" target="_blank" rel="noopener noreferrer" class="footer__link-item">React</a></li><li class="footer__item"><a href="https://opensource.facebook.com/legal/privacy" target="_blank" rel="noopener noreferrer" class="footer__link-item">Privacy Policy</a></li><li class="footer__item"><a href="https://opensource.facebook.com/legal/terms" target="_blank" rel="noopener noreferrer" class="footer__link-item">Terms of Service</a></li></ul></div></div><div class="footer__bottom text--center"><div class="margin-bottom--sm"><a href="https://opensource.facebook.com" target="_blank" rel="noopener noreferrer" class="footerLogoLink_3cAK"><img class="footer__logo" alt="Facebook Open Source Logo" src="/img/oss_logo.png"></a></div><div class="footer__copyright">Copyright © 2021 Facebook, Inc.</div></div></div></footer></div>
|
|
<script src="/styles.1b71bc8a.js"></script>
|
|
<script src="/runtime~main.c97aa552.js"></script>
|
|
<script src="/main.253479d9.js"></script>
|
|
<script src="/1.4dffec5b.js"></script>
|
|
<script src="/2.8fcdf5b9.js"></script>
|
|
<script src="/939.c1f14adb.js"></script>
|
|
<script src="/935f2afb.63ef0aae.js"></script>
|
|
<script src="/17896441.81f68a15.js"></script>
|
|
<script src="/4261946e.aa2b8ad3.js"></script>
|
|
</body>
|
|
</html> |