Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@shinchit
Created October 24, 2019 23:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shinchit/828666951c14943438621ef419ff1c9d to your computer and use it in GitHub Desktop.
Save shinchit/828666951c14943438621ef419ff1c9d to your computer and use it in GitHub Desktop.
import React from 'react';
import {
Keyboard,
} from 'react-native';
import {
View,
Button,
Text,
Textarea,
} from 'native-base';
import { KeyboardAccessoryNavigation } from 'react-native-keyboard-accessory';
class KeyboardDetector extends React.Component {
constructor(props) {
super(props);
this.state = {
isKeyboardVisible: false,
text: '',
};
}
componentDidMount() {
this.keyboardDidShowListener = Keyboard.addListener(
'keyboardDidShow',
() => {
this.setState({ isKeyboardVisible: true });
},
);
this.keyboardDidHideListener = Keyboard.addListener(
'keyboardDidHide',
() => {
this.setState({ isKeyboardVisible: false });
this.handleDone();
},
);
}
componentWillUnmount() {
this.keyboardDidShowListener.remove();
this.keyboardDidHideListener.remove();
}
handleDone = () => {
const { text } = this.state;
console.log('text is: ' + text);
// anything you want.
// e.g. store text to DB.
}
render() {
const {
isKeyboardVisible,
} = this.state;
return (
<View style={{ flex: 1 }}>
<Button
disabled={isKeyboardVisible}
>
<Text>KeyboedVisible is: {isKeyboardVisible}</Text>
</Button>
<Textarea
rowSpan={5}
onChangeText={(text) => {
this.setState({ text });
}}
/>
<KeyboardAccessoryNavigation
avoidKeyboard={true}
nextHidden={true}
previousHidden={true}
onDone={this.handleDone}
/>
</View>
);
}
}
export default KeyboardDetector;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment