question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Update from: Keyboardavoidingview not working properly with TextInput Password Field

See original GitHub issue

This bug it’s related with #23818. I’ve opened again because I strongly thing this is a bug and @hussainahmad doesn’t actually found why it was happening.

Description

The bug is as @hussainahmad explained. When you use several TextInput inside of a KeyboardAvoidingView component, if you change the focus between a secureTextEntry to another TextInput that doesn’t have this attribute, the KeyboardAvoidingView component doesn’t adapt to the space and act like a normal View component. I think this happen when keyboard size change. This is happening to me with Google Keyboard, that has a “toolbar” that doesn’t appear with the private inputs. When you change the input, the keyboard becomes bigger and make KeyboardAvoidingView doesn’t work. On the other hand, when you use other keyboards that have fixed size (like Flesky for example) we have a correct behavior.

React Native version:

System:
    OS: Linux 5.4 Manjaro Linux
    CPU: (4) x64 Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz
    Memory: 1.20 GB / 7.69 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.3.0 - ~/.nvm/versions/node/v14.3.0/bin/node
    Yarn: 1.22.10 - /usr/bin/yarn
    npm: 7.6.3 - ~/.nvm/versions/node/v14.3.0/bin/npm
    Watchman: Not Found
  SDKs:
    Android SDK: Not Found
  IDEs:
    Android Studio: Not Found
  Languages:
    Java: 1.8.0_282 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.13.1 => 16.13.1 
    react-native: ~0.63.4 => 0.63.4 
  npmGlobalPackages:
    *react-native*: Not Found

Steps To Reproduce

If you take the code that I provide, you could reproduce the bug with the following steps (Use the last version of google keyboard):

  1. Open your app with your actual device. You can’t reproduce the bug with the emulator just because the keyboard size is fixed
  2. Touch in the InputField that has the secureTextEntry attribute set to true.
  3. Once it’s focused, touch on the other InputField that has the secureTextEntry attribute set to `false
  4. The results will be as you see in this video.

All of this doesn’t happen if you change the focus from non secureTextEntry to a secure one

Expected Results

The ideal result happens when the keyboard doesn’t modify their size. You can see an example in this video.

Snack, code example, screenshot, or link to a repository:

I’m going to provide part of the code (of a personal project) that I use to make the videos. I’ve added the parts that I think could be useful. It’s the App.js and a component. It think it’s not necessary more code, but if you need it let me know.

App.js

import React, { useEffect, useRef } from "react";
import { StyleSheet, ScrollView, Text, Image, KeyboardAvoidingView, Keyboard } from "react-native";
import TextButton from './src/components/buttons/textButton/textButton';
import SimpleInput from './src/components/inputs/simple/simple';
import { useFonts, OpenSans, OpenSans_600SemiBold, OpenSans_400Regular } from '@expo-google-fonts/open-sans';
import Constants from 'expo-constants'

export default function App() {

  const scrollComponent = useRef(null);

  // const [ styleKeyboard, setStyleKeyboard ] = useState(true)
  useEffect(() => {

    Keyboard.addListener("keyboardDidShow", () => {
      scrollComponent.current.scrollToEnd();
    })

  })

  let [fontsLoaded] = useFonts({
    OpenSans,
    OpenSans_600SemiBold,
    OpenSans_400Regular
  });

  return (
    <KeyboardAvoidingView 
      behavior={Platform.OS == "ios" ? "padding" : "height"}
      style={styles.screenContainer}
      >
      <ScrollView 
        showsVerticalScrollIndicator={false}
        ref={scrollComponent}
        style={styles.content}>
        <Image
          style={{
            width: 203,
            height: 250,
            alignSelf: "center"
          }}
          source={require('./assets/icon-5359553__340.webp')}
        />
        <Text
          style={{
            textAlign: "center",
            marginVertical: 10,
            fontSize: 32,
            fontFamily: 'OpenSans_600SemiBold',
            color: '#03242B'
          }}>
          Example test for title
        </Text>
        <SimpleInput
          type='username'
          style={{ marginVertical: 10 }}
          placeholder="Usuario"
        />
        <SimpleInput 
          type="password"
          style={{ marginVertical: 10 }}
          placeholder="Contraseña"        
        />
        <TextButton 
          style={{ marginVertical: 10 }}
          text = 'Entrar'
        />
      </ScrollView>
    </KeyboardAvoidingView>
  );

}

const styles = StyleSheet.create({
  
  screenContainer: {
    flex: 1,
    // justifyContent: "center",
    padding: '5%',
    marginTop: Constants.statusBarHeight,
    backgroundColor: '#F8F8F8'
  },

  content: {
    overflow: 'scroll'
  }

})

simple.js

import React, { useState } from 'react'
import { TextInput } from 'react-native'
import { styles } from './style'

const SimpleInput = (props) => {

    const [ stateStyle, setStateStyle ] = useState(true);

    let dynamicAttr = {}

    if(props.type == 'password'){
        dynamicAttr.secureTextEntry=true

        if(props.newPassword)
            dynamicAttr.textContentType='newPassword'
    }

    const focusStyle = () => {
        setStateStyle({
            borderWidth: 1,
            borderColor: '#054956'
        })
    }

    const blurStyle = () => {
        setStateStyle({})
    }

    return (
        <TextInput 
            style={[styles.main, props.style, stateStyle]} 
            placeholder={props.placeholder}
            placeholderTextColor="#898989"

            autoCompleteType='off'
            textContentType='password'
            {...dynamicAttr}

            onFocus={focusStyle}
            onBlur={blurStyle}
        ></TextInput>
    );

}

export default SimpleInput;

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:4
  • Comments:6

github_iconTop GitHub Comments

1reaction
corderopcommented, Apr 8, 2021

@hussainahmad Thanks! will check out. Nevertheless, I think the should check out the bug in order to fix it.

1reaction
hussainahmadcommented, Apr 8, 2021

@corderop You can use react-native-keyboard-aware-scroll-view for handling keyboard and scrolling issue. Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

KeyboardAvoidingView not working with TextInput password ...
I am using react-native-paper for Text Input and using KeyboardAvoidingView to remove keyboard issues and put Input fields above the ...
Read more >
KeyboardAvoidingView not working properly? Check your ...
Check your Flexbox Layout first. Keyboard overlaying Input or Submit button is a common problem in React Native. Something like ...
Read more >
react native keyboard avoiding view not working - You.com
I am using KeyboardAvoidingView in ios with behavior="padding" but it's not working. My screen has four text input fields, which get hidden by...
Read more >
React Native KeyboardAvoidingView: A How-To Guide - Waldo
Now, click on any TextInput and the on-screen keyboard will hide the last two fields: skill and profession. The on-screen keyboard is also ......
Read more >
Avoid Keyboard in React Native Like a Pro - Netguru
In KeyboardAvoidingView screen, after opening the bottom sheet and focusing input, content is not changing its position, which makes it ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found