forked from Ivasoft/mattermost-mobile
* Initial commit post input * Fix message posting, add create direct channel and minor fixes * Fix "is typing" and "react to last post" behaviour * Some reordering, better handling of upload error, properly clear draft on send message, and fix minor progress bar misbehavior * Add keyboard listener for shift-enter, add selection between video or photo while attaching, add alert when trying to attach more than you are allowed, add paste functionality, minor fixes and reordering * Add library patch * Fix lint * Address feedback * Address feedback * Add missing negation * Check for group name and fix typo on draft comparisons * Address feedback * Address feedback * Address feedback * Address feedback * Fix several bugs * Remove @app imports * Address feedback * fix post list & post draft layout on iOS * Fix post draft cursor position * Fix file upload route * Allow to pick multiple images using the image picker * accurately get the channel member count * remove android cursor workaround * Remove local const INPUT_LINE_HEIGHT * move getPlaceHolder out of the component * use substring instead of legacy substr for hardward keyboard * Move onAppStateChange above the effects * Fix camera action bottom sheet * no need to memo SendButton * properly use memberCount in sender handler * Refactor how to get memberCount * Fix queryRecentPostsInThread * Remove unused isDirectChannelVisible && isGroupChannelVisible util functions * rename errorBadUser to errorUnkownUser * extract localized strings * use ClientErrorProps instead of ClientError * Minor improvements Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
108 lines
3.2 KiB
TypeScript
108 lines
3.2 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import React, {useCallback, useEffect, useRef} from 'react';
|
|
import {DeviceEventEmitter, Platform} from 'react-native';
|
|
import {KeyboardTrackingView, KeyboardTrackingViewRef} from 'react-native-keyboard-tracking-view';
|
|
|
|
import {PostDraft as PostDraftConstants, View as ViewConstants} from '@constants';
|
|
import {useIsTablet} from '@hooks/device';
|
|
|
|
import Archived from './archived';
|
|
import DraftHandler from './draft_handler';
|
|
import ReadOnly from './read_only';
|
|
|
|
type Props = {
|
|
testID?: string;
|
|
accessoriesContainerID?: string;
|
|
canPost: boolean;
|
|
channelId: string;
|
|
channelIsArchived?: boolean;
|
|
channelIsReadOnly: boolean;
|
|
deactivatedChannel: boolean;
|
|
rootId?: string;
|
|
scrollViewNativeID?: string;
|
|
}
|
|
|
|
export default function PostDraft({
|
|
testID,
|
|
accessoriesContainerID,
|
|
canPost,
|
|
channelId,
|
|
channelIsArchived,
|
|
channelIsReadOnly,
|
|
deactivatedChannel,
|
|
rootId,
|
|
scrollViewNativeID,
|
|
}: Props) {
|
|
const keyboardTracker = useRef<KeyboardTrackingViewRef>(null);
|
|
const resetScrollViewAnimationFrame = useRef<number>();
|
|
const isTablet = useIsTablet();
|
|
|
|
const updateNativeScrollView = useCallback((scrollViewNativeIDToUpdate: string) => {
|
|
if (keyboardTracker?.current && scrollViewNativeID === scrollViewNativeIDToUpdate) {
|
|
resetScrollViewAnimationFrame.current = requestAnimationFrame(() => {
|
|
keyboardTracker.current?.resetScrollView(scrollViewNativeIDToUpdate);
|
|
if (resetScrollViewAnimationFrame.current != null) {
|
|
cancelAnimationFrame(resetScrollViewAnimationFrame.current);
|
|
}
|
|
resetScrollViewAnimationFrame.current = undefined;
|
|
});
|
|
}
|
|
}, [scrollViewNativeID]);
|
|
|
|
useEffect(() => {
|
|
const listener = DeviceEventEmitter.addListener(PostDraftConstants.UPDATE_NATIVE_SCROLLVIEW, updateNativeScrollView);
|
|
return () => {
|
|
listener.remove();
|
|
if (resetScrollViewAnimationFrame.current) {
|
|
cancelAnimationFrame(resetScrollViewAnimationFrame.current);
|
|
}
|
|
};
|
|
}, [updateNativeScrollView]);
|
|
|
|
if (channelIsArchived || deactivatedChannel) {
|
|
const archivedTestID = `${testID}.archived`;
|
|
|
|
return (
|
|
<Archived
|
|
testID={archivedTestID}
|
|
deactivated={deactivatedChannel}
|
|
/>
|
|
);
|
|
}
|
|
|
|
if (channelIsReadOnly || !canPost) {
|
|
const readOnlyTestID = `${testID}.read_only`;
|
|
|
|
return (
|
|
<ReadOnly
|
|
testID={readOnlyTestID}
|
|
/>
|
|
);
|
|
}
|
|
|
|
const draftHandler = (
|
|
<DraftHandler
|
|
testID={testID}
|
|
channelId={channelId}
|
|
rootId={rootId}
|
|
/>
|
|
);
|
|
|
|
if (Platform.OS === 'android') {
|
|
return draftHandler;
|
|
}
|
|
|
|
return (
|
|
<KeyboardTrackingView
|
|
accessoriesContainerID={accessoriesContainerID}
|
|
ref={keyboardTracker}
|
|
scrollViewNativeID={scrollViewNativeID}
|
|
viewInitialOffsetY={isTablet ? ViewConstants.BOTTOM_TAB_HEIGHT : 0}
|
|
>
|
|
{draftHandler}
|
|
</KeyboardTrackingView>
|
|
);
|
|
}
|