I'm trying to get the bottom tab navigator to show the icons for Vue Native.
I'm new to coding, and it's a little bit confusing for me to understand some bits how Vue native and React native syntax works. I searched the internet hi and low to find the information that I needed.
I did find some information on the official React Native website.
The Vue native official website doesn't contain so much detailed information regarding this.
So, my question is how do I get this to work? The code below spits out an error code when I try to execute it.
Thanks in advance for the help :)
// Chris
I leave some code snippets below:
<template>
<app-navigator></app-navigator>
</template>
<script>
import {
createAppContainer,
createMaterialBottomTabNavigator,
createStackNavigator,
} from "vue-native-router";
import Icon from '../node_modules/react-native-vector-icons/dist/FontAwesome.js';
import Home from "./screens/HomeScreen.vue";
import Message from "./screens/Message.vue"
const StackNavigator = createMaterialBottomTabNavigator({
Hem: Home,
Message: {
screen: Message,
navigationOptions: {
title: 'woop',
tabBarIcon: ({tintColor})=>{
<Icon name="ios-home" color={tintColor} size={25}/>
}
},
},
});
const AppNavigator = createAppContainer(StackNavigator);
export default {
components: { Root, AppNavigator },
}
</script>
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject"
},
"dependencies": {
"axios": "^0.19.0",
"expo": "~36.0.2",
"expo-font": "~8.0.0",
"native-base": "^2.13.8",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-36.0.0.tar.gz",
"react-native-gesture-handler": "^1.5.2",
"react-native-paper": "^3.4.0",
"react-native-reanimated": "^1.4.0",
"react-native-vector-icons": "^6.6.0",
"react-native-web": "~0.11.7",
"react-navigation-material-bottom-tabs": "^2.1.5",
"vue-axios": "^2.1.5",
"vue-native-core": "^0.1.4",
"vue-native-helper": "^0.1.4",
"vue-native-router": "^0.1.1"
},
"devDependencies": {
"#babel/core": "^7.7.7",
"babel-preset-expo": "~8.0.0",
"vue-native-scripts": "^0.1.4"
},
"private": true
}
I got it working by adding this:
import * as React from 'react';
import Icon from 'react-native-vector-icons/FontAwesome';
Message: {
screen: Message,
navigationOptions: {
tabBarLabel: 'Meddelanden',
tabBarIcon: <Icon name="rocket" size={25}/>,
}
}
Related
When a styled component is applied to a React Native project using Expo, it is built on the web, but not on the phone.
But if I use StyleSheet.create with the same style, it works fine. Maybe there's something I'm missing out on?
Actions taken to solve the problem
Try lowering the version of the styled component to 5.0.0 or 4.4.3.
Try installing the styled component again.
Make sure my phone and computer are on the same network.
Try logging in to Expo again.
However, all of the above measures were to no avail.
What is the problem?
My App.js
import * as React from "react";
import { StatusBar } from "expo-status-bar";
import { NavigationContainer } from "#react-navigation/native";
import { createNativeStackNavigator } from "#react-navigation/native-stack";
import MainScreen from "./src/screen/MainScreen";
import LoginScreen from "./src/screen/LoginScreen";
export default function App() {
const Stack = createNativeStackNavigator();
return (
<NavigationContainer>
<StatusBar style="auto" />
<Stack.Navigator
initialRouteName="Main"
screenOptions={{ headerShown: false }}
>
<Stack.Screen name="Main" component={MainScreen} />
<Stack.Screen name="Login" component={LoginScreen} />
</Stack.Navigator>
</NavigationContainer>
);
}
enter image description here
My Package.json
{
"name": "my-project",
"version": "1.0.0",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web"
},
"dependencies": {
"#expo/vector-icons": "^13.0.0",
"#expo/webpack-config": "^0.17.0",
"#react-navigation/native": "^6.0.13",
"#react-navigation/native-stack": "^6.9.1",
"#react-navigation/stack": "^6.3.2",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"expo": "~46.0.13",
"expo-font": "^10.2.1",
"expo-status-bar": "~1.4.0",
"react": "18.0.0",
"react-dom": "18.0.0",
"react-native": "0.69.6",
"react-native-dotenv": "^3.3.1",
"react-native-web": "~0.18.7",
"socket.io-client": "^4.5.2",
"styled-components": "^5.3.6"
},
"devDependencies": {
"#babel/core": "^7.12.9",
"eslint": "^8.25.0",
"eslint-plugin-react": "^7.31.10",
"prettier": "2.7.1"
},
"private": true
}
I have an existing project that uses React Native and Expo. Currently, the application runs fine. I'm trying to integrate Jest into the project. A basic "true=true" test in jest passes and runs without error. When I try to run any code using ES6 terms, however, the following error occurs:
FAIL screens/__tests__/home.test.js
● Test suite failed to run
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/en/configuration.html
Details:
/Users/user/Documents/GitHub/ReadingRainbow/node_modules/react-native/index.js:13
import typeof AccessibilityInfo from './Libraries/Components/AccessibilityInfo/AccessibilityInfo';
^^^^^^
SyntaxError: Cannot use import statement outside a module
1 | import React from 'react';
> 2 | import { Image, View, Text, Button, TouchableOpacity, ScrollView} from 'react-native';
| ^
3 | import { globalStyles } from '../styles/global';
4 | import { useNavigation } from '#react-navigation/native';
5 |
at Runtime._execModule (node_modules/jest-expo/node_modules/jest-runtime/build/index.js:1157:58)
at Object.<anonymous> (screens/home.js:2:1)
at Object.<anonymous> (screens/__tests__/home.test.js:2:1)
I have also set up a clean, brand new project (following these directions first and these second) to test the compare the dependencies and such against my current project. The clean project runs as intended, including import/export statements. How do I correct and clean up my real project so that jest runs without error?
I have tried deleting the node_modules folder and running npm install to reestablish the dependencies. I have also tried adjusting the preset configurations for jest, the transformIgnorePatterns, and the preset defined in babel.config.js. The most helpful explanation I've been given so far is, "[this is probably not working because] node can't use imports (without transpiling) and jest is trying to render using node instead of a browser." Any help is sincerely appreciated! Please let me know if you need further information or clarification.
Example file:
// Intro.js
import React, {Component} from 'react';
import {StyleSheet, Text, View} from 'react-native';
const styles = StyleSheet.create({
container: {
alignItems: 'center',
backgroundColor: '#F5FCFF',
flex: 1,
justifyContent: 'center',
},
instructions: {
color: '#333333',
marginBottom: 5,
textAlign: 'center',
},
welcome: {
fontSize: 20,
margin: 10,
textAlign: 'center',
},
});
export default class Intro extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>Welcome to React Native!</Text>
<Text style={styles.instructions}>
This is a React Native snapshot test.
</Text>
</View>
);
}
}
Example test:
// __tests__/Intro-test.js
import React from 'react';
import renderer from 'react-test-renderer';
import Intro from './Intro';
test('renders correctly', () => {
const tree = renderer.create(<Intro />).toJSON();
expect(tree).toMatchSnapshot();
});
package.json of "clean" project
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject",
"test": "jest"
},
"dependencies": {
"expo": "~39.0.2",
"expo-status-bar": "~1.0.2",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-39.0.4.tar.gz",
"react-native-web": "~0.13.12"
},
"devDependencies": {
"#babel/core": "~7.9.0",
"jest-expo": "^39.0.0",
"react-test-renderer": "^17.0.1"
},
"jest": {
"preset": "jest-expo",
"transformIgnorePatterns": [
"node_modules/(?!(jest-)?react-native|react-clone-referenced-element|#react-native-community|expo(nent)?|#expo(nent)?/.*|react-navigation|#react-navigation/.*|#unimodules/.*|unimodules|sentry-expo|native-base|#sentry/.*)"
]
},
"private": true
}
package.json of my actual project
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"test": "jest",
"test:update": "jest --verbose --coverage --updateSnapshot",
"test:watch": "jest --verbose --watch",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject"
},
"dependencies": {
"#react-native-community/masked-view": "0.1.10",
"#react-navigation/native": "^5.8.2",
"#react-navigation/stack": "^5.11.1",
"axios": "^0.20.0",
"expo": "~39.0.2",
"expo-status-bar": "~1.0.2",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-39.0.2.tar.gz",
"react-native-dotenv": "^2.4.2",
"react-native-gesture-handler": "~1.7.0",
"react-native-reanimated": "~1.13.0",
"react-native-safe-area-context": "3.1.4",
"react-native-screens": "~2.10.1",
"react-native-testing-library": "^6.0.0",
"react-native-web": "~0.13.12",
"react-navigation-stack": "^2.10.0"
},
"devDependencies": {
"#babel/core": "~7.9.0",
"#babel/preset-env": "^7.12.1",
"#babel/preset-react": "^7.12.1",
"#testing-library/react": "^11.1.0",
"babel-jest": "^26.6.2",
"jest": "^26.6.2",
"jest-expo": "^39.0.0",
"react": "^17.0.1",
"react-navigation": "^4.4.3",
"react-test-renderer": "^17.0.1"
},
"jest": {
"preset": "jest-expo",
"transformIgnorePatterns": [
"node_modules/(?!(jest-)?react-native|react-clone-referenced-element|#react-native-community|expo(nent)?|#expo(nent)?/.*|react-navigation|#react-navigation/.*|#unimodules/.*|unimodules|sentry-expo|native-base|#sentry/.*)"
]
},
"private": true
}
babel.config.js
module.exports = function(api) {
api.cache(true);
return {
presets: ['babel-preset-expo'],
};
};
jest.config.json (non-existent in "clean" project)
{
"testRegex": "((\\.|/*.)(test))\\.js?$"
}
In your __tests__/Intro-test.js file, just above the test, mock your component like this
jest.mock('./Intro', () => './Intro');
The content of your file will look like this:
// __tests__/Intro-test.js
import React from 'react';
import renderer from 'react-test-renderer';
import Intro from './Intro';
jest.mock('./Intro', () => './Intro');
test('renders correctly', () => {
const tree = renderer.create(<Intro />).toJSON();
expect(tree).toMatchSnapshot();
});
I was facing the exact same problem. Mocking my components solved the issue. I hope it will help you too.
I am very new to React native I am trying to show content it is showing from starting. But I have
To show the content from the container, but I don't know how to apply this in React native. So
So someone please help me how to use container in React native.
In this component I tried some code please check it once
This is App.js
import React from 'react';
import {View, Text} from 'react-native';
const App = props => {
return (
<View>
<Text>Hi Mark</Text>
</View>
);
};
export default App;
These are the packages I installed in my React native project
{
"name": "testone",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"#react-native-community/masked-view": "^0.1.10",
"#react-navigation/native": "^5.3.2",
"#react-navigation/stack": "^5.3.6",
"react": "16.11.0",
"react-native": "0.62.2",
"react-native-gesture-handler": "^1.6.1",
"react-native-reanimated": "^1.8.0",
"react-native-safe-area-context": "^1.0.0",
"react-native-screens": "^2.7.0"
},
"devDependencies": {
"#babel/core": "7.9.6",
"#babel/runtime": "7.9.6",
"#react-native-community/eslint-config": "0.0.5",
"babel-jest": "24.9.0",
"eslint": "6.8.0",
"jest": "24.9.0",
"metro-react-native-babel-preset": "0.58.0",
"react-test-renderer": "16.11.0"
},
"jest": {
"preset": "react-native"
}
}
Note I am not using expo I am using pure React native for app development.
Add margin style property to root View to make it like container
import React from "react";
import { Text, View } from "react-native";
const App = () => {
return (
<View style={{ margin:100 }}>
<Text>Hi There!</Text>
</View>
);
};
export default App;
I am trying to make android application with react native.After creating project and install all dependencies i want to use use Hook inside navigator like this:
const MainNavigator = createStackNavigator({
Dashboard: DashboardScreen,
ListSurveyor: {
screen: topSurvayorsNavigator,
navigationOptions: ({ navigation }) => {
const dispatch = useDispatch();
const [term, setTerm] = useState('');
const searchServeyor = (item) => {
console.log('nav: ', item);
dispatch(survayouActions.searchSurveyouList(item))
}
switch (navigation.state.routes[navigation.state.index]["routeName"]) {
case "ActiveSurveyor":
return {
header: () => <CustomHeader
title='Active'
// term={term}
// onTermChange={setTerm}
onTermSubmit={searchServeyor}
/>
}
case "DeActiveSurveyor":
return {
header: () => <CustomHeader
title='DisActive'
onTermSubmit={searchServeyor}
/>
}
default:
return { title: (navigation.state.routes[navigation.state.index]["routes"])[(navigation.state.routes[navigation.state.index]["index"])].routeName }
}
}
},
Audited: AuditedFileNumSurveyor,
}, {
defaultNavigationOptions: defaultNavOptions
});
I imported useState and useDispatch like below:
import React, { useState } from 'react';
import { useDispatch } from "react-redux";
But When i run application i got this error:
Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons: 1. You might have mismatching versions of React and the renderer (such as React DOM) 2. You might be breaking the Rules of Hooks 3. You might have more than one copy of React in the same app See for tips about how to debug and fix this problem.
I used hook inside method navigationOptions: ({ navigation }) => { but what is happen?
This is package.json information:
{
"name": "RNMngm",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"base-64": "^0.1.0",
"prop-types": "^15.7.2",
"react": "16.9.0",
"react-native": "0.61.5",
"react-native-charts-wrapper": "^0.5.7",
"react-native-gesture-handler": "^1.5.2",
"react-native-paper": "^3.4.0",
"react-native-reanimated": "^1.4.0",
"react-native-svg": "^10.0.0",
"react-native-vector-icons": "^6.6.0",
"react-navigation": "^4.0.10",
"react-navigation-drawer": "^2.3.3",
"react-navigation-header-buttons": "^3.0.4",
"react-navigation-material-bottom-tabs": "^2.1.5",
"react-navigation-stack": "^1.10.3",
"react-navigation-tabs": "^2.7.0",
"react-redux": "^7.1.3",
"redux": "^4.0.5",
"redux-thunk": "^2.3.0"
},
"devDependencies": {
"#babel/core": "7.7.7",
"#babel/runtime": "7.7.7",
"#react-native-community/eslint-config": "0.0.5",
"babel-jest": "24.9.0",
"eslint": "6.8.0",
"jest": "24.9.0",
"metro-react-native-babel-preset": "0.56.3",
"react-test-renderer": "16.9.0"
},
"jest": {
"preset": "react-native"
}
}
Hooks can only be used in a component, and cannot be used in navigator or navigationOptions. If u need to use state in navigator or navigationOptions, u need to setParams in the component and then use the getParam method in navigationOptions
I'm building a react-native app using expo and I'm using the react native navigation library to navigate between pages and link my button to the next page but I've received an error. What do I need to change to get the pages up and to get the button (on the home page) linked to the second page?
Error: Unable to resolve "fbjs/lib/areEqual" from "node_modules\react-native-gesture-handler\createHandler.js".
UPDATE: Now shoring this error too: Unable to resolve "./Components/DatePicker.js" from "screens\Home.js" bus is it possible that it's not related to the datePicker? I think it's about the react-native-gesture-handler. Do I need to do anything specifically for Android if I'm using expo to navigate to different screens?
AppNavigator.js
import { createStackNavigator } from 'react-navigation';
import Home from './screens/Home';
import Plan from './screens/Plan'
const AppNavigator = createStackNavigator({
Home: { screen: Home },
Plan: { screen: Plan},
});
export default AppNavigator;
App.js
import React from 'react';
import AppNavigator from './AppNavigator';
export default class App extends React.Component {
render() {
return (
<AppNavigator/>
);
}
}
Package.json
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject"
},
"dependencies": {
"#unimodules/react-native-adapter": "^3.0.0",
"deep-equal": "^1.0.1",
"expo": "^34.0.1",
"expo-constants": "~6.0.0",
"expo-image-picker": "~6.0.0",
"expo-permissions": "~6.0.0",
"react": "16.8.3",
"react-dom": "^16.8.6",
"react-native": "https://github.com/expo/react-native/archive/sdk-34.0.0.tar.gz",
"react-native-calendar-select": "^0.1.2",
"react-native-datepicker": "^1.7.2",
"react-native-gesture-handler": "^1.3.0",
"react-native-image-picker": "^1.0.2",
"react-native-unimodules": "^0.5.3",
"react-native-web": "^0.11.4",
"react-navigation": "^3.11.1"
},
"devDependencies": {
"babel-preset-expo": "^6.0.0"
},
"private": true
}