mattermost-mobile/app/components/post_draft/post_draft.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
3.5 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} from 'react-native';
import {KeyboardTrackingView} from 'react-native-keyboard-tracking-view';
import {UPDATE_NATIVE_SCROLLVIEW} from '@constants/post_draft';
import EventEmitter from '@mm-redux/utils/event_emitter';
import Archived from './archived';
import DraftInput from './draft_input';
import ReadOnly from './read_only';
export default class PostDraft extends PureComponent {
static propTypes = {
accessoriesContainerID: PropTypes.string,
canPost: PropTypes.bool.isRequired,
channelId: PropTypes.string.isRequired,
channelIsArchived: PropTypes.bool,
channelIsReadOnly: PropTypes.bool.isRequired,
cursorPositionEvent: PropTypes.string,
deactivatedChannel: PropTypes.bool.isRequired,
registerTypingAnimation: PropTypes.func.isRequired,
rootId: PropTypes.string,
screenId: PropTypes.string.isRequired,
scrollViewNativeID: PropTypes.string,
valueEvent: PropTypes.string,
theme: PropTypes.object.isRequired,
};
draftInput = React.createRef();
keyboardTracker = React.createRef();
componentDidMount() {
EventEmitter.on(UPDATE_NATIVE_SCROLLVIEW, this.updateNativeScrollView);
}
componentWillUnmount() {
EventEmitter.off(UPDATE_NATIVE_SCROLLVIEW, this.updateNativeScrollView);
}
handleInputQuickAction = (value) => {
if (this.draftInput?.current) {
this.draftInput.current.handleInputQuickAction(value);
}
};
updateNativeScrollView = (scrollViewNativeID) => {
if (this.keyboardTracker?.current) {
this.keyboardTracker.current.resetScrollView(scrollViewNativeID);
}
};
render = () => {
const {
accessoriesContainerID,
canPost,
channelId,
channelIsArchived,
channelIsReadOnly,
cursorPositionEvent,
deactivatedChannel,
registerTypingAnimation,
rootId,
screenId,
scrollViewNativeID,
theme,
valueEvent,
} = this.props;
if (channelIsArchived || deactivatedChannel) {
return (
<Archived
defactivated={deactivatedChannel}
rootId={rootId}
theme={theme}
/>
);
}
const readonly = channelIsReadOnly || !canPost;
if (readonly) {
return (
<ReadOnly theme={theme}/>
);
}
const draftInput = (
<DraftInput
ref={this.draftInput}
channelId={channelId}
cursorPositionEvent={cursorPositionEvent}
registerTypingAnimation={registerTypingAnimation}
rootId={rootId}
screenId={screenId}
theme={theme}
valueEvent={valueEvent}
/>
);
if (Platform.OS === 'android') {
return draftInput;
}
return (
<KeyboardTrackingView
accessoriesContainerID={accessoriesContainerID}
ref={this.keyboardTracker}
scrollViewNativeID={scrollViewNativeID}
>
{draftInput}
</KeyboardTrackingView>
);
};
}