mattermost-mobile/app/components/post_draft/quick_actions/quick_actions.js
Elias Nahum 48f1875cf1
MM-23090 MM-26078 && MM-26876 Refactor post draft component (#4621)
* Refactor post draft component
Re-styled ReadOnly channels
Remove filename from upload error

* Update canSubmit based on file attachment changes

* Fix error message for max file size

* Fix select autocomplete values on iOS

* Style readonly and refactor accessory view for iOS

* Make PostDraft scrollViewNativeID prop not required

* Update ReadOnly to have a background with 0.40 opacity

* Update max file size error message

* Fix shift+enter with HW keyboard
2020-08-06 19:39:25 -04:00

118 lines
No EOL
3.3 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {PureComponent} from 'react';
import PropTypes from 'prop-types';
import {Platform, StyleSheet, View} from 'react-native';
import {MAX_FILE_COUNT, UPLOAD_FILES} from '@constants/post_draft';
import EventEmitter from '@mm-redux/utils/event_emitter';
import CameraAction from './camera_quick_action';
import ImageAction from './image_quick_action';
import FileAction from './file_quick_action';
import InputAction from './input_quick_action';
export default class QuickActions extends PureComponent {
static propTypes = {
canUploadFiles: PropTypes.bool,
fileCount: PropTypes.number,
inputEventType: PropTypes.string.isRequired,
maxFileSize: PropTypes.number.isRequired,
onTextChange: PropTypes.func.isRequired,
theme: PropTypes.object.isRequired,
};
static defaultProps = {
canUploadFiles: true,
fileCount: 0,
};
constructor(props) {
super(props);
this.state = {
inputValue: '',
atDisabled: false,
slashDisabled: false,
};
}
componentDidMount() {
EventEmitter.on(this.props.inputEventType, this.handleInputEvent);
}
componentWillUnmount() {
EventEmitter.off(this.props.inputEventType, this.handleInputEvent);
}
handleInputEvent = (inputValue) => {
const atDisabled = inputValue[inputValue.length - 1] === '@';
const slashDisabled = inputValue.length > 0;
this.setState({atDisabled, slashDisabled, inputValue});
};
handleOnTextChange = (newValue) => {
this.handleInputEvent(newValue);
this.props.onTextChange(newValue);
}
handleUploadFiles(files) {
EventEmitter.emit(UPLOAD_FILES, files);
}
render() {
const {
canUploadFiles,
fileCount,
theme,
} = this.props;
const uploadProps = {
disabled: !canUploadFiles,
fileCount,
maxFileCount: MAX_FILE_COUNT,
theme,
onUploadFiles: this.handleUploadFiles,
};
return (
<View style={style.quickActionsContainer}>
<InputAction
disabled={this.state.atDisabled}
inputType='at'
onTextChange={this.handleOnTextChange}
theme={theme}
value={this.state.inputValue}
/>
<InputAction
disabled={this.state.slashDisabled}
inputType='slash'
onTextChange={this.handleOnTextChange}
theme={theme}
/>
<FileAction {...uploadProps}/>
<ImageAction {...uploadProps}/>
<CameraAction {...uploadProps}/>
</View>
);
}
}
const style = StyleSheet.create({
container: {
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
paddingBottom: Platform.select({
ios: 1,
android: 2,
}),
},
quickActionsContainer: {
display: 'flex',
flexDirection: 'row',
height: 44,
},
});