Git Product home page Git Product logo

react-native-iconify's Introduction

React Native Iconify

react-native-iconify is a library that simplifies the use of icons in React Native projects. It provides access 150,000+ icons.

You can find all the supported icons on these websites:

Icones Iconify

Installation

To use the react-native-iconify library, you first need to install it in your project. You can do this using the following command:

npm install react-native-iconify

Install react-native-svg

# for bare react native apps
npm install react-native-svg
npx pod-install

or

# for Expo apps
npx expo install react-native-svg

add plugin to (babel.config.js)

module.exports = {
  presets: [
    ...
  ],
  plugins: [
    ...
    'react-native-iconify/plugin',
  ],
};

Usage

Using the react-native-iconify library is straightforward. First, you need to call the Iconify component and provide the icon name using the icon prop:

import React from 'react';
import { Iconify } from 'react-native-iconify';

const ExampleScreen = () => {
  return <Iconify icon="mdi:heart" size={24} color="#900" />;
};

export default ExampleScreen;

In the example above, we show how to use the mdi-heart Iconify icon. You can provide values for the size and color props to customize the appearance of the icon.

Bundle size

Tested on empty expo managed app

Icons Size (MB) Difference (MB)
1 3.07 -
100 3.14 +0.07
1000 3.7 +0.63

Troubleshooting

Iconify: 'icon' prop must be a string literal

Adding more than 150,000 icons to the application would increase the size and loading time of the application. Therefore, the React Native Iconify Babel plugin loads only the necessary icons, allowing the application to contain only the icons that are needed so you cannot use variable.

Here is an example of the incorrect usage:

const icon = 'mdi:heart';
<Iconify icon={icon} size={24} color="red" />;

To fix this issue, use like this:

<Iconify icon="mdi:heart" size={24} color="red" />

Iconify: You need to install a Babel plugin before using this library. You can continue by adding the following to your babel.config.js

If you're using a library that requires the "react-native-iconify/plugin" Babel plugin but you forgot to install it, you may encounter errors. Here's how to troubleshoot and fix the issue:

Add the following code to your Babel configuration file (usually babel.config.js):

module.exports = {
  presets: [
    ...
  ],
  plugins: [
    ...
    'react-native-iconify/plugin',
  ],
};

After installing and configuring the plugin, you may need to restart your bundler to ensure that the changes take effect.

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

react-native-iconify's People

Contributors

amandeepmittal avatar oktaysenkan avatar ubaidjs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-native-iconify's Issues

Add support for strokeWidth

Some icon sets allow for the configuration of strokeWidth. Unfortunately, the strokeWidth argument does not work on icons that have stroke-width defined in nested tags. I found a workaround that allows overriding stroke-width, but I'm not sure how you want to implement it in the library, so I'll just suggest an idea:

Example Icon SVG:

<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.5"><path d="M17 8V5a1 1 0 0 0-1-1H6a2 2 0 0 0 0 4h12a1 1 0 0 1 1 1v3m0 4v3a1 1 0 0 1-1 1H6a2 2 0 0 1-2-2V6"/><path d="M20 12v4h-4a2 2 0 0 1 0-4z"/></g></svg>

My workaround:

export const renderIcon = (props: RuntimeProps) => {
  const svg = prepareSvgIcon(props);

  if (!props.iconData || !svg || !svg.body) {
    return null;
  }

  if (props.strokeWidth !== undefined) {
    svg.body = svg.body.replace(
      /stroke-width="[^"]*"/g,
      `stroke-width="${props.strokeWidth}"`
    );
  }

  if (Platform.OS === 'web') {
    return renderWebIcon(svg, props);
  }

  return renderNativeIcon(svg, props);
};

This is not an issue but an inquiry. Do you support animating the icon. In the case of <View />, we use Iconify?

example from Reanimated 3

import React, { useRef } from 'react';
import { StyleSheet, View, Button, ViewProps } from 'react-native';
import Animated, { useSharedValue, withSpring } from 'react-native-reanimated';

const MyView = React.forwardRef(
  (props: ViewProps, ref: React.LegacyRef<View>) => {
    // some additional logic
    return <View ref={ref} {...props} />;
  }
);

// highlight-next-line
const MyAnimatedView = Animated.createAnimatedComponent(MyView);

export default function App() {
  const ref = useRef<View | null>(null);
  const width = useSharedValue(100);

  const handlePress = () => {
    width.value = withSpring(width.value + 50);
  };

  return (
    <View style={styles.container}>
      <MyAnimatedView style={{ ...styles.box, width }} />
      <Button onPress={handlePress} title="Click me" />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
  },
  box: {
    height: 100,
    backgroundColor: '#b58df1',
    borderRadius: 20,
    marginVertical: 64,
  },
});

Still getting "Need to install a Babel plugin" even after adding to babel.config.js

