0

I am beginner and creating first app in react-native. I have made it but stuck at one place. I just added a segment in header and hide/shown Login/Signup page in base of segment click, but the issue is with navigation, I have a button in login page but this is not working and throwing error. Here is my segment page Code

import React, { Component } from 'react'; import { Platform, StyleSheet, Text, ScrollView } from 'react-native'; 
import { Container, Header, Left,Button,Icon,Body,Title, Segment, View, Content } from 'native-base';
import Login from './login'; import Signup from './signup';

const forgot = (props) => ( 
  <View style={{
 flex:1,
 flexDirection:'row',
 justifyContent:'center',
 alignItems:'center'
 }} > 
   <Text style={{
   fontSize:17,justifyContent:'center'
   }}> 
   Register a new account 
   <Text/>
 <View>
)
export default class Choices extends Component{
  constructor(props) {
    super(props); 
    this.state = { seg: 1, login:1 }; 
    } 
    render() { 
    const { navigate } = this.props.navigation; 
    return ( <Header hasSegment style={{
    backgroundColor:'#ff9102'
    }} androidStatusBarColor="#ed8702" iosBarStyle="light-content"> 
    <Button transparent onPress={() => this.props.navigation.goBack()} >
    <Title>Login</Title> 
    <Segment style={{
  backgroundColor:'#F5FCFF',display:'flex',height:50}}> 
    <Button first active={this.state.seg === 1 ? true:false} onPress={()=>this.setState({seg:1,login:1})} style={{flex:1,justifyContent:'center',height:60}} >
    JOBSEEKER 
    </Button>
    <Button last active={this.state.seg === 2 ? true : false} onPress={() => this.setState({ seg: 2,login:2 })} style={{
    flex:1,
    justifyContent:'center',
    height:60}} > 
    EMPLOYER 
     </Button>
    {this.state.seg === 1 && } {this.state.seg === 2 && }

      </Content>
    </ScrollView>
    </Container>
);
} }

const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#F5FCFF', } });

Here is my Login Page Code import React, { Component } from 'react'; import { Platform, StyleSheet, Text, ScrollView } from 'react-native'; import { Container,Content,View,Button } from 'native-base'; import t from 'tcomb-form-native'; var _ = require('lodash'); const Form = t.form.Form; const stylesheet = _.cloneDeep(t.form.Form.stylesheet);

Form.stylesheet.textbox.normal.height = 50; Form.stylesheet.textbox.normal.marginBottom = 20; Form.stylesheet.textbox.normal.borderRadius = 30; Form.stylesheet.textbox.normal.paddingHorizontal = 30; Form.stylesheet.textbox.normal.borderWidth = 2; Form.stylesheet.textbox.normal.fontSize = 20; Form.stylesheet.textbox.normal.color = '#66747c';

var loginForm = t.struct({ email:t.String, password:t.String });

var formOptions = { 
  fields:{ 
    email:{ placeholder:'Email', }, 
    password:{ placeholder:'Password' }
  },
  auto:'none' 
}

export default class Login extends Component{
  constructor(props){ 
    super(props); 
    this.state = { seg: 1 };
  }
  render() { 
    alert(JSON.stringify(this.props)) 
    return ( 
      <View style={{flex:1,flexDirection:'row',justifyContent:'center',alignItems:'center'}}> <Button rounded={true} large={true} style={{
      backgroundColor:'#ff9102',
      paddingHorizontal:30,flex:1,justifyContent:'center'}} > 
      <Text style={{fontSize:27,color:'#fff'}}>Login <View style{{flex:1,flexDirection:'row',justifyContent:'center',alignItems:'center'}} 
      padder > 
      <Text style={{fontSize:17,justifyContent:'center'}}> Register a new account 
      <View style={{
      flex:1,flexDirection:'row',justifyContent:'center',alignItems:'center'}} padder > 
      <Button transparent onPress={()=>this.props.navigation.navigate('Forgot')} > <Text style={{fontSize:17,justifyContent:'center', color:'#ff9102'}}> 
      Forgot Password 
    ); 
  } 
}
const styles = StyleSheet.create(
{ 
container: { flex: 1, backgroundColor: '#F5FCFF', } })
;

Please help what I am doing wrong in this code.

Rajat Gupta
  • 1,864
  • 1
  • 9
  • 17
Ravi.K
  • 41
  • 1
  • 6
  • Can you tell us what error is it throwing? Will help with getting context of the problem – Nemi Shah Jun 30 '18 at 18:40
  • @NemiShah, I was switching between components of segments, and added button to component. But the button navigation not working. Look at Login.js file, there is button to call navigation, but it is not working. I had rendered it in segment., look at choices.js – Ravi.K Jun 30 '18 at 18:50
  • I meant what was the exact error message on the red screen or crash logs that you were getting, also with react navigation it is also important to know the code you used to create the navigator you are using, and you will be surprised with how much information the error log could give. – Nemi Shah Jun 30 '18 at 18:55
  • for NativeBase button, you need to wrap the text within ``. Also NativeBase `` is an implementation of React Native ``. You need to use only any one of them. See more examples of NativeBase segments on docs http://docs.nativebase.io/Components.html#segment-inside-header-headref – akhil xavier Jul 03 '18 at 06:34
  • So we cannot use scrollView and Content simultaneously? – Ravi.K Jul 04 '18 at 07:28

0 Answers0