Skip to content

IOS keyboard closes when the component is rendering #25225

Description

@mi-mazouz

Unfortunately I can't get KeyboardAvoidingView working so I'm trying to handle the problem by myself. So I'm listening on keyboard events and update my component's state consequently! My problem is that the keyboard is closing when setState function trigger a re-render.

class MyComponent extends Component {
 state = {
    isKeyboardOpen: false
  };

 componentWillMount() {
    this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', () =>
      this.setState({ isKeyboardOpen: true })
    );
    this.keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', () =>
      this.setState({ isKeyboardOpen: false })
    );
  }

  componentWillUnmount () {
    this.keyboardDidShowListener.remove();
    this.keyboardDidHideListener.remove();
  }

render () {
  const {isKeyboardOpen } = this.state
  return (
    <TextInput style={{bottom: isKeyboardOpen: 150 : 0 }} />
 )
}

React Native version:

React Native Environment Info:
System:
OS: macOS 10.14.5
CPU: (4) x64 Intel(R) Core(TM) i7-7660U CPU @ 2.50GHz
Memory: 1.45 GB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 12.3.0 - /usr/local/bin/node
Yarn: 1.16.0 - /usr/local/bin/yarn
npm: 6.9.0 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
IDEs:
Android Studio: 3.4 AI-183.6156.11.34.5522156
Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild
npmPackages:
react: 16.8.3 => 16.8.3
react-native: 0.59.9 => 0.59.9

I didn't test on Android, thanks for your help!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    API: KeyboardBugPlatform: iOSiOS applications.StaleThere has been a lack of activity on this issue and it may be closed soon.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions