Created
October 24, 2019 23:07
-
-
Save shinchit/828666951c14943438621ef419ff1c9d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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