App using Expo

babel.config.js

module.exports = function (api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
    plugins: [
      'react-native-iconify/plugin',
    ],
  };
};

package.json

{
  "name": "turmeiro",
  "version": "1.0.0",
  "main": "expo-router/entry",
  "scripts": {
    "start": "expo start",
    "android": "expo run:android",
    "ios": "expo run:ios",
    "web": "expo start --web",
    "lint": "eslint ."
  },
  "dependencies": {
    "@hookform/resolvers": "^3.3.4",
    "@react-native-async-storage/async-storage": "1.21.0",
    "@supabase/supabase-js": "^2.39.3",
    "expo": "^50.0.4",
    "expo-constants": "~15.4.5",
    "expo-image": "~1.10.5",
    "expo-image-picker": "~14.7.1",
    "expo-linking": "~6.2.2",
    "expo-router": "^3.4.6",
    "expo-secure-store": "~12.8.1",
    "expo-status-bar": "~1.11.1",
    "react": "18.2.0",
    "react-hook-form": "^7.49.3",
    "react-native": "0.73.2",
    "react-native-iconify": "^1.0.0",
    "react-native-safe-area-context": "4.8.2",
    "react-native-screens": "~3.29.0",
    "react-native-svg": "14.1.0",
    "react-native-toast-message": "^2.2.0",
    "react-native-url-polyfill": "^2.0.0",
    "zod": "^3.22.4"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@types/react": "~18.2.45",
    "typescript": "^5.3.3"
  },
  "private": true
}

Full Error:

Error: Iconify: You need to install a Babel plugin before using this library. You can continue by adding the following to your babel.config.js

This error is located at:
    in Iconify (at Avatar.tsx:15)
    in RCTView (at View.js:116)
    in View (at Avatar.tsx:14)
    in Avatar (at Profile.tsx:10)
    in RCTView (at View.js:116)
    in View (at createAnimatedComponent.js:54)
    in Unknown (at TouchableOpacity.js:256)
    in TouchableOpacity (at TouchableOpacity.js:323)
    in TouchableOpacity (at ImagePicker.tsx:30)
    in ImagePicker (at Profile.tsx:10)
    in RCTView (at View.js:116)
    in View (at Profile.tsx:9)
    in RCTSafeAreaView (at Profile.tsx:8)
    in Profile (at profile.tsx:4)
    in ProfilePage (at useScreens.js:112)
    in Unknown (at useScreens.js:116)
    in Suspense (at useScreens.js:115)
    in Route (at useScreens.js:131)
    in Route(profile) (at SceneView.tsx:132)
    in StaticContainer
    in EnsureSingleNavigator (at SceneView.tsx:124)
    in SceneView (at useDescriptors.tsx:218)
    in QualifiedSlot (at Navigator.js:103)
    in PreventRemoveProvider (at useNavigationBuilder.tsx:718)
    in NavigationContent (at useComponent.tsx:35)
    in Unknown (at Navigator.js:72)
    in QualifiedNavigator (at Navigator.js:52)
    in Navigator (at Navigator.js:102)
    in Slot (at _layout.tsx:18)
    in AppLayout (at useScreens.js:112)
    in Unknown (at useScreens.js:116)
    in Suspense (at useScreens.js:115)
    in Route (at useScreens.js:131)
    in Route((app)) (at SceneView.tsx:132)
    in StaticContainer
    in EnsureSingleNavigator (at SceneView.tsx:124)
    in SceneView (at useDescriptors.tsx:218)
    in QualifiedSlot (at Navigator.js:103)
    in PreventRemoveProvider (at useNavigationBuilder.tsx:718)
    in NavigationContent (at useComponent.tsx:35)
    in Unknown (at Navigator.js:72)
    in QualifiedNavigator (at Navigator.js:52)
    in Navigator (at Navigator.js:102)
    in Slot (at _layout.tsx:8)
    in AuthContextProvider (at _layout.tsx:7)
    in RootLayout (at useScreens.js:112)
    in Unknown (at useScreens.js:116)
    in Suspense (at useScreens.js:115)
    in Route (at useScreens.js:131)
    in Route() (at ExpoRoot.js:90)
    in RNCSafeAreaProvider (at SafeAreaContext.tsx:92)
    in SafeAreaProvider (at ExpoRoot.js:55)
    in wrapper (at ExpoRoot.js:89)
    in EnsureSingleNavigator (at BaseNavigationContainer.tsx:430)
    in BaseNavigationContainer (at NavigationContainer.native.js:105)
    in ThemeProvider (at NavigationContainer.native.js:104)
    in NavigationContainerInner (at ExpoRoot.js:86)
    in ContextNavigator (at ExpoRoot.js:64)
    in ExpoRoot (at qualified-entry.js:20)
    in App (created by ErrorOverlay)
    in ErrorToastContainer (created by ErrorOverlay)
    in ErrorOverlay (at withDevTools.ios.js:25)
    in withDevTools(ErrorOverlay) (at renderApplication.js:57)
    in RCTView (at View.js:116)
    in View (at AppContainer.js:127)
    in RCTView (at View.js:116)
    in View (at AppContainer.js:155)
    in AppContainer (at renderApplication.js:50)
    in main(RootComponent) (at renderApplication.js:67), js engine: hermes

