Display Local and Remote Images in React Native (2024)

Instructor: [00:00] Let's name a new folder in Source called Images and a new package.json file in the images folder. Specify a name of images, which will allow us to use an absolute import path to import images from this folder.

[00:19] Into that folder, we'll paste the images of a pizza slice at 1X, 2X, and 3X resolution. Note that the naming is important here. All three files should have the exact same basename, and the 2X and 3X files are differentiated with @2X and @3X before the file extension.

[00:41] Then in app.js, we can import that image like any other component, except that we must ensure to add the file extension. Even though the @2X or @3X isn't included in that import statement, React Native will automatically detect the proper file to use for the current device.

[01:00] We can't use that image directly. First, we have to impact the image component from React Native. Then in the render method, we'll use the image component and set the source prop to the pizza image that we imported. We can add a wrapping view for a bit of styling. When we load now, we have that image, which will be included in the app bundle and displayed automatically at the proper resolution for the current device.

[01:28] To look at remote images, that is, images that aren't in our bundle and that we'll have to download from a server, let's switch to restaurantRow.js and log the values of the places coming from the server. For every place, the server is also sending an image name. We can get those images from the server.

[01:49] Let's import image into restaurantRow.js and use image in the info component of the row. We're going to set the source prop like before, but with remote images, we have to supply an object to that prop and include a URI key. That URI is where we can get the image, just like with an image tag on the Web.

[02:13] Remember that in the in iOS simulator using localhost is OK, but that won't work on the Android emulator. Use your computer's local network IP address instead.

[02:25] If we reload the app now, nothing is showing up where we would expect the image to be. That's because it's important in React Native to specify the image dimensions for remote images, at least to specify what dimensions you'd like the image to be on screen.

[02:42] We can go back to image and in the same object where you specify the URI, you can also specify a height and a width. Then when we reload, we can see the image.

[02:55] We could also specify the height and width as a style prop instead of in the source prop, but if we specify the wrong aspect ratio, say we try to make the image wider than it is tall for this square image, React Native will automatically fill the width and height and clip the image that doesn't fit.

[03:14] You can keep that setting or specify a different one by specifying the resize mode prop on the image component. For example, we could stretch the image, which will deform the image -- probably not what we want to do in this case -- or we can set the resize mode to contain, which ensures the entire image will be displayed within the width and the height, which is probably what we want for this image.

[03:39] If we don't know wide the image is, but we want it to fill the space, we can also set flex 1 on an image instead of a width. The image will flex just like a view does, but still obey the resize mode to prop that we give it.

Display Local and Remote Images in React Native (2024)
Top Articles
How to Make Money from Home with 10 Google Online Jobs
How to Improve Your Credit Score Before a Divorce and Why It’s Important - Divorce Financial Solutions
Myusu Canvas
Patelco New Car Loan Rates
Herbalism Guide Tbc
Examples of "Crocodile" in a Sentence
Www.nerdballertv
Washington Food Handlers Card Test Answers
Covers Nfl.forum
Edgenuity Spanish 1 Semester 1 Final Exam Answers
10-Day Weather Forecast for Nockamixon Township, PA - The Weather Channel | weather.com
Stocktwits Cycc
Margie's Money Saver Hey Dudes
1 P.m. Pdt
Wilmington Pets Craigslist
Genesis 1 Mission Loot Table
Seo Glossary definition page
Trib Live High School Sports Network
Flake - RimWorld Wiki
The 36 best Chicago attractions
Dogs Craiglist
Profile By Sanford Recipes
Nipr To Sipr File Transfer Dots
Minecraft Jar Google Drive
Oreilleys Auto Near Me
Craigslist Furniture Bedroom Set
1980 Monte Carlo For Sale Craigslist
Amwednesday Full Video
24 Hour Drive Thru Car Wash Near Me
Steelweb Usw
Quiktrip Maple And West
Vystar Cars For Sale
714-603-0170
Strange World Showtimes Near Blackstone Valley 14 Cinema De Lux
Craigslist Rome Ny
Hyundai Scottsdale
ما ملكت أيمانكم (مسلسل) - المعرفة
German Shepherd puppies for sale | Pets4Homes
My Juno Personal Start Page
Oakley Rae Net Worth – Real Name, Wiki, Husband, Age, Height
Power Outage Map Albany Ny
Restored Republic December 9 2022
3rd Age Felling Axe / Third Age Felling Axe [High Level Delivery!... | ID 217153061 | PlayerAuctions
Speechwire Login
Lohud Obits Rockland County
The Fabelmans Showtimes Near Amc Regency 24
Chicago Craigslist Classifieds
Tucker Gott Jaclyn Weiss
R/Mcoc
Harper and Finley Lockwood Biography, Age, Height, Husband, Net Worth, Family
Do sprzedania Zenith Captain Power Reserve Elite za cene 11 124 zł od Seller na Chrono24
Tiraj Florida 1H30
Latest Posts
Article information

Author: Pres. Lawanda Wiegand

Last Updated:

Views: 6322

Rating: 4 / 5 (51 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Pres. Lawanda Wiegand

Birthday: 1993-01-10

Address: Suite 391 6963 Ullrich Shore, Bellefort, WI 01350-7893

Phone: +6806610432415

Job: Dynamic Manufacturing Assistant

Hobby: amateur radio, Taekwondo, Wood carving, Parkour, Skateboarding, Running, Rafting

Introduction: My name is Pres. Lawanda Wiegand, I am a inquisitive, helpful, glamorous, cheerful, open, clever, innocent person who loves writing and wants to share my knowledge and understanding with you.