Skip to content

Commit ab75c5f

Browse files
Updating cookbook with messageinput examples
1 parent 44627f8 commit ab75c5f

File tree

1 file changed

+87
-1
lines changed

1 file changed

+87
-1
lines changed

docs/cookbook.md

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,16 @@
2525
- [How to customize underlying `FlatList` in `MessageList` or `ChannelList`?](#how-to-customizemodify-underlying-flatlist-of-messagelist-or-channellist)
2626
- [Image upload takes too long. How can I fix it?](#image-upload-takes-too-long-how-can-i-fix-it)
2727
- [How can I override/intercept message actions such as edit, delete, reaction, reply? e.g. to track analytics](#how-can-i-overrideintercept-message-actions-such-as-edit-delete-reaction-reply-eg-to-track-analytics)
28-
- [How to change layout of MessageInput (message text input box) component](#how-to-change-layout-of-messageinput-message-text-input-box-component)
2928

29+
- MessageInput customizations
30+
31+
- [How to change layout of MessageInput (message text input box) component](#how-to-change-layout-of-messageinput-message-text-input-box-component)
32+
33+
- [Separate buttons for file picker and image picker](#separate-buttons-for-file-picker-and-image-picker)
34+
35+
- [Add some extra props to inner `TextInput` of `MessageInput` component](#adding-extra-props-to-inner-textinput-of-messageinput-component)
36+
37+
- [Growing input box with content](#growing-input-box-with-content)
3038

3139
# How to customize message component
3240

@@ -1212,4 +1220,82 @@ const theme = {
12121220
<MessageInput Input={InputBox} />
12131221
</Channel>
12141222
</Chat>
1223+
```
1224+
1225+
## Separate buttons for file picker and image picker
1226+
1227+
Additionally if you want separate buttons for file picker and image picker or just want to open either one of them on some action, you can use _pickImage() and _pickFile() functions available on props of `InputBox` component (in above example)
1228+
1229+
So basically you can add some button in `InputBox` component following way
1230+
1231+
```js
1232+
const InputBox = props => {
1233+
return (
1234+
<View style={inputBoxStyles.container}>
1235+
{/** Here you will put all the other components such as AutoCompleteInput */}
1236+
{/** Following button will only open filePicker */}
1237+
<Button onPress={props._pickFile()} />
1238+
{/** Following button will only open image picker */}
1239+
<Button onPress={props._pickImage()} />
1240+
</View>
1241+
);
1242+
};
1243+
1244+
// And then pass this InputBox to MessageInput
1245+
1246+
<MessageInput Input={InputBox} />
1247+
```
1248+
1249+
## Adding extra props to inner `TextInput` of `MessageInput` component
1250+
1251+
`MessageInput` internally uses [TextInput](https://reactnative.dev/docs/textinput.html) component from react-native. We attach some default props to it internally. But if you want to add some additional props, you can do it via `additionalTextInputProps`
1252+
1253+
```js
1254+
<MessageInput
1255+
additionalTextInputProps={{
1256+
allowFontScaling: true,
1257+
clearTextOnFocus: true
1258+
}}
1259+
/>
1260+
```
1261+
1262+
## Growing input box with content
1263+
1264+
For general idea, you may want to read this post first (thanks to [@manojsinghnegi](https://medium.com/@manojsinghnegi)) - https://medium.com/@manojsinghnegi/react-native-auto-growing-text-input-8638ac0931c8
1265+
1266+
```js
1267+
// Override the default max-height on inner TextInput
1268+
const theme = {
1269+
'messageInput.inputBox': 'max-height: 250px',
1270+
}
1271+
1272+
class ChannelScreen extends React.Component {
1273+
constructor(props) {
1274+
this.state = {
1275+
height: 40,
1276+
}
1277+
}
1278+
1279+
updateSize = (height) => {
1280+
this.setState({
1281+
height
1282+
});
1283+
}
1284+
1285+
render() {
1286+
return (
1287+
<Chat>
1288+
<Channel>
1289+
<MessageInput
1290+
additionalTextInputProps={{
1291+
onContentSizeChange: e =>
1292+
this.updateSize(e.nativeEvent.contentSize.height),
1293+
style: {height: this.state.height},
1294+
}}
1295+
/>
1296+
</Channel>
1297+
</Chat>
1298+
)
1299+
}
1300+
}
12151301
```

0 commit comments

Comments
 (0)