RNSVGRect has Duplicate Registered

Hy @oktaysenkan, thanks to this great package.

i'm using your package since yesterday, everything fine until i linking my static assets using npx react-native-asset and i faces this error

Invariant Violation: Tried to register two views with the same name RNSVGRect, js engine: hermes

Click here to see full error message.

my package.json

which i have try

  • remove node_modules
  • reinstall app & reinstall package
  • reset cache using yarn start --reset-cache

Thanks 🍻

Exception thrown while executing UI block: -[__NSDictionaryM firstObject]: unrecognized selector sent to instance

Exception thrown while executing UI block: -[__NSDictionaryM firstObject]: unrecognized selector sent to instance 0x6000024c9f20 __53-[ABI46_0_0RCTUIManager flushUIBlocksWithCompletion:]_block_invoke ABI46_0_0RCTUIManager.m:1202 __53-[ABI46_0_0RCTUIManager flushUIBlocksWithCompletion:]_block_invoke.431 _dispatch_call_block_and_release _dispatch_client_callout _dispatch_main_queue_drain _dispatch_main_queue_callback_4CF __CFRUNLOOP_IS_SERV

"react-native-svg": "12.3.0"
"react-native": "0.69.9",
"react": "18.0.0",
"expo": "^46.0.0",

'icon' prop must be a string literal

Hi, I would like to ask is there any way to insert dynamic value in 'icon' prop?
I have my code like image shown below.

Screenshot 2023-09-22 at 15 00 18

Your advice is appreciated. Thanks in advance.

Babel plugin

Hi there,

I am first try to use iconify in react native.
I have followed the steps provided in Readme.md to add the plugin in babel.config.js, and clear cache for my project.
But it turns out an error like the image below.

Simulator Screenshot - iPhone 14 Pro - 2023-09-21 at 15 07 48

Screenshot 2023-09-21 at 15 11 37

I would like to humbly seek your advice to resolve this issue.
Thanks in advance.

Poor performance in lists

When rendering icons in lists, performance drops.
Below are 2 videos of how the lists behave with or without icons.
I don't know about performance on iOS, because I can't run my app on iOS, but I think on iOS will be the same problem.

Screen.Recording.2024-02-07.at.13.20.27.mov
Screen.Recording.2024-02-07.at.13.20.13.mov

`Element type is invalid: expected ... but got: undefined`

Hi, I just installed this library on a fresh Expo 50 project using the Metro Bundler for web, and when trying to use the Iconify component, I get this error:

Uncaught Error
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Check the render method of `Iconify`.

Environment

Node: v20.10.0
Expo: v50.0.2
react-native-iconify: v0.2.11
Web bundler: Metro

Reproduction

Here's a minimal reproduction GitHub repository

Cannot read property 'toString' of undefined

Screenshot_20240320_092402

Hi there,

I've encountered a bug while using react-native-iconify that I haven't encountered before. Despite checking online and in library issues, I couldn't find anyone else experiencing the same problem.

I'm using Expo SDK 50 on a --dev client. Here's my package.json:

 "expo": "~50.0.13",
 "expo-dev-client": "^3.3.10",
 "react": "18.2.0",
 "react-native": "0.73.5",
 "react-native-iconify": "^1.0.0",

In my babel plugin configuration, I have:

 module.exports = function (api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
    plugins: [
    'react-native-reanimated/plugin',
    'react-native-iconify/plugin'
    ]
  };
};

Here's how I import and use Iconify in my component:

At the top of my component:
import { Iconify } from 'react-native-iconify';

In the render method:
<Iconify icon="iconamoon:discount-fill" color="#fff" />

If anyone has a solution or tips to resolve this issue, I'd appreciate it.

Universal Support

I've decided to enhance the project by adding support for React, Vue, Svelte, Vanilla, React Native, and React Native Web. The primary reason behind this decision is my dissatisfaction with the Iconify official library's operation over HTTP. Therefore, I wish to rename the project from react-native-iconify to a different name.

In conjunction with this, we will transition to a monorepo structure, offering several packages:

  • {package}/core
  • {package}/react
  • {package}/vue
  • {package}/svelte
  • {package}/native

Each of these packages will be tailored to integrate seamlessly with the respective technology, providing developers with a uniform icon library experience across multiple frameworks and platforms.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.