how to add #expo/vector-icons in react native app? - react-native

i am using #expo/vector-icons here is my package.json file
"dependencies": {
"#expo/vector-icons": "^4.1.1",
"color": "^1.0.3",
"expo": "^30.0.1",
"moment": "^2.22.2",
"react": "16.3.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-
30.0.0.tar.gz",
"react-native-extended-stylesheet": "^0.4.0" },
when i import #expo/vector-icon library in my component
import { Ionicons } from '#expo/vector-icons';
it gives error

The library comes by default so you don't need to install #expo/vector-icons.
You can just do this for example:
import { Ionicons } from '#expo/vector-icons';
and then you can use it like:
<Ionicons name="ios-pizza" color="red" size={200} />
FYI, this directory is helpful in finding different icons https://expo.github.io/vector-icons/

In your dependencies (package.json) remove #expo/vector-icons. They are included in the expo package and different versions of expo and expo/vector-icons can cause errors like this one.
From the official docs:
This library is installed by default on the template project that get
through expo init -- it is part of the expo package. It includes
popular icon sets and you can browse all of the icons using the
#expo/vector-icons directory.
Update 2021:
The official docs changed a bit, and instead of searching for icons in:
#expo/vector-icons directory
You can now search using:
icons.expo.fyi
This makes it far easier than before.

Go to 'https://icons.expo.fyi/' choose whatever you want, then import via copy, then use it.
import React from 'react'
import { Entypo } from '#expo/vector-icons';
import { View } from 'react-native';
export const Example = () => {
return(
<View>
<Entypo name="plus" size={24} color="black" />
</View>
)
}

Delete your node module folder and run expo init. And run the project

Related

StripeProvider.initialise is not defined

Im trying to using stripe-react-native (with expo and using android) library but immediately I use the StripeProvider I got this error (I followed the Docs):
TypeError: null is not an object (evaluating '_NativeStripeSdk["default"].initialise')
This error is located at:
in StripeProvider (at App.js:35)
in EnsureSingleNavigator (at BaseNavigationContainer.tsx:409)
in ForwardRef(BaseNavigationContainer) (at NavigationContainer.tsx:91)
in ThemeProvider (at NavigationContainer.tsx:90)
...
This is where I use it:
...
import { StripeProvider } from '#stripe/stripe-react-native'
//pass the ref to your navigation container
import { PersistGate } from 'redux-persist/integration/react'
import { store, persistor } from './store'
import { Provider } from 'react-redux'
import { AppTab } from './Navigation'
export default function App() {
return (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<NavigationContainer>
<StripeProvider
publishableKey="pk_live_L4zEu37Als6Z..."
>
<AppTab />
</StripeProvider>
</NavigationContainer>
</PersistGate>
</Provider>
)
}
my package.json:
...
"expo": "~41.0.1",
"expo-status-bar": "~1.0.4",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-41.0.0.tar.gz",
"react-native-web": "~0.13.12",
...
"#stripe/stripe-react-native": "^0.1.2",
....
I dont find anything on this problem can someone help me seeing what im doing wrong? thanks!
You'll need to update your Expo client, support for stripe-react-native was only added recently: https://github.com/stripe/stripe-react-native/issues/3#issuecomment-846225534
As I don't have enough reputation to comment, I'll have to post this as an answer. Extending Paul's solution, it's also helpful to checkout the "Upgrading your app" section of the Expo SDK 41 release blog post: https://blog.expo.io/expo-sdk-41-12cc5232f2ef#e10c.
Some key things to remember are that you will also need to upgrade the Expo apps on the devices you are using. If they are physical then use their respective app stores, and if not then you can can delete the apps and recreate them, or run expo client:install:ios and expo client:install:android. A final piece that helped me was to do a clean run after the upgrade: expo start -c.

How can I fix this error: Module not found: Can't resolve 'react-navigation/stack'?

package.json:
"#react-navigation/native": "^5.9.4",
"#react-navigation/stack": "^5.14.5",
MainNavigator:
import React from 'react';
import {
createStackNavigator,
createAppContainer,
} from 'react-navigation/stack';
import HomeScreen from './Surveys'
const Stack = createStackNavigator(MyStack);
function MyStack() {
return (
<Stack.Navigator>
<Stack.Screen name="HomeScreen" component={HomeScreen} />
</Stack.Navigator>
)
}
export default createAppContainer(Stack);
I have deleted node_modules, npm installed for Expo, installed specifically react-navigation/native, installed specifically react-navigation/stack.. I've gone in circles for an hour on this, nothing fixes it.
Try this:
$ yarn add react-navigation
$ expo install react-native-gesture-handler react-native-reanimated react-native-screens react-native-safe-area-context #react-native-community/masked-view
$ yarn add react-navigation-stack #react-native-community/masked-view
import { createAppContainer } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';
i was trying to re-use parts of an old project using old versions of these libraries/components. the solution was to build it from scratch with the current versions, which was very easy/fast. i wasted a few hours, which i guess isn't a total loss because will serve as a reminder that sometimes it is better to just start from scratch.

