mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-22 19:48:56 +08:00
Re-license and rename UIExplorer integration test app as RNTester
Reviewed By: yungsters Differential Revision: D4950085 fbshipit-source-id: 44574b5d0ef0d2ad5dfc714309b18dc69cbad9ff
This commit is contained in:
committed by
Facebook Github Bot
parent
82c4b9f0b7
commit
4a80dceac7
107
RNTester/js/KeyboardAvoidingViewExample.js
Normal file
107
RNTester/js/KeyboardAvoidingViewExample.js
Normal file
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
* Copyright (c) 2013-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @providesModule KeyboardAvoidingViewExample
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
const React = require('React');
|
||||
const ReactNative = require('react-native');
|
||||
const {
|
||||
KeyboardAvoidingView,
|
||||
Modal,
|
||||
SegmentedControlIOS,
|
||||
StyleSheet,
|
||||
Text,
|
||||
TextInput,
|
||||
TouchableHighlight,
|
||||
View,
|
||||
} = ReactNative;
|
||||
|
||||
const RNTesterBlock = require('./RNTesterBlock');
|
||||
const RNTesterPage = require('./RNTesterPage');
|
||||
|
||||
class KeyboardAvoidingViewExample extends React.Component {
|
||||
static title = '<KeyboardAvoidingView>';
|
||||
static description = 'Base component for views that automatically adjust their height or position to move out of the way of the keyboard.';
|
||||
|
||||
state = {
|
||||
behavior: 'padding',
|
||||
modalOpen: false,
|
||||
};
|
||||
|
||||
onSegmentChange = (segment: String) => {
|
||||
this.setState({behavior: segment.toLowerCase()});
|
||||
};
|
||||
|
||||
renderExample = () => {
|
||||
return (
|
||||
<View style={styles.outerContainer}>
|
||||
<Modal animationType="fade" visible={this.state.modalOpen}>
|
||||
<KeyboardAvoidingView behavior={this.state.behavior} style={styles.container}>
|
||||
<SegmentedControlIOS
|
||||
onValueChange={this.onSegmentChange}
|
||||
selectedIndex={this.state.behavior === 'padding' ? 0 : 1}
|
||||
style={styles.segment}
|
||||
values={['Padding', 'Position']} />
|
||||
<TextInput
|
||||
placeholder="<TextInput />"
|
||||
style={styles.textInput} />
|
||||
</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>
|
||||
);
|
||||
};
|
||||
|
||||
render() {
|
||||
return (
|
||||
<RNTesterPage title="Keyboard Avoiding View">
|
||||
<RNTesterBlock title="Keyboard-avoiding views move out of the way of the keyboard.">
|
||||
{this.renderExample()}
|
||||
</RNTesterBlock>
|
||||
</RNTesterPage>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = KeyboardAvoidingViewExample;
|
||||
Reference in New Issue
Block a user