0

Holaa he hecho un pequeño login pero cuando intento la funcion de onPress en un touchableOpacity lo que hace en vez de yo pulsar el touchable y que aparezca en la consola , lo que hace es que al escribir se va mostrando cada letra cosa que no le he dicho que haga y hace pero luego pulso el touchable y nada aparece solo al escribir y me resulta muy raro cuando en ningun momento he refrenciado la funcion que hace el log a la funcion del onchangetext, aqui os comparto el codigo a ver si me podeis ayudar, gracias.

    import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View, TextInput, Button, TouchableOpacity } from 'react-native';
import React, { useState } from 'react';
import { Dimensions, Platform } from 'react-native';


const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
    width: '100%',
    fontSize: 25
  },
  containerLogin: {
    width: '33%',
    padding: '3%',
    display: 'flex',
    alignItems: 'center',
    borderRadius: 25,
    backgroundColor: 'powderblue'
  },
  containerLoginMobile: {
    width: '80%',
    display: 'flex',
    alignItems: 'center'
  },
  inputMobile: {
    textAlign: 'center',
    width: '100%',
    margin: 12,
    borderWidth: 1,
    padding: 10,
  },
  input: {
    textAlign: 'center',
    width: '100%',
    margin: 12,
    borderWidth: 1,
    padding: 10,
  },
  boton: {
    width: '100%',
    marginTop: '5%',
  },
  botonTexto: {
    fontSize: 25
  },
  tituloAzul: {
    color: 'navy'
  },
  h1: {
    fontSize: 35,
    fontWeight: 'bold',
    marginBottom: 10,
  },
  button: {
    backgroundColor: 'blue',
    paddingVertical: 12,

    borderRadius: 10,
    elevation: 3,
    width:'auto'
  },
  buttonText: {
    fontSize: 16,
    color: '#fff',
    alignSelf: 'center',
    textTransform: 'uppercase',
  },
});
const { width } = Dimensions.get('window');
const isMobile = width < 768;
const deviceType = isMobile ? 'Mobile' : 'Desktop';

const RegisterForm = () => {
  const [username, setUsername] = useState('');
  const [password, setPassword] = useState('');
  // const [email, setEmail] = useState('');

  const handleRegister = () => {
    // Código para enviar los datos del formulario
    console.log(username);
    //console.clear();
  };
  var inputPantalla = () => {
    if (deviceType == "Mobile") {
      return styles.inputMobile
    } else {
      return styles.input
    }
  }
  var containerLoginPantalla = () => {
    if (deviceType == "Mobile") {
      return styles.containerLoginMobile
    } else {
      return styles.containerLogin
    }
  }
  return (
    <View style={styles.container}>
      <View style={containerLoginPantalla()}>
        <Text style={StyleSheet.flatten([styles.tituloAzul, styles.h1])}> INCOES</Text>
        <Text>Ingeniería y Control de estacionamientos</Text>


        <TextInput
          style={inputPantalla()}
          placeholder="Usuario"
          value={username}
          onChangeText={(text) => setUsername(text)}
        />
        <TextInput
          style={inputPantalla()}
          placeholder="Contraseña"
          value={password}
          onChangeText={setPassword}
        />
        <View style={styles.boton}>
          {/* <Button title="Entrar" onPress={handleRegister} style={styles.boton} titleStyle={styles.botonTexto}/> */}
          <TouchableOpacity style={styles.button} onPress={handleRegister()}>
            <Text style={styles.buttonText}>Login</Text>
          </TouchableOpacity>
        </View>
      </View>
    </View>
  );
};

export default RegisterForm;

1 respuesta 1

0

el problema era que en handler del onPress le ponia los parentesis al final del nombre de la funcion y no es asi, es sin los parentesis

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.