Uncaught Error: ReferenceError: Can't find variable: React for react-native-svg on Expo

I want to render simple svg on Expo, but the below error code is shown.
Uncaught Error: ReferenceError: Can't find variable: React
My code:
import * as React from 'react';
import { Component } from 'react';
import { View, Text} from 'react-native';
import Svg, { Circle, Rect } from 'react-native-svg';
export default class Chart extends Component {
render() {
return (
<View>
<Svg height="20" width="20">
<Circle cx="10" cy="10" r="10" fill="red" />
</Svg>
</View>
);
}
}
My dependencies are as below.
Expo cli: 3.27.4
"expo": "~37.0.3",
"react": "~16.9.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz",
"react-native-svg": "11.0.1",
Please advise if you know how to solve this issue.
Thanks!
Try to delete the node_modules and do and npx expo install or yarn install and check if this works.

Can't resolve Font Awesome modules in React Native

I am trying to get Font Awesome icons running my React Native application by following the instructions posted here. However, after completing the instructions, my simulator doesn't load the application and the command line gives me the following error:
error: bundling failed: Error: While trying to resolve module `#fortawesome/fontawesome-svg-core` from file `/Users/agaidis/Auto-ID-Lab/AudioApp/App.js`, the package `/Users/agaidis/Auto-ID-Lab/AudioApp/node_modules/#fortawesome/fontawesome-svg-core/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`/Users/agaidis/Auto-ID-Lab/AudioApp/node_modules/#fortawesome/fontawesome-svg-core/index.js`. Indeed, none of these files exist:
* `/Users/agaidis/Auto-ID-Lab/AudioApp/node_modules/#fortawesome/fontawesome-svg-core/index.js(.native||.ios.js|.native.js|.js|.ios.json|.native.json|.json)`
* `/Users/agaidis/Auto-ID-Lab/AudioApp/node_modules/#fortawesome/fontawesome-svg-core/index.js/index(.native||.ios.js|.native.js|.js|.ios.json|.native.json|.json)`
at ResolutionRequest.resolveDependency (/Users/agaidis/Auto-ID-Lab/AudioApp/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:92:15)
at DependencyGraph.resolveDependency (/Users/agaidis/Auto-ID-Lab/AudioApp/node_modules/metro/src/node-haste/DependencyGraph.js:237:485)
at Object.resolve (/Users/agaidis/Auto-ID-Lab/AudioApp/node_modules/metro/src/lib/transformHelpers.js:116:25)
at dependencies.map.result (/Users/agaidis/Auto-ID-Lab/AudioApp/node_modules/metro/src/DeltaBundler/traverseDependencies.js:298:29)
at Array.map (<anonymous>)
at resolveDependencies (/Users/agaidis/Auto-ID-Lab/AudioApp/node_modules/metro/src/DeltaBundler/traverseDependencies.js:294:16)
at /Users/agaidis/Auto-ID-Lab/AudioApp/node_modules/metro/src/DeltaBundler/traverseDependencies.js:159:33
at Generator.next (<anonymous>)
at step (/Users/agaidis/Auto-ID-Lab/AudioApp/node_modules/metro/src/DeltaBundler/traverseDependencies.js:239:307)
at /Users/agaidis/Auto-ID-Lab/AudioApp/node_modules/metro/src/DeltaBundler/traverseDependencies.js:239:467
BUNDLE [ios, dev] ../../index.js ░░░░░░░░░░░░░░░░ 0.0% (0/1), failed.
My code is as follows:
App.js
import React, {Component} from 'react';
import {AppRegistry} from 'react-native';
import MainApp from './src/components/MainApp';
import AudioExample from './src/components/AudioExample';
// For icons we use font awesome
import { library } from '#fortawesome/fontawesome-svg-core';
import { FontAwesomeIcon } from '#fortawesome/react-fontawesome';
import { faStroopwafel } from '#fortawesome/free-solid-svg-icons';
library.add(faStroopwafel)
AppRegistry.registerComponent('audioApp', () => MainApp);
export default MainApp;
Relevant piece of LangPage.js:
import React from 'react'
import { FontAwesomeIcon } from '#fortawesome/react-fontawesome'
import {View, Text, StyleSheet, Picker} from 'react-native'
import PropTypes from 'prop-types'
import Menu from './Menu'
class LangPage extends React.Component{
static propTypes = {
List: PropTypes.array.isRequired,
passFunc: PropTypes.func.isRequired,
}
render(){
return(
<View style={styles.container}>
<View style={styles.boxContainers}>
<FontAwesomeIcon icon="stroopwafel" />
<Text style={styles.header}>Select a Language</Text>
</View>
<View style={[styles.boxContainers, styles.menuBox]}>
<Menu givenL={this.props.List} selectFunc={this.props.passFunc}/>
</View>
</View>
)
}
}
For reference, I am using:
"#fortawesome/fontawesome-svg-core": "^1.2.0-14",
"#fortawesome/free-solid-svg-icons": "^5.1.0-11",
"#fortawesome/react-fontawesome": "0.1.0-11",
"i": "^0.3.6",
"npm": "^6.3.0",
"react": "16.4.1",
"react-native": "0.56.0"
Any thoughts on how I could fix this? Thanks!
Good morning,
I strongly recommend you to use the react-native-vectors-icons library instead of directly using fontAwesome. It may be why it doesn't work. For more informations, click here.
EDIT: You need to import the react-native-vector-icons in your dependencies. Go in your package.json file and type this line in the 'dependencies' section :
"react-native-vector-icons": "^4.5.0",
In your LangPage.js file, you will be able to import them like this :
import Icon from 'react-native-vector-icons/FontAwesome';
With that done, you will be able to display easily icons from font-awesome in your react native components, just like that :
<Icon
color={Colors.primaryBackground}
name={stroopwafel}
size={40}
/>
Hope it helped :)
Have a good day
William is on the right track for getting you where you want to be, however, there are a couple of things missing from his answer.
react-native-vector-icons needs to be linked, either by running
react-native link react-native-vector-icons
or by following the manual linking example in the README.
You can check if linking has worked correctly by checking the following files;
Android:
android/app/src/main/java/.../MainApplication.java
android/settings.gradle
android/app/build.gradle
iOS:
ios/<APP_NAME>/Info.plist
ios/<APP_NAME>/<APP_NAME>.xcodeproj/project.pbxproj
I may have missed some files, but these should be the main ones.
If you have used react-native-create-app and have an expo project that hasn't been ejected yet, then I would recommend using the expo vector-icons package.
Hope this helps.
just:
npm i --save #fortawesome/react-native-fontawesome
remove the libraries
"react-native-linear-gradient": "^2.5.6",
"react-native-vector-icons": "^4.5.0",
and then Reload (cmd+R) the app

