I can't see the button and my text input doesn't work in my react native expo app


Edward Cullen

I am building a login screen. I am completely new to it. I am using a grid view with the help of google to put my 3 buttons in one row. Here is my code:

import { StatusBar } from 'expo-status-bar';
import React, {useState,useEffect, Component} from "react";
import { StyleSheet, Text, View, TextInput, TouchableOpacity } from 'react-native';

export class GridView extends Component {

  render() {
    return (
       <View style={styles.container}>
          <View style={styles.buttonContainer}>
            <Button title="Button 1"/>
          </View>

          <View style={styles.buttonContainer}>
            <Button title="Button 2"/>
          </View>
          <View>
            <TouchableOpacity>
              <Text style={style.Email_btn}>
                Email
              </Text>
            </TouchableOpacity>
          </View>
      </View>
    );
   }
   }
   export default function App() {
     const [email, setEmail] = useState('');
     const [password, setPassword] = useState('');
     return (
      <View style={styles.container}>
      <Text style={{color:'#ffffff', fontSize:28}}>LOG IN</Text>
      <StatusBar style="auto" />
      <View style={styles.inputView}>
    <TextInput
      style={styles.TextInput}
      autoCapitalize="none"
      placeholder="Email."
      placeholderTextColor="#003f5c"
      onChangeText={(email) => setEmail(email)}
    />
  </View>
    
  <View style={styles.inputView}>
    <TextInput
      style={styles.TextInput}
      placeholder="Password."
      placeholderTextColor="#003f5c"
      secureTextEntry={true}
      onChangeText={(password) => setPassword(password)}
    />
  </View>

  </View>
  );
  }

  const styles = StyleSheet.create({
  container: {
     flex: 1,
     flexDirection: 'row',
     alignItems: 'center',
     justifyContent: 'center',
  },
  buttonContainer: {
     flex: 1,
  },
      Email_btn:{
      backgroundColor:"#1c313a",
      width:30,
      height:80,
     },
     container: {
    flex: 2,
    backgroundColor: '#455a64',
    /*alignItems:'flex-start',
   justifyContent: 'center'*/
   },



   inputView: {
   backgroundColor: '#1c313a',
   borderRadius: 30,
   width: "70%",
   height: 45,
   marginBottom: 20,

   alignItems: "center",
   },

   TextInput: {
   height: 50,
   flex: 1,
   padding: 10,
   marginLeft: 20,
  }
 });

The buttons in the grid view class should appear in the same row. Below them there should be email and password text inputs. I can't see the button on the screen and my text input is not getting the text from the user. please help me! !

Lakshman Kambam

You add flexDirection:'row'a container view to your app. This means that everything you add to it will be displayed horizontally.

You are not there <GridVieweither App.

You need to cross-check the styles that affect most of the layout.

enter image description here

Here's a snippet modified for you.

import React, {useState, Component} from "react";
import { StatusBar, Button, StyleSheet, Text, View, TextInput, TouchableOpacity } from 'react-native';

export class GridView extends Component {
  render() {
    return (
       <View style={styles.btnContainer}>
          <View style={styles.button}>
            <Button color={'white'} title="Button 1"/>
          </View>
          <View style={styles.button}>
            <Button color={'white'} title="Button 2"/>
          </View>
          <View style={[styles.button, styles.emailBtnWrap]}>
            <TouchableOpacity>
              <Text style={styles.emailBtn}>
                Email
              </Text>
            </TouchableOpacity>
          </View>
      </View>
    );
   }
}

export default function App() {
  const [email, setEmail] = useState('');
  const [password, setPassword] = useState('');
    return (
    <View style={styles.containerWrap}>
      <StatusBar />
      <View style={styles.textCenter}>
        <Text style={styles.textColor}>LOG IN</Text>
      </View>
      <View style={styles.formContainer}>
        <View style={styles.inputView}>
          <TextInput
            autoCapitalize="none"
            placeholder="Email."
            placeholderTextColor="#003f5c"
            onChangeText={(email) => setEmail(email)}
          />
        </View>
        <View style={styles.spacing12} />
        <View style={styles.inputView}>
          <TextInput
            placeholder="Password."
            placeholderTextColor="#003f5c"
            secureTextEntry={true}
            onChangeText={(password) => setPassword(password)}
          />
        </View>
      </View>
      <GridView />
    </View>
  );
}

