2018-02-28 01:45:15 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
*
|
|
|
|
* @flow
|
|
|
|
* @format
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const React = require('React');
|
2018-04-11 02:47:21 +00:00
|
|
|
const ReactNative = require('react-native');
|
|
|
|
const {
|
|
|
|
Alert,
|
|
|
|
Button,
|
|
|
|
InputAccessoryView,
|
|
|
|
ScrollView,
|
|
|
|
StyleSheet,
|
|
|
|
Text,
|
|
|
|
TextInput,
|
|
|
|
View,
|
|
|
|
} = ReactNative;
|
2018-02-28 01:45:15 +00:00
|
|
|
|
|
|
|
class Message extends React.PureComponent<*> {
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<View style={styles.textBubbleBackground}>
|
|
|
|
<Text style={styles.text}>Text Message</Text>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class TextInputBar extends React.PureComponent<*, *> {
|
|
|
|
state = {text: ''};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2018-03-15 16:58:16 +00:00
|
|
|
<View style={styles.textInputContainer}>
|
2018-02-28 01:45:15 +00:00
|
|
|
<TextInput
|
|
|
|
style={styles.textInput}
|
|
|
|
onChangeText={text => {
|
|
|
|
this.setState({text});
|
|
|
|
}}
|
|
|
|
value={this.state.text}
|
|
|
|
placeholder={'Type a message...'}
|
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
onPress={() => {
|
|
|
|
Alert.alert('You tapped the button!');
|
|
|
|
}}
|
|
|
|
title="Send"
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class InputAccessoryViewExample extends React.Component<*> {
|
|
|
|
static title = '<InputAccessoryView>';
|
2018-06-06 12:20:40 +00:00
|
|
|
static description =
|
|
|
|
'Example showing how to use an InputAccessoryView to build an iMessage-like sticky text input';
|
2018-02-28 01:45:15 +00:00
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<ScrollView keyboardDismissMode="interactive">
|
|
|
|
{Array(15)
|
|
|
|
.fill()
|
|
|
|
.map((_, i) => <Message key={i} />)}
|
|
|
|
</ScrollView>
|
|
|
|
<InputAccessoryView backgroundColor="#fffffff7">
|
|
|
|
<TextInputBar />
|
|
|
|
</InputAccessoryView>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
textInputContainer: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
},
|
|
|
|
textInput: {
|
|
|
|
flex: 1,
|
|
|
|
paddingLeft: 10,
|
|
|
|
},
|
|
|
|
text: {
|
|
|
|
padding: 10,
|
|
|
|
color: 'white',
|
|
|
|
},
|
|
|
|
textBubbleBackground: {
|
|
|
|
backgroundColor: '#2f7bf6',
|
|
|
|
borderRadius: 20,
|
|
|
|
width: 110,
|
|
|
|
margin: 20,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = InputAccessoryViewExample;
|