React Native with Native Base (Unexpected Token Error)

I have React Native and Native Base configured. When I deploy the app for Android it throws me an error stating that an unexpected token was found near where Container component is present in my code.
My package.json file is:
{
"name": "React Native POC",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"native-base": "^0.5.18",
"react": "15.4.1",
"react-native": "0.39.2",
"react-redux": "^4.4.6",
"redux": "^3.6.0"
},
"devDependencies": {
"babel-jest": "17.0.2",
"babel-preset-react-native": "1.9.0",
"jest": "17.0.3",
"react-test-renderer": "15.4.1"
},
"jest": {
"preset": "react-native"
}
}
Could it be that certain versions are not working well with the other?
Additionally (if it matters) I am using Node version 6.8.1, npm version 3.10.8 and react-native-cli 2.0.0. Also, I have yarn, sinopia and browserify installed globally.
Still a beginner with React Native and I cannot tell if any dependency clashes may be present (obvious or otherwise)
My js file is:
import React, {Component} from 'react';
import {Container, Content} from 'native-base';
export default class ReactNativePOC extends Component {
render() {
return {
<Container> // Error here
<Content>
</Content>
</Container>
}
}
}
There does not seem to be any problem with my setup (excluding native base) as I can run a react native app with default controls however I seem to be getting this error only for native base controls
The return statement should use parentheses instead of braces.
render() {
return (
<Container>
<Content>
</Content>
</Container>
);
}
Please check the basic syntax from docs of React Native
Check NativeBase KitchenSink - An example app with all the UI components of NativeBase.
Since you said you are beginner in React Native, you can check Native Starter Kit - A Starter Kit for React Native + NativeBase + Navigation Experimental + Redux + CodePush Apps