const styles = StyleSheet.create({
  containerWrap: {
     flex: 1,
  },
  textCenter: {
    flex:1,
    alignItems: 'center',
    justifyContent: 'center'
  },  
  textColor: {
    color:'#000', 
    fontSize:28
  },
  formContainer: {
    flex:1,
    padding:12
  },
  inputView: {
    backgroundColor: '#f9f9f9',
    borderRadius: 30,
    borderWidth:1,
    borderColor: '#ccc',
    paddingVertical:16,
    paddingHorizontal:12
  },
  spacing12: {
    marginVertical:12
  },

  btnContainer: {
    flexDirection: 'row'
  },
  button: {
    flex:1,
    backgroundColor:'blue',
    padding:12
  },
  emailBtnWrap: {
    backgroundColor:'green'
  },
  emailBtn: {
    color:'white'
  },
  btnColor: {
    color:'white'
  }

 });

Related


react-native-file-viewer doesn't work in my app

ED I try to use react-native-file-viewer in my app to view à pdf file. I have imported the lib like this:import FileViewer from 'react-native-file-viewer'; And I have à function: getPdf(){ const path = '../images/Charte.pdf'; FileViewer.open(pa

react-native-file-viewer doesn't work in my app

ED I try to use react-native-file-viewer in my app to view à pdf file. I have imported the lib like this:import FileViewer from 'react-native-file-viewer'; And I have à function: getPdf(){ const path = '../images/Charte.pdf'; FileViewer.open(pa

Routing doesn't work on load on my react native app

username I'm working on a React native project with a login system using Firebase. The login system works normally. I also managed to capture the current user id from Firebase. I tried setting "stay logged in" with the asyncStorage system and current user id.

react-native-file-viewer doesn't work in my app

ED I try to use react-native-file-viewer in my app to view à pdf file. I have imported the lib like this:import FileViewer from 'react-native-file-viewer'; And I have à function: getPdf(){ const path = '../images/Charte.pdf'; FileViewer.open(pa

react-native-file-viewer doesn't work in my app

ED I try to use react-native-file-viewer in my app to view à pdf file. I have imported the lib like this:import FileViewer from 'react-native-file-viewer'; And I have à function: getPdf(){ const path = '../images/Charte.pdf'; FileViewer.open(pa

Routing doesn't work on load on my react native app

username I'm working on a React native project with a login system using Firebase. The login system works normally. I also managed to capture the current user id from Firebase. I tried setting "stay logged in" with the asyncStorage system and current user id.

Share button doesn't work in my app

User 8936954 I created a simple website app using webview in android studio and gave it internet access and also enabled java script on the app When I added WhatsApp share button using this code <button> <a href="whatsapp://send?text=HERE GOES THE URL ENCODED

Expo app IPA doesn't work on my iphone

Julian Wazniak I've created an app in React Native and Expo and I want to generate APK and IPA files. So I used: exp build:android exp build:ios I don't have any problem with the APK file, it works fine on my Android. Unfortunately, I have more problems with

Fontawesome doesn't work in my React app

Dinosaur I installed font-awesome via npm. "dependencies": { "@fortawesome/fontawesome-svg-core": "^1.2.15", "@fortawesome/free-solid-svg-icons": "^5.7.2", "@fortawesome/react-fontawesome": "^0.1.4", "axios": "^0.18.0",

my button doesn't work

Merlin This is the main activity where i click the button public class NewAddMarketingProg extends Activity implements OnClickListener { private StartAppAd startAppAd; String note_detail; ListView lvNote; String[] data; private int m

my button doesn't work

Merlin This is the main activity where i click the button public class NewAddMarketingProg extends Activity implements OnClickListener { private StartAppAd startAppAd; String note_detail; ListView lvNote; String[] data; private int m

I can't use Expo to test my app in iOS

Carlos Adriano I have some issues when I try to run my app on a phone with iOS, but not on Android. I am coding in Sublime Text, not XDE and executing my project in terminal, using commands npm startand reading QR codes. I am coding in Windows 10. I usecreate-