Closed yairopro closed 6 years ago
That's exactly what I did in a project.
index.js
looks like this:
/**
* Multiple ways to import:
* 1- Importing a specific font as Icon
* -- import Icon from './lib/Icons/FontAwesome'
*
* 2- Importing a specific font as its name
* -- import {FontAwesome} from './lib/Icons'
*
* 3- Importing all fonts in an Icon object
* -- import * as Icon from './lib/Icons'
*/
import MaterialCommunityIconsI from 'react-native-vector-icons/MaterialCommunityIcons'
import SimpleLineIconsI from 'react-native-vector-icons/SimpleLineIcons'
import MaterialIconsI from 'react-native-vector-icons/MaterialIcons'
import FontAwesomeI from 'react-native-vector-icons/FontAwesome'
import FoundationI from 'react-native-vector-icons/Foundation'
import EvilIconsI from 'react-native-vector-icons/EvilIcons'
import OcticonsI from 'react-native-vector-icons/Octicons'
import IoniconsI from 'react-native-vector-icons/Ionicons'
import FeatherI from 'react-native-vector-icons/Feather'
import EntypoI from 'react-native-vector-icons/Entypo'
import ZocialI from 'react-native-vector-icons/Zocial'
import React from 'react'
export const MaterialCommunityIcons = props => (
<MaterialCommunityIconsI {...props} />
)
export const SimpleLineIcons = props => <SimpleLineIconsI {...props} />
export const MaterialIcons = props => <MaterialIconsI {...props} />
export const FontAwesome = props => <FontAwesomeI {...props} />
export const Foundation = props => <FoundationI {...props} />
export const EvilIcons = props => <EvilIconsI {...props} />
export const Ionicons = props => <IoniconsI {...props} />
export const Octicons = props => <OcticonsI {...props} />
export const Feather = props => <FeatherI {...props} />
export const Entypo = props => <EntypoI {...props} />
export const Zocial = props => <ZocialI {...props} />
Except that instead of importing from my local folder (for example: import ZocialI from './Zocial'
) I just imported directly from the library as you might just want to have a single file (index.js), and not a file per font like I do.
Other files look like this:
import Icon from 'react-native-vector-icons/Octicons'
export default Icon
I wanted to know if there was an already implemented way in the project, not writting a file of my own, which later might be obsolete.
By the way, why do you export this way?
export const SimpleLineIcons = props => <SimpleLineIconsI {...props} />
It might be easier like this, isn't it?
export default {
SimpleLineIcons,
// ...
}
Did the problem solve?I have the same problem with this
@peng8350 That was more a question than a problem. And the answer is "No, there isn't an existing way to do this.". So you have to import + export all icons by yourself in one single file.
This article will help you follow these steps https://medium.com/p/45c0afdb7ca7
Is there a way to import all fonts at once? Something like this :
import * as IconSets from "react-native-vector-icons"
And in the render method:return <IconSets.MaterialIcons name="alarm" size={30} />