I'm trying 'DrawerLayoutAndroid' in react native with inside the drawer I added the react-navigation 'stackNavigator' to navigate between screen.What I'm trying to do
but the problem is when I navigate it opens in the drawer
How do I open it full screen as a normal page
Is there a better method to achieve this
(redux state ?)
Thank you in advance
I found a solution
what I did is created a routing page and added it as the root component
routes.js
import Main from '../screens/main';
import Ad from '../screens/adView';
export const AdNav = StackNavigator({
Home:{screen:Main,
navigationOptions:{
header:null,
}
},
Ad:{screen:Ad,
navigationOptions:{
title:'Details',
}}
}
);
App.js
import {AdNav} from './src/config/routes';
export default class App extends Component<{}> {
render() {
return (
<View style={styles.container}>
<AdNav />
</View>
);
}
}
Then I added DrawerLayoutAndroid to the main screen
inside the drawer layout I used stackNavigator to navigate with no issues
main screen with DrawerLayoutAndroid
render() {
var navigationView = (
<View style={{flex: 1}}>
<Button onPress={()=>this.props.navigation.navigate('Ad')} title="go to next page"/>
</View>
);
return (
<DrawerLayoutAndroid
drawerWidth={300}
drawerPosition={DrawerLayoutAndroid.positions.Left}
renderNavigationView={() => navigationView}>
<View style={styles.container}>
{/*content*/}
</View>
</DrawerLayoutAndroid>
);
}
}
Related
I dont know what to do here i've tried stack navigator also same issue with props ;/
Enter Screen
...
export default function App(props) {
return (
<View style={{flex:1 , justifyContent:'center', alignItems:'center'}}>
<TouchableOpacity onPress={()=>{
console.log(props)
this.props.navigation.navigate('Home')
//this.props.navigation.dispatch(SwitchActions.jumpTo('Home'))
} } >
<Text>switch test</Text>
</TouchableOpacity>
</View>
);
}...
Navigation
...
const SwitchNavigation = createStackNavigator({
Enter:{screen : EnterScreen},
Home:{ screen :HomeScreen}
})...
export default createAppContainer(SwitchNavigation);
APP
...
export default function App(props) {
return (
<NavigaitonScreens />
);
}...
It has nothing to do with navigation.
There is No this in functional-component ...
access props directly like props.navigation.navigate('Home')
I'm having problem with custom drawer navigator. all the methods on internet address lower versions of react navigation which do not work anymore.
here's my code
import { createAppContainer,DrawerItems } from 'react-navigation';
import HomeScreen from './screens/HomeScreen';
import SettingsScreen from './screens/SettingsScreen';
import {SafeAreaView,ScrollView,Dimensions,View} from 'react-native';
const MyDrawerNavigator = createDrawerNavigator({
Home: HomeScreen,
Settings: SettingsScreen,
},{
contentComponent:CustomDrawerComponent,
})
const CustomDrawerComponent = (props) => {
<SafeAreaView style={{flex:1}}>
<View>
<Image source={{'uri' : 'https://cdn.pixabay.com/photo/2017/08/30/01/05/milky-way-2695569_960_720.jpg'}} />
</View>
<ScrollView>
<DrawerItems {...props} />
</ScrollView>
</SafeAreaView>
}
const AppContainer = createAppContainer(MyDrawerNavigator);
export default AppContainer;
the code works fine without custom drawer. but when i add custom drawer the links on the sidebar do not appear. the side bar is empty.
You need to change your import to import from react-navigation-drawer.
If you're using react-navigation-drawer 1.x:
import { DrawerItems } from 'react-navigation-drawer';
If you're using react-navigation-drawer 2.x, use DrawerNavigatorItems instead:
import { DrawerNavigatorItems as DrawerItems } from 'react-navigation-drawer';
Always read the official docs: https://reactnavigation.org/docs/en/drawer-navigator.html#providing-a-custom-contentcomponent
Instead of using this
const CustomDrawerComponent = (props) => {
<SafeAreaView style={{flex:1}}>
<View>
<Image source={{'uri' : 'https://cdn.pixabay.com/photo/2017/08/30/01/05/milky-way-2695569_960_720.jpg'}} />
</View>
<ScrollView>
<DrawerItems {...props} />
</ScrollView>
</SafeAreaView>
}
i created a new react component
class CustomDrawerComponent React.Componect{
render(){
return(
<SafeAreaView style={{flex:1}}>
<View>
<Image source={{'uri' : 'https://cdn.pixabay.com/photo/2017/08/30/01/05/milky-way-2695569_960_720.jpg'}} />
</View>
<ScrollView>
<DrawerItems {...props} />
</ScrollView>
</SafeAreaView>
)
}
}
this worked
I am mapping array to component.
{this.state.forms.map((data)=><Box data={data} />)}
and the code for component Box is
import React,{Component} from 'react'
import {View,Text,ScrollView,Image,Button,StyleSheet,AsyncStorage} from 'react-native'
class Login extends Component{
constructor(props){
super(props)
this.state = {
forms:[],
}
this.onSetCompany = this.onSetCompany.bind(this)
}
onSetCompany(data){
console.log(data)
// AsyncStorage.setItem('Company',data);
this.props.navigation.navigate('CompanyDeatails')
}
render(){
return(
<View style={style.container}>
{console.log(this.props.data)}
<View style={style.box}>
<View style={style.box1}>
<Text style={style.row2}>{this.props.data.CompanyName} bkb</Text>
</View>
<View style={style.box3}>
<Text style={style.row2}>{this.props.data.LastDate} </Text>
</View>
</View>
<View style={style.buttonBox}>
<View style={style.button}>
<Button color="#6d5d17" title="Fill" onPress={()=>this.props.navigation.navigate('CompanyDeatails')}></Button>
</View>
</View>
</View>
)
}
}
export default Login
var style = StyleSheet.create({
.....
})
and my Routes
export default class App extends Component{
render(){
return(
<Links />
)
}
}
const Links = DrawerNavigator({.....,
CompanyDeatails:{screen:CompanyDeatails},
....,
},{contentComponent:props => <Slider {...props}/>
})
When i Map array to Box then navigation in that box is not working.I have working navigation to which are working on my rest of app but not in this particular component.
Like
in login.js, I have this.props.navigation.navigate('C1')
Which is working but when I paste same line in Box component it throw error.
Can not read property navigate of undefined
If Box component is not part of navigator then, you should wrap it within withNavigation function inorder to access the navigation object. Take a look at the doc here
Consider the following example
import React from 'react';
import { withNavigation } from 'react-navigation';
class Box extends React.Component {
...
render() {
...
}
}
export default withNavigation(Box);
Now, within the Box component, you can access this.props.navigation.navigate function.
Hope this will help!
I am using Redux for other purposes, and I was wondering if is possible using standard React-Navigation with no integration in redux just registering the screens and using this.props.navigation.navigate as a function to navigate
This is in App.js
export default class App extends Component {
render() {
const Navigation = StackNavigator({
Home: {screen: Home },
Page: {screen: Page },
});
return (
<Provider store={store}>
<Home />
</Provider>
);
}
}
and this is in home.js
<Button transparent style={{position: 'absolute', top: 0}} onPress={() => this.props.navigation.navigate("Page")}>
<Text style={{ color: '#403f3f' }}>10</Text>
</Button>
Pressing on the button I get 'undefined is not an object(evaluate this.props.navigation.navigate)'
Yes, but you have to render the whole StackNavigation, in your case <Navigation/> instead of <Home/>.
I am just React Native beginner.I have just created NavigatorDrawer with classes Home.js and Team.js.I have just added toolbar but it's not displaying. Can anyone look at my code and help me where I have done a mistake.
Home.js
const { navigate } = props.navigation;
return (
<ToolbarAndroid
title='Home'
style={styles.toolbar}
titleColor='white'
/>
<View>
<Text style={styles.abt}Home</Text>
</View>
);
index.android.js:
render()
{
const { navigation } =this.props;
return (
<Home navigation={ navigation }/> );
}
}
const App =DrawerNavigator({
Home:{screen:Home},
Team :{ screen: Team},
Wallpapers:{screen: Wallpapers},
});