I have tried clearing the expo cache with "expo start -c", still not working.
But it works on my App.js file, when i use the css styling on my HomeScreen File, it does not work.
**App.Js**
import * as React from 'react';
import { StatusBar } from 'expo-status-bar';
import { Text, View } from 'react-native';
import { NavigationContainer } from '#react-navigation/native';
import { createNativeStackNavigator } from '#react-navigation/native-stack';
import HomeScreen from './screens/HomeScreen';
const Stack = createNativeStackNavigator();
export default function App() {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="Home" component={HomeScreen} />
</Stack.Navigator>
</NavigationContainer>
);
}
**Homescreen.js file**
import { View, Text, SafeAreaView } from 'react-native';
import React, { useLayoutEffect } from 'react';
import { useNavigation } from '#react-navigation/native';
const HomeScreen = () => {
const navigation = useNavigation();
useLayoutEffect(() => {
navigation.setOptions({
headerShown: false,
});
}, []);
return (
<SafeAreaView>
<Text className="text-red-500"> HomeScreen </Text>
</SafeAreaView>
);
};
export default HomeScreen;
**Tailwind Config file**
/** #type {import('tailwindcss').Config} */
module.exports = {
content: [
"./App.{js,jsx,ts,tsx}",
"./screens/**/ *.{js,jsx,ts,tsx}",
"./pages/**/ *.{js,ts,jsx,tsx}",
"./components/**/ *.{js,ts,jsx,tsx}",
],
theme: {
extend: {},
},
plugins: [],
}
What i mean is that, I'm using NativewWind in my React-native App. Now after following all of the documentation. i tried using the css in the App.js which is the default home screen, It worked fine. But when i created a new screen (Home) and made it as my default screen after installation REACT NAVIGATION. Using the css on the Home screen isn't reflecting. Its simply not working. And i've done all of the solutions online (Clearing cache, restarting and all but still same result)
Related
I want to have a splash screen and a home screen that contains drawer.
I'm facing some issue here.
The below is my stack navigator.
import React from 'react';
import {createNativeStackNavigator} from '#react-navigation/native-stack';
import SplashScreen from '../Screens/SplashScreen';
import HomeScreen from '../Screens/HomeScreen';
import DrawerNavigator from './DrawerNavigator';
const Stack = createNativeStackNavigator();
const StackNavigator = () => {
return (
<Stack.Navigator>
<Stack.Screen name="Splash" component={SplashScreen} />
<Stack.Screen name="Home" component={DrawerNavigator} />
</Stack.Navigator>
);
};
export default StackNavigator;
The splashScreen
import React, {useState, useEffect} from 'react';
import {View, Text} from 'react-native';
const SplashScreen = ({navigation}) => {
const [splashScreen, setSplashScreen] = useState(true);
const hideSplashScreen = () => {
setSplashScreen(false);
};
useEffect(() => {
const interval = setTimeout(() => {
hideSplashScreen();
navigation.replace('Home');
}, 5000);
return () => {
clearTimeout(interval);
};
}, []);
const renderSplash = () => {
return (
<View style={{padding: 100}}>
<Text>Welcome</Text>
</View>
);
};
return <View>{splashScreen === true && renderSplash()}</View>;
};
export default SplashScreen;
DrawerNavigator
import React from 'react';
import {createDrawerNavigator} from '#react-navigation/drawer';
import HomeScreen from '../Screens/HomeScreen';
import {LogBox} from 'react-native';
LogBox.ignoreLogs([
"[react-native-gesture-handler] Seems like you're using an old API with gesture components, check out new Gestures system!",
]);
const Drawer = createDrawerNavigator();
const DrawerNavigator = () => {
return (
<Drawer.Navigator>
<Drawer.Screen name="HomeScreen" component={HomeScreen} />
</Drawer.Navigator>
);
};
export default DrawerNavigator;
HomeScreen
import React from 'react';
import {View, Text} from 'react-native';
const HomeScreen = () => {
return (
<View>
<Text>Hello!</Text>
</View>
);
};
export default HomeScreen;
App.js
import React from 'react';
import 'react-native-gesture-handler';
import {NavigationContainer} from '#react-navigation/native';
import StackNavigator from './navigation/StackNavigator';
import Icon from 'react-native-vector-icons/Ionicons';
Icon.loadFont().then();
const App = () => {
return (
<NavigationContainer>
<StackNavigator />
</NavigationContainer>
);
};
export default App;
On the homeScreen header of Stack navigation is shown up with title Home. Below that header of drawer Navigation is showing up.
I just want to see drawer on the home screen. How to achieve this? Am I doing it correctly?
I understand that you need to show a splash screen when the user enters the app.
What's wrong in it?
Splash screen should be shown when your app bundle & assets are loading. If you are mounting your splash screen inside the App component, the splash screen will be showing after the bundle and asset loading.
Recommended
Try to use react-native-splash-screen library.
Follow this blog
I am creating my app for my site with React Native and since I couldn't figure out how to fix the header from scrolling, I found the alternative method which is React Navigator 5.
However, in <Stack.Screen name="Home" component={Home} />, It doesnt show anything but for iPhone, there is only text that said "Home" from the above which is the name param from the Stack.Screen, it should have showed the list I got from the API i called since I have tested the FlatList showing before React Navigation:
Here is the code:
import React, { Component, useState, useEffect } from 'react';
import { Text, View, ScrollView, Image, Platform, TouchableHighlight, SafeAreaView, FlatList, StyleSheet } from 'react-native';
import { createDrawerNavigator } from '#react-navigation/drawer';
import { NavigationContainer } from '#react-navigation/native';
import { createStackNavigator } from '#react-navigation/stack';
const Stack = createStackNavigator();
function Main() {
return (
<SafeAreaView>
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen
name="Home"
component={Home} //Class component, Turning it to Function Component no luck for me to fix.
/>
</Stack.Navigator>
</NavigationContainer>
</SafeAreaView>
);
}
class Home extends Component {
constructor(props) {
super(props)
this.state = {
postlists: [],
postlistsnum: 0,
}
}
componentDidMount() {
this.SendAPI();
}
SendAPI() {
//any api get command here
}
postRow({ item }) {
return (
<View
style={PostListStyles.post}>
<Text>{item.title}</Text>
</View>
)
}
render() {
return (
<FlatList
data={this.state.postlists}
renderItem={this.postRow}
scrollEnabled={false}
style={{
marginTop: 50,
}}
/>
)
}
}
export default Main;
can you try export default instead of function Main() { only...
like this: export default functionMain() {
Also i think you should not put a SafeAreaView outside a NavigationContainer.. try putting the SafeAreaView inside the Home Class
Fixed:
index.js:
import {AppRegistry} from 'react-native';
import App from './App';
import Main from './Main'
import {name as appName} from './app.json';
AppRegistry.registerComponent(appName, () => Main); //switching from App to Main
also thank you for the answers!
Hi i 'm new to react native how to implement a drawer navigator in react native. Actually i'm following this doc
Updated:
code for home page is as follows
constructor(props){
super(props)
this.state= {
icon: null
}
}
render(){
return(
<Container>
<Header style={{backgroundColor:'pink'}} >
<Button
transparent
onPress= {() => this.props.navigation.navigate("DrawerOpen")}>
<Icon
style= {{color: '#ffffff', fontSize:25, paddingTop:0}}
name="bars"
/>
</Button>
</Header>
<Content>
</Content>
</Container>
);
}
}
also
index.js
import CourseListing from './CourseListing';
import SideBar from './SideBar/SideBar';
import {DrawerNavigator} from 'react-navigation';
import Profile from './Profile';
const MyHome =DrawerNavigator(
{
CourseListing: {screen: CourseListing},
Profile: {screen: Profile},
},
{
contentComponent: props => <SideBar {...props} />
}
);
I'm getting this error
In addition to the documentation which is great, I also recommend watching This video.
I would suggest creating a file called Router.js. It could look something like this:
import React from 'react';
import { DrawerNavigator } from 'react-navigation';
import Screens1 from ... // Import all your screens here
import Screens2 from ...
import Screens3 from ...
// The DrawerNavigator uses all the screens
export const MyDrawer = DrawerNavigator({
Screen1: { screen: Screen1 },
Screen2: { screen: Screen2 },
Screen3: { screen: Screen3 },
});
In your root (usually called App.js) make sure to import MyDrawer:
import React, { Component } from 'react';
import { MyDrawer } from '(correct path here)/Router.js';
export default class App extends Component {
render() {
return <MyDrawer />;
}
}
Now when the app starts Screen1 will be loaded. Each of the screens has a side menu because of the DrawerNavigator. To open the menu in any screen, use the following method:
_openMenu() {
this.props.navigation.navigate('DrawerOpen');
}
Hope this helps.
it's so, implement drawer such as stack-navgation
exmaple :
import { createDrawerNavigator } from 'react-navigation-drawer';
import {signIn,drawer} from 'scene'
const RouteConfigs = {
signIn
}
const DrawerNavigatorConfig = {
drawerPosition:'right',
drawerType:'front',
hideStatusBar:true,
contentComponent:drawer
}
export default createDrawerNavigator(RouteConfigs, DrawerNavigatorConfig);
the important part is contentComponent in DrawerNavigatorConfig. it's a view that shows in the drawer when it opens
import React, { Component } from "react";
import { Dimensions, StyleSheet, } from 'react-native';
import { createStackNavigator } from '#react-navigation/stack';
import { createDrawerNavigator } from '#react-navigation/drawer';
import color from '../../../constants/color'
import Attendance from '../../ExtraScreens/Attendance/Attendance'
import KIETDigitalDirectory from '../../ExtraScreens/KIETDigitalDirectory/KIETDigitalDirectory'
import KIETExtensions from '../../ExtraScreens/KIETExtensions/KIETExtensions'
import StudentRedressal from '../../ExtraScreens/StudentRedressal/StudentRedressal'
//
import Ticketing from '../../ExtraScreens/Ticketing/Ticketing'
import TicketingApply from '../../ExtraScreens/Ticketing/TicketingApply'
//
import Grievance from '../../ExtraScreens/EmployeeGrievance/Grievance'
import GrievanceApply from '../../ExtraScreens/EmployeeGrievance/GrievanceApply'
export default class Extra extends React.Component {
render() {
const Drawer = createDrawerNavigator();
return (
<Drawer.Navigator
drawerType="back"
// openByDefault
// overlayColor="transparent"
>
<Drawer.Screen name="KIET Extensions" component={KIETExtensions} />
<Drawer.Screen name="Grievance" component={GrievanceStack} />
<Drawer.Screen name="Ticketing" component={TicketingStack} />
<Drawer.Screen name="Student Redressal" component={StudentRedressal} />
<Drawer.Screen name="Attendance" component={Attendance} />
<Drawer.Screen name="KIET Digital Directory" component={KIETDigitalDirectory} />
</Drawer.Navigator>
)
}
}
const StackNavigator = createStackNavigator();
const GrievanceStack = (props) => (
<StackNavigator.Navigator
initialRouteName="Grievance"
mode="card"
headerMode="none"enter code here>
<StackNavigator.Screen name="Grievance" component={Grievance} />
<StackNavigator.Screen name="Grievance Apply" component={GrievanceApply} />
</StackNavigator.Navigator>
)
const TicketingStack = (props) => (
<StackNavigator.Navigator
initialRouteName="Ticketing"
mode="card"
headerMode="none"
>`enter code here`
<StackNavigator.Screen name="Ticketing" component={Ticketing} />
<StackNavigator.Screen name="Ticketing Apply" component={TicketingApply} />
</StackNavigator.Navigator>
)
I am creating an app in ReactNative and i got this issue. Following are the files containing code
index.js
import React from 'react';
import {AppRegistry} from 'react-native';
import Home from 'MobileApp/src/users/Home';
AppRegistry.registerComponent('MobileApp', () => App);
Home.js
import React, {Component} from 'react';
import { View,Button} from 'react-native';
import Profile from './Profile';
class Home extends Component{
onPressProfile(){
navigate('Profile', { name: 'Profile' })
}
render() {
return(
<View style={styles.viewStyle}>
<View style={styles.buttonStyle}>
<Button
onPress={this.onPressProfile}
title="Profile"
/>
</View>
</View>
);
}
}
const styles= {
viewStyle: {
flex: 1,
justifyContent: 'center',
},
};
export default Home;
Error is in my Home.js. what is the mistake?Thanks in advance.
In your index.js file, you should be using your Home component as entry point of your app.
Index.js
import React from 'react';
import {AppRegistry} from 'react-native';
import Home from 'MobileApp/src/users/Home';
AppRegistry.registerComponent('MobileApp', () => Home);
In your actual code, App is undefined.
You may have error on this line:
navigate('Profile', { name: 'Profile' })
need to define navigate to access it. Assuming you are learning from official documentation
const { navigate } = this.props.navigation;
And import navigation would be like:
import {
StackNavigator,
} from 'react-navigation';
const App = StackNavigator({
Home: { screen: HomeScreen },
Profile: { screen: ProfileScreen },
});
For further information how navigation works, check documentation
I'm using react navigation for my app development. When i run log-android, it keeps logging something like this.
Navigation Dispatch: Action: {...}, New State: {...}
which is from createNavigationContainer.js line 150.
I've run through github and document said it could be done by by setting onNavigationStateChange={null} on a top-level navigator.
How can i achieve this by setting onNavigationStateChange={null} and where should i set it?
I've try to set like below, but it the page will not be able to redirect to other page.
export default () => {
<App onNavigationStateChange={null} />
}
Below are my app.js code
import React, { Component } from 'react';
import { AppRegistry, StyleSheet, Text, View } from 'react-native';
import { StackNavigator,DrawerNavigator } from 'react-navigation';
import DrawerContent from './components/drawer/drawerContent.js';
import News from './components/news/home.js';
const drawNavigation = DrawerNavigator(
{
Home : {
screen : News ,
navigationOptions : {
header : null
}
}
},
{
contentComponent: props => <DrawerContent {...props} />
}
)
const StackNavigation = StackNavigator({
Home : { screen : drawNavigation,
navigationOptions: {
header: null
}
}
});
export default StackNavigation;
This is my drawerContent.js
import React, {Component} from 'react'
import {View,Text, StyleSheet,
TouchableNativeFeedback,
TouchableOpacity,
TouchableHighlight
} from 'react-native'
import { DrawerItems, DrawerView } from 'react-navigation';
import Icon from 'react-native-vector-icons/Octicons';
import MaterialIcons from 'react-native-vector-icons/MaterialIcons';
class DrawerContent extends Component {
constructor(props){
super(props);
console.log('DrawerContent|testtttttt');
}
render(){
return (
<View style={styles.container}>
<Text>Hi darren</Text>
<TouchableOpacity style={{ marginBottom:5 }} onPress={() => this.props.navigation.navigate('RegistrationScreen') } >
<View style={styles.nonIconButton}>
<Text style={{ color: 'black',fontSize: 13 }} >Sign Up</Text>
</View>
</TouchableOpacity>
<Text>Hi darren</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
});
export default DrawerContent;
First, make sure you are using the latest release of react-navigation as the comment noting that the fix was committed is fairly recent.
Based on your code example, to disable logging for all navigation state changes, you would want to replace this code:
export default StackNavigation;
with:
export default () => (
<StackNavigation onNavigationStateChange={null} />
);
as StackNavigation appears to be your root navigator.
React navigation is great, but this logging is really bad. Solution
const AppNavigator = StackNavigator(SomeAppRouteConfigs);
class App extends React.Component {
render() {
return (
<AppNavigator onNavigationStateChange={null} />
);
}
}