2016-06-07 14:42:50 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-06-07 14:42:50 +00:00
|
|
|
*
|
2018-05-11 20:32:37 +00:00
|
|
|
* @format
|
2016-06-07 14:42:50 +00:00
|
|
|
*/
|
2018-05-11 20:32:37 +00:00
|
|
|
|
2016-06-07 14:42:50 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const React = require('React');
|
|
|
|
const ReactNative = require('react-native');
|
|
|
|
const {
|
|
|
|
KeyboardAvoidingView,
|
|
|
|
Modal,
|
|
|
|
SegmentedControlIOS,
|
|
|
|
StyleSheet,
|
|
|
|
Text,
|
|
|
|
TextInput,
|
|
|
|
TouchableHighlight,
|
|
|
|
View,
|
|
|
|
} = ReactNative;
|
|
|
|
|
2017-05-06 03:50:47 +00:00
|
|
|
const RNTesterBlock = require('./RNTesterBlock');
|
|
|
|
const RNTesterPage = require('./RNTesterPage');
|
2016-06-07 14:42:50 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
class KeyboardAvoidingViewExample extends React.Component {
|
|
|
|
static title = '<KeyboardAvoidingView>';
|
2018-06-06 12:20:40 +00:00
|
|
|
static description =
|
|
|
|
'Base component for views that automatically adjust their height or position to move out of the way of the keyboard.';
|
2016-06-07 14:42:50 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
state = {
|
|
|
|
behavior: 'padding',
|
|
|
|
modalOpen: false,
|
|
|
|
};
|
2016-06-07 14:42:50 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
onSegmentChange = (segment: String) => {
|
2016-06-07 14:42:50 +00:00
|
|
|
this.setState({behavior: segment.toLowerCase()});
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2016-06-07 14:42:50 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
renderExample = () => {
|
2016-06-07 14:42:50 +00:00
|
|
|
return (
|
|
|
|
<View style={styles.outerContainer}>
|
|
|
|
<Modal animationType="fade" visible={this.state.modalOpen}>
|
2018-05-11 20:32:37 +00:00
|
|
|
<KeyboardAvoidingView
|
|
|
|
behavior={this.state.behavior}
|
|
|
|
style={styles.container}>
|
2016-06-07 14:42:50 +00:00
|
|
|
<SegmentedControlIOS
|
|
|
|
onValueChange={this.onSegmentChange}
|
|
|
|
selectedIndex={this.state.behavior === 'padding' ? 0 : 1}
|
|
|
|
style={styles.segment}
|
2018-05-11 20:32:37 +00:00
|
|
|
values={['Padding', 'Position']}
|
|
|
|
/>
|
|
|
|
<TextInput placeholder="<TextInput />" style={styles.textInput} />
|
2016-06-07 14:42:50 +00:00
|
|
|
</KeyboardAvoidingView>
|
|
|
|
<TouchableHighlight
|
|
|
|
onPress={() => this.setState({modalOpen: false})}
|
|
|
|
style={styles.closeButton}>
|
|
|
|
<Text>Close</Text>
|
|
|
|
</TouchableHighlight>
|
|
|
|
</Modal>
|
|
|
|
|
|
|
|
<TouchableHighlight onPress={() => this.setState({modalOpen: true})}>
|
|
|
|
<Text>Open Example</Text>
|
|
|
|
</TouchableHighlight>
|
|
|
|
</View>
|
|
|
|
);
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2016-06-07 14:42:50 +00:00
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2017-05-06 03:50:47 +00:00
|
|
|
<RNTesterPage title="Keyboard Avoiding View">
|
|
|
|
<RNTesterBlock title="Keyboard-avoiding views move out of the way of the keyboard.">
|
2016-06-07 14:42:50 +00:00
|
|
|
{this.renderExample()}
|
2017-05-06 03:50:47 +00:00
|
|
|
</RNTesterBlock>
|
|
|
|
</RNTesterPage>
|
2016-06-07 14:42:50 +00:00
|
|
|
);
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-07 14:42:50 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
outerContainer: {
|
|
|
|
flex: 1,
|
|
|
|
},
|
|
|
|
container: {
|
|
|
|
flex: 1,
|
|
|
|
justifyContent: 'center',
|
|
|
|
paddingHorizontal: 20,
|
|
|
|
paddingTop: 20,
|
|
|
|
},
|
|
|
|
textInput: {
|
|
|
|
borderRadius: 5,
|
|
|
|
borderWidth: 1,
|
|
|
|
height: 44,
|
|
|
|
paddingHorizontal: 10,
|
|
|
|
},
|
|
|
|
segment: {
|
|
|
|
marginBottom: 10,
|
|
|
|
},
|
|
|
|
closeButton: {
|
|
|
|
position: 'absolute',
|
|
|
|
top: 30,
|
|
|
|
left: 10,
|
2018-05-11 20:32:37 +00:00
|
|
|
},
|
2016-06-07 14:42:50 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = KeyboardAvoidingViewExample;
|