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.

Height adjustment when keyboard appears is wrong

See original GitHub issue

Hi, I am trying to shorten the screen when the keyboard is active. But it always adjust it weirdly in android, it works fine in iOS.

Before keyboard is active: whatsapp image 2016-11-17 at 6 10 39 pm

After keyboard is active: whatsapp image 2016-11-17 at 6 07 27 pm

I am using RN 0.37, this also happens when i am starting from scratch:

This is my code:

import React from 'react';

import {
  Keyboard,
  Dimensions,
  ScrollView,
  StyleSheet,
  Text,
  TextInput,
  AppRegistry
} from 'react-native';

var {height, width} = Dimensions.get('window');
var _keyboardWillShowSubscription;
var _keyboardWillHideSubscription;
height = height - 20;

class awesomeproject extends React.Component {
  constructor(props) {
 		super(props);
 		this.state = {
			height: height,
		};
	}
	componentDidMount() {
		_keyboardWillShowSubscription = Keyboard.addListener('keyboardDidShow', (e) => this._keyboardWillShow(e));
		_keyboardWillHideSubscription = Keyboard.addListener('keyboardDidHide', (e) => this._keyboardWillHide(e));
	}
	componentWillUnmount() {
		_keyboardWillShowSubscription.remove();
		_keyboardWillHideSubscription.remove();
	}
	_keyboardWillShow(e) {
		this.setState({height: height - e.endCoordinates.height});
	}
	_keyboardWillHide(e) {
		this.setState({height: height});
	}
  render() {
    return (
		<View style={{height: this.state.height}}>	
			<View style={{backgroundColor: 'blue', flex: 1}} />
			<View style={styles.fieldBox}>
				<TextInput 
					style={styles.field}
					placeholder={'hello'}
					autoCapitalize={'none'}
					placeholderTextColor={'#afbccc'}
					blurOnSubmit={false}
					autoCorrect={false}
					ref={'textinput'}
					onChangeText={(data) => this.setState({message: data})} />
			</View>
		</View>
    );
  }
}

const styles = StyleSheet.create({
  field: {
		color:'black',
		fontWeight:'bold',
		fontSize:18,
		flex: 1,
		marginHorizontal: 10
	},
});

AppRegistry.registerComponent('awesomeproject', () => awesomeproject);

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:5
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

10reactions
vonovakcommented, Nov 17, 2016

try the keyboardavoidingview

2reactions
Friendly-Robotcommented, Nov 21, 2017

kelvinaliyanto’s advice isn’t too far off. If that doesn’t work, try replacing

android:windowSoftInputMode="adjustResize"

with

android:windowSoftInputMode="adjustPan"

in your android/app/src/main/Android.Manifest.xml.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Height adjustment when keyboard appears is wrong in react ...
I am trying to shorten the screen when the keyboard is active. But it always adjust it weirdly in android, ...
Read more >
Adjusting view for Keyboard Height… | Apple Developer Forums
When adjusting my view for the Keyboard Height there is additional space between the software keyboard and the view I am trying to...
Read more >
Keyboard Avoidance for SwiftUI Views - Yet Another Swift Blog
Moving SwiftUI View Up When Keyboard Appears · Create keyboard height state. · Add padding to the bottom of the view, which will...
Read more >
Android how to adjust for soft keyboard | by Yat Man, Wong
use adjustPan · change to a layout to that support resizing (wrap it in a ScrollView) · mark some views as GONE when...
Read more >
Move view when keyboard is shown (guide)
Most likely you have worked on an app with multiple textfields, and when the keyboard show up, there's a chance that your text...
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