0

Hi I want to create a card with Login and SignUp tabs with react native, I am using react native elements but dont know how to add a tab in the card, Here's of image of what I wantThing that I want to Implement

Talha Nadeem
  • 99
  • 1
  • 4
  • 22

1 Answers1

0

Maybe something like this would work

const AuthentificationCard = () => {
  // 0 = login || 1 = signIn
  const [cardstate, setcardState] = useState(0);

  return (
    <Card>
      <TouchableTab onPress={() => setcardState(0)}> login </TouchableTab>
      <TouchableTab onPress={() => setcardState(1)}> Signin </TouchableTab>

      {cardstate == 0 ? ( <LoginComponent/> ) : ( <SignInComponent/> )}
    </Card>
  );
}

OR with class based component

class AuthentificationCard extends Component {

  constructor(props) {
    super(props);
    this.state = {
      cardstate: 0,
    };
  }

  render() {
    return (
     <Card>
           <TouchableOpacity onPress={() => this.setState({ cardstate: 0})}> <Text>login</Text> </TouchableOpacity> 
           <TouchableOpacity onPress={() => this.setState({ cardstate: 1})}> <Text>SignIn</Text> </TouchableOpacity> 
           {this.state.cardstate == 0 ? ( <LoginComponent/> ) : ( <SignInComponent/> )}
    </Card>
    );
  }
}
  • There is no such thing as TouchableTab – Talha Nadeem Jul 15 '20 at 15:36
  • Yes, it is only an exemple. You can make setcardState(0)}> login the point was about conditionnal rendering whith state variable that change when the user tap the pressable Text (the tab) – Nicolas De Tiesenhausen Jul 15 '20 at 15:46
  • Okay How to call this function inside my main render method – Talha Nadeem Jul 15 '20 at 15:49
  • I edited my comment to show you. By the way you may learn about functionnal components : https://dev.to/danielleye/react-class-component-vs-function-component-with-hooks-13dg and react conditionnal rendering : https://fr.reactjs.org/docs/conditional-rendering.html it could help you :) – Nicolas De Tiesenhausen Jul 15 '20 at 15:56