Skip to content

Commit 284a7b8

Browse files
authored
docs(guides): add asset icons pack guide
1 parent 617b40d commit 284a7b8

File tree

1 file changed

+77
-3
lines changed

1 file changed

+77
-3
lines changed

docs/src/articles/guides/icon-packages.md

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ const HomeScreen = () => (
143143

144144
const App = () => (
145145
<React.Fragment>
146-
<IconRegistry icons={EvaIconsPack} />
146+
<IconRegistry icons={FeatherIconsPack} />
147147
<ApplicationProvider mapping={mapping} theme={lightTheme}>
148148
<HomeScreen />
149149
</ApplicationProvider>
@@ -220,8 +220,8 @@ By passing an array of icon packs, we can register it in the application:
220220
import React from 'react';
221221
import { ApplicationProvider, IconRegistry, Layout, Text } from '@ui-kitten/components';
222222
import { mapping, light as lightTheme } from '@eva-design/eva';
223-
import { FeatherIconsPack } from './feather-icons.js'; // <-- Import Feather icons
224-
import { MaterialIconsPack } from './material-icons.js'; // <-- Import Material icons
223+
import { FeatherIconsPack } from './feather-icons'; // <-- Import Feather icons
224+
import { MaterialIconsPack } from './material-icons'; // <-- Import Material icons
225225

226226
const HomeScreen = () => (
227227
<Layout style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
@@ -270,6 +270,80 @@ That's it. Here is a result that you might have
270270
271271
<hr>
272272
273+
## Tip: Asset Icon Package
274+
275+
By using same technique, this may be also useful to create an Icon package for all of available icons in assets.
276+
277+
With a similar to [3rd party Icon packages guide](guides/icon-packages#3rd-party-icon-packages) way, create an Asset Icons provider.
278+
279+
```jsx
280+
import React from 'react';
281+
import { Image } from 'react-native';
282+
283+
const IconProvider = (source) => ({
284+
toReactElement: ({ animation, ...style }) => (
285+
<Image style={style} source={source}/>
286+
),
287+
});
288+
289+
export const AssetIconsPack = {
290+
name: 'assets',
291+
icons: {
292+
'github': IconProvider(require('../assets/images/github.png')),
293+
'color-palette': IconProvider(require('../assets/images/color-palette.png')),
294+
// ...
295+
},
296+
};
297+
```
298+
299+
### Register Icons
300+
301+
By passing an array of icon packs, we can register it in the application:
302+
303+
```jsx
304+
import React from 'react';
305+
import { ApplicationProvider, IconRegistry, Layout, Text } from '@ui-kitten/components';
306+
import { EvaIconsPack } from '@ui-kitten/eva-icons';
307+
import { mapping, light as lightTheme } from '@eva-design/eva';
308+
import { AssetIconsPack } from './asset-icons'; // <-- Import Feather icons
309+
310+
const HomeScreen = () => (
311+
<Layout style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
312+
<Text catetory='h1'>HOME</Text>
313+
</Layout>
314+
);
315+
316+
const App = () => (
317+
<React.Fragment>
318+
<IconRegistry icons={[EvaIconsPack, AssetIconsPack]}/>
319+
<ApplicationProvider mapping={mapping} theme={lightTheme}>
320+
<HomeScreen />
321+
</ApplicationProvider>
322+
</React.Fragment>
323+
);
324+
325+
export default App;
326+
```
327+
328+
### Usage
329+
330+
When using multiple icon packages, you're able to choose an icon library with simply changing `pack` property.
331+
332+
```jsx
333+
import React from 'react';
334+
import { Button, Icon } from '@ui-kitten/components';
335+
336+
export const GithubIcon = (style) => (
337+
<Icon {...style} name='github' pack='assets' />
338+
);
339+
340+
export const GithubButton = () => (
341+
<Button icon={GithubIcon}>View Github</Button>
342+
);
343+
```
344+
345+
<hr>
346+
273347
## Conclusion
274348
275349
In this guide, you learned how to use UI Kitten Icon component. Since Eva Icons relies on svg icons, consider reading <a href="https://github.com/react-native-community/react-native-svg#react-native-svg" target="_blank">react-native-svg documentation</a> to become more familiar with it. Also, if you your icon pack of choice relies on vector icons, read <a href="https://github.com/oblador/react-native-vector-icons#table-of-contents" target="_blank">react-native-vector-icons docs</a>.

0 commit comments

Comments
 (0)