-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Expand file tree
/
Copy pathInputAccessoryViewExample.js
More file actions
116 lines (105 loc) · 2.51 KB
/
InputAccessoryViewExample.js
File metadata and controls
116 lines (105 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
*/
'use strict';
import type {RNTesterModuleExample} from '../../types/RNTesterTypes';
import {useTheme} from '../../components/RNTesterTheme';
import {useState} from 'react';
import {
Alert,
Button,
InputAccessoryView,
ScrollView,
StyleSheet,
Text,
TextInput,
View,
} from 'react-native';
function Message(): React.Node {
return (
<View style={styles.textBubbleBackground}>
<Text style={styles.text}>Text Message</Text>
</View>
);
}
function TextInputBar(): React.Node {
const {PlaceholderTextColor, LabelColor, SeparatorColor} = useTheme();
const [text, setText] = useState<string>('');
return (
<View style={[styles.textInputContainer, {borderTopColor: SeparatorColor}]}>
<TextInput
style={[styles.textInput, {color: LabelColor}]}
onChangeText={setText}
value={text}
placeholder={'Type a message...'}
placeholderTextColor={PlaceholderTextColor}
/>
<Button
onPress={() => {
Alert.alert('You tapped the button!');
}}
title="Send"
/>
</View>
);
}
function InputAccessoryViewExample(): React.Node {
const {BackgroundColor} = useTheme();
return (
<>
<ScrollView style={styles.fill} keyboardDismissMode="interactive">
{Array(15)
.fill()
.map((_, i) => (
<Message key={i} />
))}
</ScrollView>
<InputAccessoryView backgroundColor={BackgroundColor}>
<TextInputBar />
</InputAccessoryView>
</>
);
}
const BAR_HEIGHT = 44;
const styles = StyleSheet.create({
fill: {
flex: 1,
},
textInputContainer: {
flexDirection: 'row',
alignItems: 'center',
borderTopWidth: 1,
height: BAR_HEIGHT,
},
textInput: {
flex: 1,
paddingLeft: 10,
},
text: {
padding: 10,
color: 'white',
},
textBubbleBackground: {
backgroundColor: '#2f7bf6',
borderRadius: 20,
width: 110,
margin: 20,
},
});
exports.title = 'InputAccessoryView';
exports.description =
'Example showing how to use an InputAccessoryView to build an iMessage-like sticky text input';
exports.examples = [
{
title: 'Simple view with sticky input',
render: function (): React.Node {
return <InputAccessoryViewExample />;
},
},
] as Array<RNTesterModuleExample>;