In my RN application, I use react-native-pdf. I want to show a file which is in the file system of the app. But when I set the source it doesn't work and the app can't identify the path. How can I set the path properly?
<Pdf
source={{ uri:'file:///terms.pdf'
/>
It should be below. when I tried that, it worked. And there is no bug about that on the repository of react-native-pdf. Maybe your version of react-native-pdf has bug. You should get this version => 5.1.6.
<Pdf
source={uri:"file:///absolute/path/to/terms.pdf"}
/>
Related
When I add some image from my assets folder using require, the image is apparently being taken from a folder .png-cache , but react native probably has bad paths stored in them because I get an error wherever I've used the same file as the image source.
My code is:
<Image
source={require('#assets/images/thunder.svg')}
height={20}
width={20}
resizeMode={'contain'}
style={styles.actionButtonIconStyle}
/>
The image doesn't show up and the console shows:
Error: Asset not found: C:\Users\<project path>\src\assets\images\.png-cache\thunder-31748fee8334daf886e2bea1259f80c9#3x.png for platform: android
at getAbsoluteAssetRecord (C:\Users\<project path>\node_modules\metro\src\Assets.js:110:11)
at async getAsset (C:\Users\<project path>\node_modules\metro\src\Assets.js:238:18)
at async Server._processSingleAssetRequest (C:\Users\<project path>\node_modules\metro\src\Server.js:352:20)
at async Server._processRequest (C:\Users\<project path>\node_modules\metro\src\Server.js:427:7)
Not sure why the current paths are not valid. Is it possible to make it so that the old cached paths are forgotten and new cache file generated?
What I've tried:
I renamed one image file and it worked but I wouldn't want to rename all the files, looking for a way to reset the cache.
I looked at the solution in Reset internal android image cache in React Native but I can't have dynamic paths in require so this solution didn't work.
I see first time using like #asset...
In my code i everytime use like this:
<Image
source={require('../assets/images/thunder.svg')}
height={20}
width={20}
resizeMode={'contain'}
style={styles.actionButtonIconStyle}
/>
am i missunderstanding what you need?
My problem was solved by resetting the react native cache with the command:
npm start -- --reset-cache
I am building an IOS application using ReactNative. My app needs to display image from the local file system or gallery or the ones captured by the camera. But it is not working. I am displaying something like this.
<FastImage
style={[imageStyle.image]}
source={{ uri: source }}
/>
This is the library I am using, https://github.com/DylanVann/react-native-fast-image. The source value is something like this.
As you can see, it is not displaying the image. What is wrong with my code and how can I fix it?
I also tried prepending "file://" to the path as well. It did not work either.
If you are using a local file. The source prop should have a file path instead of a uri. Let’s say your image is located at ./Images/myImage.png. Try this:
source={require("./Images/myImage.png")}
const directoryPath = Platform.OS === 'android' ? RNFS.PicturesDirectoryPath : RNFS.DocumentDirectoryPath;
<FastImage
style={YOUR_IMAGE_STYLE}
source={{uri: `file://${directoryPath}/${YOUR_IMAGE_FILE_NAME}`}}
/>
PS: on Android, must use file://
PS: Need enable fs permission, ref to ENOENT: open failed: EACCES (Permission denied), open '/storage/emulated/0/Download/ on Android, and IOS file downloaded not able to be located on device on iOS.
I'm trying to show image placeholder before the actual image loaded from the server.
For iOS, defaultSource prop is working fine but for android the image is not getting displayed.
<Image style={dashBoardStyles.buildingImage} source={{ uri: 'some server image' }} defaultSource={ require('../images/loadingindicatorImage.png')}>
Can anyone help regarding this issue.
Please read https://reactnative.dev/docs/image#defaultsource carefully, and you'll find below note.
Note: On Android, the default source prop is ignored on debug builds.
I'm having an issue with adding static images to my project. I added a resource folder with images inside, restarted the packager and get the following error:
error: bundling failed:
Error: Unable to resolve module `../../assets/img/receiptIcon.PNG` from
`C:\Users\Keith\Desktop\Phase1\Screens\Receipts\ReceiptRow.js`:
The module `../../assets/img/receiptIcon.PNG` could not be found from
`C:\Users\Keith\Desktop\Phase1\Screens\Receipts\ReceiptRow.js`. Indeed, none of
these files exist:`C:\Users\Keith\Desktop\Phase1\assets\img\receiptIcon.PNG(.native||.android.js|.native.js|.js|.android.json|.native.json|.json)`
`C:\Users\Keith\Desktop\Phase1\assets\img\receiptIcon.PNG\index(.native||.android.js|.native.js|.js|.android.json|.native.json|.json)`
Copying the path below into File Explorer opens the image as expected. I've made sure there are no special chars in the file path as suggested in other posts, I've copied the image into the same directory as the js file but I still get an unresolved module error.
This is how I am adding the image:
(I've tried using different paths with the same result, 'receiptIcon.png', './receiptIcon.png', './../../assets/img/receiptIcon.png', './../../assets/img/receiptIcon.PNG' )
<View style={styles.iconContainer}>
{/* icon image*/}
<Image source={require('./receiptIcon.PNG')} style={styles.icon} />
</View>
Is there anything I am missing because as far as the documentation says I just need to add the image to the project dir and the packager does the rest?
I'm using
react-native-cli: 2.0.1
react-native: 0.52.0
(I also have images working when loaded from a URL, from taking a picture and from the Camera Roll/Gallery)
Here you can see the icons are not loaded. Can someone please find me a solution.
Code content:
import {Icon, Row} from '#shoutem/ui';
return (
<View style={styles.container}>
<NavigationBar title="All Restaurants" />
<View style={styles.row}>
<Row styleName="small" >
<Icon name="play"/>
<Text>About</Text>
<Icon styleName="disclosure" name="right-arrow"/>
</Row>
</View>
</View>
);
For me this issue occurred because the font files were not in the android/app/src/main/assests/font/ folder inside the root of your react-native directory.
I copied all the font files from this link to shoutem's github (you may also find it inside your-project-directory/node_modules/#shoutem/ui/examples/RestaurentsApp/android/app/src/main/assests/font/) to the above folder and rebuilt the app.
This worked for me, I hope it'll work for you too.
Perhaps it's an issue with loading fonts. Could you check #shoutem/ui's Github for similar issues? There is one about icons appearing as Chinese letters. Did you try with other icon names?
I know I am responding to an old thread, but as it shows up first in Google for I'm sure many people experiencing the same problem will come across this one.
I realized I forgot to run react-native link after npm install #shoutem/ui --save.
Skipping this step caused the fonts and assets (including icons) not to be installed. Running the link command fixed the missing fonts.