Skip to content

Commit 600b1d2

Browse files
CRNS-61: Adding prop for AttachButton to MessageInput
Resolves #119
1 parent 18a06ef commit 600b1d2

File tree

5 files changed

+81
-17
lines changed

5 files changed

+81
-17
lines changed

src/components/AttachButton.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React from 'react';
2+
import styled from '@stream-io/styled-components';
3+
import iconAddAttachment from '../images/icons/plus-outline.png';
4+
import { themed } from '../styles/theme';
5+
import PropTypes from 'prop-types';
6+
7+
const Container = styled.TouchableOpacity`
8+
margin-right: 8;
9+
${({ theme }) => theme.messageInput.attachButton.css}
10+
`;
11+
12+
const AttachButtonIcon = styled.Image`
13+
width: 15;
14+
height: 15;
15+
${({ theme }) => theme.messageInput.attachButtonIcon.css}
16+
`;
17+
18+
/**
19+
* UI Component for attach button in MessageInput component.
20+
*
21+
* @extends PureComponent
22+
* @example ./docs/AttachButton.md
23+
*/
24+
export const AttachButton = themed(
25+
class AttachButton extends React.PureComponent {
26+
static themePath = 'messageInput';
27+
static propTypes = {
28+
handleOnPress: PropTypes.func,
29+
};
30+
31+
render() {
32+
const { handleOnPress } = this.props;
33+
return (
34+
<Container onPress={handleOnPress}>
35+
<AttachButtonIcon source={iconAddAttachment} />
36+
</Container>
37+
);
38+
}
39+
},
40+
);

src/components/MessageInput.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ import uniq from 'lodash/uniq';
1818
import styled from '@stream-io/styled-components';
1919
import { themed } from '../styles/theme';
2020
import { SendButton } from './SendButton';
21+
import { AttachButton } from './AttachButton';
2122

2223
import { ActionSheetCustom as ActionSheet } from 'react-native-actionsheet';
2324
// import iconMedia from '../images/icons/icon_attach-media.png';
2425

25-
import iconAddAttachment from '../images/icons/plus-outline.png';
2626
import iconGallery from '../images/icons/icon_attach-media.png';
2727
import iconFolder from '../images/icons/icon_folder.png';
2828
import iconClose from '../images/icons/icon_close.png';
@@ -61,17 +61,6 @@ const InputBoxContainer = styled.View`
6161
${({ theme }) => theme.messageInput.inputBoxContainer.css}
6262
`;
6363

64-
const AttachButton = styled.TouchableOpacity`
65-
margin-right: 8;
66-
${({ theme }) => theme.messageInput.attachButton.css}
67-
`;
68-
69-
const AttachButtonIcon = styled.Image`
70-
width: 15;
71-
height: 15;
72-
${({ theme }) => theme.messageInput.attachButtonIcon.css}
73-
`;
74-
7564
const ActionSheetTitleContainer = styled.View`
7665
flex-direction: row;
7766
justify-content: space-between;
@@ -180,6 +169,15 @@ const MessageInput = withKeyboardContext(
180169
PropTypes.node,
181170
PropTypes.elementType,
182171
]),
172+
/**
173+
* Custom UI component for attach button.
174+
*
175+
* Defaults to and accepts same props as: [AttachButton](https://getstream.github.io/stream-chat-react-native/#attachbutton)
176+
* */
177+
AttachButton: PropTypes.oneOfType([
178+
PropTypes.node,
179+
PropTypes.elementType,
180+
]),
183181
/**
184182
* Additional props for underlying TextInput component. These props will be forwarded as it is to TextInput component.
185183
*
@@ -205,6 +203,7 @@ const MessageInput = withKeyboardContext(
205203
hasImagePicker: true,
206204
hasFilePicker: true,
207205
SendButton,
206+
AttachButton,
208207
};
209208

210209
getMessageDetailsForState = (message) => {
@@ -690,7 +689,12 @@ const MessageInput = withKeyboardContext(
690689
this.attachActionSheet.hide();
691690
};
692691
render() {
693-
const { hasImagePicker, hasFilePicker, SendButton } = this.props;
692+
const {
693+
hasImagePicker,
694+
hasFilePicker,
695+
SendButton,
696+
AttachButton,
697+
} = this.props;
694698
let editingBoxStyles = {};
695699
if (this.props.editing) {
696700
editingBoxStyles = {
@@ -749,7 +753,7 @@ const MessageInput = withKeyboardContext(
749753
)}
750754
<InputBoxContainer ref={this.props.setInputBoxContainerRef}>
751755
<AttachButton
752-
onPress={async () => {
756+
handleOnPress={async () => {
753757
if (hasImagePicker && hasFilePicker) {
754758
await this.props.dismissKeyboard();
755759
this.attachActionSheet.show();
@@ -758,9 +762,7 @@ const MessageInput = withKeyboardContext(
758762
else if (!hasImagePicker && hasFilePicker)
759763
this._pickFile();
760764
}}
761-
>
762-
<AttachButtonIcon source={iconAddAttachment} />
763-
</AttachButton>
765+
/>
764766
{/**
765767
TODO: Use custom action sheet to show icon with titles of button. But it doesn't
766768
work well with async onPress operations. So find a solution.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Attach button
2+
3+
```js
4+
<div className="str-chat">
5+
<AttachButton />
6+
</div>
7+
```
8+
9+
Send edited message button
10+
11+
```js
12+
<div className="str-chat">
13+
<AttachButton />
14+
</div>
15+
```

styleguide.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ module.exports = {
9191
'src/components/LoadingIndicator.js',
9292
'src/components/Image.js',
9393
'src/components/SendButton.js',
94+
'src/components/AttachButton.js',
9495
'src/components/DateSeparator.js',
9596
'src/components/Window.js',
9697
'src/components/ChannelListMessenger.js',

types/index.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ export interface MessageInputProps
217217
/** https://github.com/beefe/react-native-actionsheet/blob/master/lib/styles.js */
218218
actionSheetStyles?: object;
219219
AttachmentFileIcon?: React.ElementType<FileIconUIComponentProps>;
220+
AttachButton?: React.ElementType<AttachButtonProps>;
220221
}
221222

222223
export interface AttachmentProps extends MessageContentContextValue {
@@ -715,6 +716,10 @@ export interface AttachmentActionsProps {
715716
actionHandler?(name: string, value: string): any;
716717
}
717718

719+
export interface AttachButtonProps {
720+
handleOnPress(): void;
721+
}
722+
718723
//================================================================================================
719724
//================================================================================================
720725
//
@@ -810,6 +815,7 @@ export class TypingIndicator extends React.PureComponent<
810815
> {}
811816
export class MessageInput extends React.PureComponent<MessageInputProps, any> {}
812817

818+
export class AttachButton extends React.PureComponent<AttachButtonProps, any> {}
813819
export class MessageSimple extends React.PureComponent<
814820
MessageUIComponentProps,
815821
any

0 commit comments

Comments
 (0)