I just started React Native development, installed Expo, created an app (works), installed react-navigation and tried the first StackNavigator example using the example from https://reactnavigation.org/docs/intro/. I am running npm run ios from the commandline, and using Nuclide IDE. All of which are completely new to me.
The problem is, that on running the example the screen in the iOS emulator shows this:
Instead of showing a title bar with 'Welcome' on it.
As a beginner I have no clue where to go from here. Here's my package.json:
{
"name": "rnproject",
"version": "0.1.0",
"private": true,
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-preset-flow": "^6.23.0",
"flow-bin": "0.42.0",
"jest-expo": "~1.0.1",
"react-native-scripts": "0.0.30",
"react-test-renderer": "16.0.0-alpha.6"
},
"main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
"scripts": {
"start": "react-native-scripts start",
"eject": "react-native-scripts eject",
"android": "react-native-scripts android",
"ios": "react-native-scripts ios",
"test": "node node_modules/jest/bin/jest.js --watch"
},
"jest": {
"preset": "jest-expo"
},
"dependencies": {
"expo": "^17.0.0",
"react": "16.0.0-alpha.6",
"react-native": "^0.44.0",
"react-navigation": "^1.0.0-beta.11"
}
}
there's an app.json file with these contents:
{
"expo": {
"sdkVersion": "17.0.0"
}
}
I also added flow, which throws me no errors in the example code, but 115 errors in the react-navigation package. Most of them look like: identifier 'expect', could not resolve name.
In the end I found the answer here: To use the examples on reactnavigation.org in Expo XDE, you have to make some changes. Here are the changes necessary for the first example:
import Expo from 'expo'; // <--- include this line
import React from 'react';
import {
AppRegistry, // <- remove this line
Text,
} from 'react-native';
import { StackNavigator } from 'react-navigation';
class HomeScreen extends React.Component {
static navigationOptions = {
title: 'Welcome',
};
render() {
return <Text>Hello, Navigation!</Text>;
}
}
const SimpleApp = StackNavigator({
Home: { screen: HomeScreen },
});
// change the following line:
AppRegistry.registerComponent('SimpleApp', () => SimpleApp);
// into:
Expo.registerRootComponent(SimpleApp);
Related
Tailwind CSS in the native wind is not being applied on Screen components.
Is there any package or dependency that is missing in my project .
This is a package.json
{
"name": "first-app",
"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": {
"#react-navigation/native": "^6.0.13",
"#react-navigation/native-stack": "^6.9.1",
"expo": "~46.0.13",
"expo-status-bar": "~1.4.0",
"nativewind": "^2.0.11",
"react": "18.0.0",
"react-native": "0.69.6",
"react-native-safe-area-context": "4.3.1",
"react-native-screens": "~3.15.0"
},
"devDependencies": {
"#babel/core": "^7.12.9",
"tailwindcss": "^3.2.0"
},
"private": true
}
Tailwind CSS is Applied on App.js but on screens components
import { StatusBar } from 'expo-status-bar';
import { NavigationContainer } from '#react-navigation/native';
import { createNativeStackNavigator } from '#react-navigation/native-stack';
import HomeScreen from './screens/HomeScreen';
export default function App() {
const Stack = createNativeStackNavigator();
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="Home" component={HomeScreen} />
</Stack.Navigator>
</NavigationContainer>
);
}
This is Screen Component where native wind ( tailwind ) is not Applied
import { View, Text } from 'react-native'
import React from 'react'
const HomeScreen = () => {
return (
<View className="flex-1 text-center align-middle justify-center">
<Text className="bg-black text-white">App</Text>
</View>
)
}
export default HomeScreen
Firstly my tailwind.config.js Looks like this
module.exports = {
content: ["./App.{js,jsx,ts,tsx}", "./components/**/*.{js,jsx,ts,tsx}", "./screens/**/*.{js,jsx,ts,tsx}"],
theme: {
extend: {},
},
plugins: [],
}
Then I CHANGED IT WITH FOLLOWING CODE. THE MAIN CHANGE WAS IN content part. By applying the above change tailwindcss started applying both in screens and components. This worked for me
module.exports = {
content:[
"./screens/**/*.{js,jsx,ts,tsx}",
"./pages/**/*.{js,jsx,ts,tsx}",
"./components/**/*.{js,jsx,ts,tsx}",
],
theme: {
extend: {},
},
plugins: [],
};
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}/>,
}
}
When I Press Back Button(In the stack header) or swipe left to right in a physical iPhone device my react native app crashes. The App is working fine in the simulator but not in a physical device.
So, how can I fix this issue?
Here is the code for my main navigator
import { themeColor, themeColorLite } from "../styles/common";
import Login from "../views/Login"
import ForgetPass from "../views/forgetPass"
import Registration from "../views/Registration"
import UserDashboard from "../views/user/dashboard"
import ProductDetails from "../views/user/productDetails"
import ShoppingMall from "../views/user/shoppingMalls"
import Shops from "../views/user/shops"
import NormalProducts from "../views/user/normalProducts"
import ShoppingCart from "../views/user/shoppingCart"
import UserProfile from "../views/user/profile"
import { createSwitchNavigator, createAppContainer } from 'react-navigation'
import { createStackNavigator } from 'react-navigation-stack'
import { createDrawerNavigator } from 'react-navigation-drawer'
import UserDrawerNav from '../views/drawerNav'
const ProductStackNavigator = createStackNavigator({
UserDashboard: UserDashboard,
ProductDetails: ProductDetails,
ShoppingCart: ShoppingCart,
ShoppingMall: ShoppingMall,
Shops: Shops,
NormalProducts: NormalProducts
})
const DrawerNavigator = createDrawerNavigator(
{
UserDashboard: ProductStackNavigator,
ShoppingMall: ProductStackNavigator,
UserProfile: UserProfile
},
{
contentComponent: UserDrawerNav,
hideStatusBar: true,
drawerBackgroundColor: 'white',
overlayColor: themeColorLite,
contentOptions: {
activeTintColor: '#fff',
activeBackgroundColor: themeColor,
}
}, {
unmountInactiveRoutes: true
}
);
const AuthStack = createSwitchNavigator({
Login: { screen: Login } ,
Registration: { screen: Registration } ,
ForgetPass: { screen: ForgetPass }
});
const AppContainer = createAppContainer(createSwitchNavigator(
{
App: DrawerNavigator,
Auth: AuthStack
},
{
initialRouteName: 'Auth',
}
));
export default AppContainer;
Here is my package.json
{
"name": "ENC",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"ipadAir": "react-native run-ios --simulator 'iPad Air (3rd generation)'",
"start": "react-native start",
"iphone11": "react-native run-ios --simulator 'iPhone 11'",
"cleanStart": "react-native start --reset-cache",
"link": "react-native link",
"podInstall": "cd ios && pod install && cd ..",
"podUpdate": "cd ios && pod update && cd ..",
"upgradeRN": "react-native upgrade",
"regenDir": "react-native upgrade --legacy true",
"test": "jest"
},
"dependencies": {
"#react-native-community/async-storage": "^1.6.1",
"axios": "^0.19.0",
"react": "16.10.1",
"react-native": "0.61.2",
"react-native-flip-card": "^3.5.5",
"react-native-fs": "^2.14.1",
"react-native-gesture-handler": "^1.4.1",
"react-native-image-picker": "^1.1.0",
"react-native-photo-upload": "^1.3.0",
"react-native-really-awesome-button": "^1.4.2",
"react-native-reanimated": "^1.2.0",
"react-native-tiny-toast": "^1.0.3",
"react-native-webview": "^7.4.0",
"react-native-xml2js": "^1.0.3",
"react-navigation": "^4.0.5",
"react-navigation-drawer": "^2.2.1",
"react-navigation-stack": "1.5.1"
},
"devDependencies": {
"#babel/core": "^7.5.0",
"#babel/runtime": "^7.5.0",
"#react-native-community/eslint-config": "^0.0.5",
"babel-jest": "^24.1.0",
"jest": "^24.1.0",
"metro-react-native-babel-preset": "^0.56.0",
"react-test-renderer": "16.10.1"
},
"jest": {
"preset": "react-native"
}
}
The above code is also available at my gist here
Finally found the solution after profiling the issue in xcode
this solution is work for me fine :
https://github.com/kmagiera/react-native-gesture-handler/issues/320#issuecomment-447534290
I'm developing iOS application with React Native and using Icon from native-base in the navigation bar.
However, some icons are not shown up as the icon I expected there.
This is my code.
import React, { Component } from 'react';
import {
View,
Text,
} from 'react-native';
import { Icon } from 'native-base';
export default class HomeTab extends Component {
static navigationOptions = {
tabBarIcon: ({tintColor}) => (
<Icon name='md-add-circle-outline' style={{color: tintColor}} />
)
};
render() {
return (
<View>
<Text>
HomeTab
</Text>
</View>
)
}
}
This code is supposed to show up the icon below.
https://gyazo.com/b9a19f8de26261cb62e834cd7a0ca867
But, in fact, the icon below is shown up.
https://gyazo.com/5476d5b168f51014038470d85381c9e9
This is, I think, the icon reference site.
And this is my package.json.
{
"name": "Sample",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"native-base": "^2.12.1",
"react": "16.8.6",
"react-native": "0.59.7",
"react-native-gesture-handler": "^1.2.1",
"react-native-vector-icons": "^6.4.2",
"react-navigation": "^3.9.1"
},
"devDependencies": {
"#babel/core": "7.4.4",
"#babel/runtime": "7.4.4",
"babel-jest": "24.8.0",
"jest": "24.8.0",
"metro-react-native-babel-preset": "0.54.0",
"react-test-renderer": "16.8.6"
},
"jest": {
"preset": "react-native"
}
}
In Icon component also specify type component, most of the time it works but sometimes it gives error.
type is the name of the font, eg: 'AntDesign', 'MaterialCommunityIcons', etc
you can search for almost all icons here
I have an old React Native project, now i want to run it with Expo. The problem is Expo software stuck at “waiting for package and tunnel to start” when i try to use Expo to open the project and start it. I am working on MacOS with watchman already installed.
Here's the structure of my project
My app.json:
{ "name": "myapp", "displayName": "myApp", "expo": { "sdkVersion": "28.0.0" } }
package.json:
{
"name": "MyApp",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"expo": "^28.0.0",
"react": "15.4.1",
"react-native": "0.42.0",
"react-native-calendar-strip": "^0.1.4",
"react-native-check-box": "^1.0.4",
"react-native-checkbox": "^1.1.0",
"react-native-code-push": "1.17.0-beta",
"react-native-collapsible": "0.8.0",
"react-native-datepicker": "^1.6.0",
"react-native-fetch-blob": "0.10.6",
"react-native-image-picker": "0.26.2",
"react-native-keyboard-aware-scroll-view": "^0.2.9",
"react-native-modal-picker": "0.0.16",
"react-native-modalbox": "1.3.9",
"react-native-pdf": "1.2.4",
"react-native-picker": "4.0.18",
"react-native-signature-pad": "git+https://github.com/silverspace/react-native-signature-pad/#greg/android_blank_workaround",
"react-native-simple-store": "^1.2.0",
"react-native-vector-icons": "4.0.1",
"react-navigation": "1.0.0-beta.7",
"react-redux": "5.0.3",
"realm": "2.11.0",
"redux": "3.6.0",
"redux-logger": "2.8.2",
"redux-thunk": "2.2.0",
"tipsi-stripe": "3.2.0"
},
"devDependencies": {
"babel-jest": "19.0.0",
"babel-preset-react-native": "1.9.1",
"jest": "20.0.4",
"react-test-renderer": "15.4.1"
},
"jest": {
"preset": "react-native"
}
}
index.ios.js and and index.android.js have the same code: import './App';
Here's my App.js:
import React from 'react';
import {
AppRegistry,
Text,
View,
Button,
AppState,
DeviceEventEmitter
} from 'react-native';
import { BackAndroid } from 'react-native'
import { NavigationActions, StackNavigator } from 'react-navigation';
// Redux
import { Provider } from 'react-redux'
import store from './app/store'
import codePush from 'react-native-code-push';
import HomeNavigation from './app/Home/screens/HomeNavigation'
import simpleStore from 'react-native-simple-store';
import { HOST } from './app/Common/constants';
const GET_USER_URL = `${HOST}/api/user`;
let codePushOptions = {
checkFrequency: codePush.CheckFrequency.ON_APP_RESUME,
installMode: codePush.InstallMode.ON_NEXT_RESUME
};
class App extends React.Component {
//Doing something here...
render(){
return(
<Provider store={store}>
<HomeNavigation />
</Provider>
)
}
}
export default CodePushApp = codePush(codePushOptions)(App);
AppRegistry.registerComponent('MypApp', () => CodePushApp);
I have try to install Expo on a Window PC but still have the same issues when try to run this project.
I know this is late but if you have already installed expo-cli then try changing the scripts section of your package.json file to the following
"scripts": {
"start": "expo start",
"eject": "expo eject",
"android": "expo start --android",
"ios": "expo start --ios",
"test": "jest"
}
This worked for me