Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

the Keyboard is not staying up (losing focus after each key) - TextInput

$
0
0

Here below can you see the code that I have, now this code is part of a much bigger project, but I am wondering if you guys can see anything that would make it lose focus, or if you can by any chance tell me what I could do so that the keyboard stays up

import React, {Component, useState,useEffect } from 'react';import {Button,SafeAreaView,StyleSheet, View, TextInput, Text} from 'react-native';import {  Onfido,  OnfidoCaptureType,  OnfidoCountryCode,  OnfidoDocumentType,} from '@onfido/react-native-sdk';import {createApplicant, createCheck, createSdk} from '../../services/callToBackend';import CountrySelectDropdown from '../../services/CountrySelector/countrySelectDropDown';import getCountryISO3 from "country-iso-2-to-3";import { withNavigation } from 'react-navigation';const styles = StyleSheet.create({  input: {    height: 40,    margin: 12,    borderWidth: 1,  },});const OnFidoSDK = ({navigation}) => {  const [firstName, setFirstName] = useState('');  const [lastName, setLastName] = useState('');  const [countryCode, setCountryCode] = useState('ISL');  const [applicantId, setApplicantId] = useState('');  const [sdkToken, setSDKtoken] = useState('');  const CountrySelection = () => {    //const [countrycode, setCountryCode] = React.useState(null);    //useEffect(() => {    //  setCountry(getCountryISO3(countrycode))    //},[country]) ;    return (<SafeAreaView><Text style={{padding:10}}>Select country of issuance</Text><CountrySelectDropdown          countrySelect={setCountryCode}          error={"errorMsg"}          fontFamily={"Nunito-Regular"}          textColor={"#0a0a0a"}          //defaultCountry={"IS"}          /></SafeAreaView>    )  }  const UselessTextInput = () => {    //const [firstname, onChangeFirst] = React.useState(null);    //const [lastname, onChangeLast] = React.useState(null);    /*useEffect(() => {      setFirstName(firstName);    },[firstName]);    useEffect(() => {      setLastName(lastName);    },[lastName]); */    //TO-DO - TextInput looses focus after each keystroke    return (<SafeAreaView><TextInput          style={styles.input}          value={firstName}          //autoFocus={true} autofocus might work if we split the input into two functions          onChangeText={setFirstName}          placeholder="First name"        /><TextInput          style={styles.input}          value={lastName}          onChangeText={setLastName}          placeholder="Last name"        /></SafeAreaView>    );  };  const _createApplicant = async () => {    const result = await createApplicant(firstName,lastName)    return result  }  const getToken = async (applicant_id:string) => {    console.log("Firstname + lastname --->  "+firstName+"  "+lastName)    //const result = await createApplicant(firstName,lastName)    const sdkTokenResponse = await createSdk(applicant_id,"com.sampleapp");    setSDKtoken(sdkTokenResponse);    return sdkTokenResponse;  }  const startSDK = async () =>  {    //const [id, setID] = useState('');    const applicant_id = await _createApplicant();    console.log("appliccant_id: "+applicant_id)    console.log("country: "+countryCode);    Onfido.start({      sdkToken: await getToken(applicant_id),      flowSteps: {        welcome: true,        captureFace: {          type: OnfidoCaptureType.PHOTO,        },        captureDocument: {          docType: OnfidoDocumentType.DRIVING_LICENCE,          countryCode: getCountryISO3(countryCode),        },      },    })      .then(res => navigation.navigate('Screen2',applicant_id))      .catch(err => console.warn('OnfidoSDK: Error:', err.code, err.message));  }    return (<View style={{marginTop: 100,padding: 20}}><UselessTextInput/><CountrySelection/><View style={{marginTop: 100,padding: 20}}></View><Button title="Start Onfido SDK" onPress={async () => await startSDK()} /></View>    );}export default withNavigation(OnFidoSDK);

where I need to do any changes are around line 75-92 where I am receiving the first and last name of the user.

thanks for any help that you can provide me with!


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>