I need to show SVG icons inside my application, I did the entire process of installing the react-native-vector-icons library and configuring icomon. Also, I went to the icomon website and created my font files. But when I use it, the application renders an icon different from the one I should be reloaded by the file.
config icomon
import { createIconSetFromIcoMoon } from 'react-native-vector-icons';
import icoMoonConfig from '../../assets/customIcons/selection.json';
export default createIconSetFromIcoMoon(
icoMoonConfig,
);
icon that should be loaded.
icon being loaded
My code
export function ItemMenuDropdown({ item }) {
const navigation = useNavigation();
return (
<Container onPress={() => navigation.navigate(item.navigation)}>
<Content>
<CustomIcon name="pencil" size={normalize(18)} color="#F68B1F" />
<Text>{item.item}</Text>
</Content>
</Container>
)
I've looked for several solutions here on the site, but I haven't found one that works. Can someone help me?
I think the problem is in your selection.json file. It's either out of date or you're having some kind of cache problem. Maybe you want to try the same operation using this module.
react-icomoon
I want to see a different icon and tooltip when I set the property editable in material-table but I can't find a way. I know that there is the possibility to override a component but nothing works. Something like this maybe...
components={{
EditRow: props => (
<MTableEditRow
{...props}
icons={{
Edit: () => <SettingsIcon />
}}
/>
)
}}
I think there is a simpler way to achieve what you are looking for. Try this:
Import the icon component of your choice and define an object with the Edit key to override the default icon:
import Settings from "#material-ui/icons/Settings";
const tableIcons = {
Edit: () => <Settings />
};
Then use icons props of your MT component:
<MaterialTable
columns={tableColumns}
data={data}
title="Material Table - change edit icon & tooltip "
icons={tableIcons}
localization={{
body: {
editTooltip: "Custom edit tooltip"
}
}}
// other props..
/>
As seen above, use localization to set the label you need. This a sandbox with a working example, good luck!
In my react-native project, I would like to implement a feature that tapping on an icon pops up a native picker component in iOS and Android respectively. Something like this library's effect:
But with the linked library, it always default to have a text input field clicking on which the picker native component pops out. But in my project I don't need that default text input field, I have an icon component (think it as whatever react-native custom component), I would like to have the same effect when clicking/tapping on the icon component.
Is it possible to achieve it with the library I linked? I noticed there is icon property in the library, but it is not clear how to use it and whether it is the property that could replace the text input field. Anyone could you please help me?
This is what I tried with the library, but it doesn't show MyIconComponent instead it still shows a input text field:
return (
<RNPickerSelect
onValueChange={value => console.log(value)}
icon={() => {
return (
<View style={styles.main}>
<MyIconComponent />
</View>
);
}}
items={[
{label: 'Football', value: 'football'},
{label: 'Baseball', value: 'baseball'},
{label: 'Hockey', value: 'hockey'},
]}
/>
);
If I can't achieve what I want with this library then how to implement the same effect when tapping on my icon component?
According to the library documentation, in order to remove the default field add "placeholder={}" to the component props.
That is what you are looking for? did I get you right?
I want to use the Alert Api to display OS behavior alerts.
I'm asking myself if you can display Hyperlinks inside the Text of an alert?
Alert.alert(
'Alert',
'This is an Alert. I want to include hyperlinks here.',
[
{
text: 'Cancel',
onPress: () => console.log("Alert cancel"),
style: 'cancel',
},
{
text: 'Accept',
onPress: () => console.log("Alert accept"),
style: 'default'
},
]
);
You could implement a dialog container, and use the React Native Linking component on the Dialog.Description onPress() to turn it into a hyperlink:
<Dialog.Description onPress={() => Linking.openURL('https://www.google.com')}
style={{ textDecorationLine: 'underline', color: 'blue' }}>www.google.com</Dialog.Description>
or you could add a Text component inside the Dialog.Description alongside some other text to just have a certain word be the hyperlink:
<Dialog.Description>
Visit this website:
<Text onPress={() => Linking.openURL('https://www.google.com')}
style={{ textDecorationLine: 'underline', color: 'blue' }}>www.google.com</Text>
</Dialog.Description>
A word of caution, you're suppose to only pass a string to the Dialog.Description and doing the above will give you a console warning. So use at your own caution but it's working fine for me, and you can hide the warning using the React Native YellowBox component by adding this line outside of your class export (so near the import statements):
YellowBox.ignoreWarnings(['Failed prop type: Invalid prop `children` of type `array` supplied to `DialogDescription`, expected `string`'])
Much better to create a Modal (or simply a View component with position: absolute) to handle this than to dive into the native code.
https://facebook.github.io/react-native/docs/0.56/modal
You need to install "react-native-dialogs"( an android only module for material design dialogs) as follows:
1] Installation:
npm install react-native-dialogs --save
2] Linking:
react-native link react-native-dialogs
3] Import it in your page:
import DialogAndroid from 'react-native-dialogs';
also need to add below code inside your render:
<Button title="show custom alert" onPress={this.showCustomAlert} />
and at last add below function in your screen:
showCustomAlert() {
DialogAndroid.alert('Alert', `This is a link Google`, {
contentIsHtml: true
});
}
You can find more details here https://github.com/aakashns/react-native-dialogs
This is possible using the Linking module that comes with React-Native. Please check out the following:
Display hyperlink in React Native App
If this doesn't work maybe try this npm package:
https://www.npmjs.com/package/react-native-hyperlink
The documentation says that the only way to reference a static image is to use require.
But I'm not sure where does react expect to have those images. The examples don't have any domain, so it seems like you have to go to Xcode and add them to Images.xcassets, but that didn't work for me.
Using React Native 0.41 (in March 2017), targeting iOS, I just found it as easy as:
<Image source={require('./myimage.png')} />
The image file must exist in the same folder as the .js file requiring it for "./" to work.
I didn't have to change anything in the XCode project. It just worked.
Note that the path seems to have to start with "./" or "../" and be full lower case. I'm not sure what all the restrictions are, but start simple and work forward.
Hope this helps someone, as many other answers here seem overly complex and full of (naughty) off-site links.
UPDATE: BTW - The official documentation for this is here:
https://reactnative.dev/docs/images
It works exactly as you expect it to work. There's a bug https://github.com/facebook/react-native/issues/282 that prevents it from working correctly.
If you have node_modules (with react_native) in the same folder as the xcode project, you can edit node_modules/react-native/packager/packager.js and make this change: https://github.com/facebook/react-native/pull/286/files . It'll work magically :)
If your react_native is installed somewhere else and the patch doesn't work, comment on https://github.com/facebook/react-native/issues/282 to let them know about your setup.
ES6 solution:
import DefaultImage from '../assets/image.png';
const DEFAULT_IMAGE = Image.resolveAssetSource(DefaultImage).uri;
and then:
<Image source={{uri: DEFAULT_IMAGE}} />
If loading images dynamically one can create a .js file like following and do require in it.
export const data = [
{
id: "1",
text: "blablabla1",
imageLink: require('../assets/first-image.png')
},
{
id: "2",
text: "blablabla2",
imageLink: require('../assets/second-image.png')
}
]
In your component .js file
import {data} from './js-u-created-above';
...
function UsageExample({item}) {
<View>
<Image style={...} source={item.imageLink} />
</View>
}
function ComponentName() {
const elements = data.map(item => <UsageExample key={item.id} item={item}/> );
return (...);
}
I had this exact same issue until I realized I hadn't put the image in my Image.xcassets. I was able to drag and drop it into Xcode with Image.xcassets open and after rebuilding, it fixed the problem!
To display image from local folder, you need to write down code:
<Image source={require('../assets/self.png')}/>
Here I have put my image in asset folder.
From the UIExplorer sample app:
Static assets should be required by prefixing with image! and are located in the app bundle.
So like this:
render: function() {
return (
<View style={styles.horizontal}>
<Image source={require('image!uie_thumb_normal')} style={styles.icon} />
<Image source={require('image!uie_thumb_selected')} style={styles.icon} />
<Image source={require('image!uie_comment_normal')} style={styles.icon} />
<Image source={require('image!uie_comment_highlighted')} style={styles.icon} />
</View>
);
}
I was having trouble with react-native-navigation, I created my own header component, then inserted a image - as logo - on the left before title, then when I was triggering navigate to another screen and then back again, logo was loading again, with a timeout near 1s, my file were local. My solution :
Logo.json
{"file" : "base64 big string"}
App.js
import Logo from '.../Logo.json'
...
<Image source={{uri:Logo.file}} />
We can do like below:
const item= {
image: require("../../assets/dashboard/project1.jpeg"),
location: "Chennai",
status: 1,
projectId: 1
}
<Image source={item.image} style={[{ width: 150, height: 150}]} />
This from https://github.com/facebook/react-native/issues/282 worked for me:
adekbadek commented on Nov 11, 2015
It should be mentioned that you don't have to put the images in Images.xcassets - you just put them in the project root and then just require('./myimage.png') as #anback wrote
Look at this SO answer and the pull it references
For typescript user
import { ImageSourcePropType } from 'react-native'
type Data = {
image:ImageSourcePropType
}
const data:Data = {
image:require('../.../log.png')
}
and then
<Image source={data.image}/>
You have to add to the source property an object with a property called "uri" where you can specify the path of your image as you can see in the following example:
<Image style={styles.image} source={{uri: "http://www.mysyte.com/myimage.jpg"}} />
remember then to set the width and height via the style property:
var styles = StyleSheet.create({
image:{
width: 360,
height: 40,
}
});