Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with sending messages. Scroll to bottom on send #1048

Merged
merged 1 commit into from Aug 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/chat/Chat.js
Expand Up @@ -21,21 +21,27 @@ export default class Chat extends PureComponent {
};

scrollOffset: number = 0;
listComponent: Object;

props: {
narrow: Narrow,
isFetching: boolean,
isOnline: boolean,
isSubscribed: boolean,
noMessages: boolean,
// unreadCount: number,
};

handleSend = () => {
this.listComponent.scrollToEnd();
};

render() {
const { styles } = this.context;
const { isFetching, narrow, isOnline, isSubscribed, noMessages } = this.props;
const WrapperView = Platform.OS === 'ios' ? KeyboardAvoidingView : View;
const CheckSub = isSubscribed ? <ComposeBoxContainer /> : <NotSubscribed />;
const CheckSub = isSubscribed
? <ComposeBoxContainer onSend={this.handleSend} />
: <NotSubscribed />;

return (
<WrapperView style={styles.screen} behavior="padding">
Expand All @@ -44,7 +50,11 @@ export default class Chat extends PureComponent {
{noMessages && isFetching && <MessageListLoading />}
{!noMessages &&
<ActionSheetProvider>
<MessageListContainer />
<MessageListContainer
listRef={component => {
this.listComponent = component || this.listComponent;
}}
/>
</ActionSheetProvider>}
{/* <UnreadNotice
unreadCount={unreadCount}
Expand Down
12 changes: 7 additions & 5 deletions src/compose/ComposeBox.js
Expand Up @@ -42,6 +42,7 @@ type Props = {
composeTools: boolean,
editMessage: EditMessage,
actions: Actions,
onSend: () => void,
};

export default class ComposeBox extends PureComponent {
Expand Down Expand Up @@ -95,18 +96,19 @@ export default class ComposeBox extends PureComponent {
};

handleSend = () => {
const { actions, narrow } = this.props;
const { actions, narrow, onSend } = this.props;
const { topic, message } = this.state;

const topicToSend = replaceEmoticonsWithEmoji(topic);
const messageToSend = replaceEmoticonsWithEmoji(message);
const destinationNarrow = isStreamNarrow(narrow)
? topicNarrow(narrow[0].operand, topicToSend || '(no topic)')
: narrow;

actions.addToOutbox(
isStreamNarrow(narrow) ? topicNarrow(narrow[0].operand, topicToSend) : narrow,
messageToSend,
);
actions.addToOutbox(destinationNarrow, messageToSend);

this.clearMessageInput();
onSend();
};

handleEdit = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/group/GroupCard.js
Expand Up @@ -26,7 +26,7 @@ const styles = StyleSheet.create({
});

export default class GroupCard extends PureComponent {
listRef: Object;
listRef: (component: Object) => void;

props: {
actions: Actions,
Expand Down
1 change: 1 addition & 0 deletions src/message/HtmlChildrenContainer.js
Expand Up @@ -13,6 +13,7 @@ class HtmlChildrenContainer extends PureComponent {
auth: Auth,
actions: Actions,
handleLinkPress: string => void,
onLongPress: () => void,
};

render() {
Expand Down
35 changes: 21 additions & 14 deletions src/message/InfiniteScrollView.js
Expand Up @@ -6,27 +6,29 @@ import { Platform } from 'react-native';

import type { StyleObj } from '../types';
import config from '../config';
import { nullFunction } from '../nullObjects';
import AnchorScrollView from '../native/AnchorScrollView';

export default class InfiniteScrollView extends PureComponent {
props: {
onStartReached?: ?() => void,
onEndReached?: ?() => void,
onStartReachedThreshold: number,
onEndReachedThreshold: number,
onScroll: (e: Event) => void,
startReachedThreshold: number,
endReachedThreshold: number,
listRef: (component: Object) => void,
contentContainerStyle?: Object,
style: StyleObj,
stickyHeaderIndices: [],
autoScrollToBottom: boolean,
children?: Children,
onStartReached?: () => void,
onEndReached?: () => void,
onScroll: (e: Event) => void
};

static defaultProps = {
onStartReached: null,
onEndReached: null,
onStartReachedThreshold: config.startMessageListThreshold,
onEndReachedThreshold: config.endMessageListThreshold,
onStartReached: nullFunction,
onEndReached: nullFunction,
startReachedThreshold: config.startMessageListThreshold,
endReachedThreshold: config.endMessageListThreshold
};

_scrollOffset: number;
Expand All @@ -52,7 +54,7 @@ export default class InfiniteScrollView extends PureComponent {
if (
this.props.onStartReached &&
this._contentHeight &&
distFromStart <= this.props.onStartReachedThreshold &&
distFromStart <= this.props.startReachedThreshold &&
this._sentStartForContentHeight !== this._contentHeight
) {
this._sentStartForContentHeight = this._contentHeight;
Expand All @@ -64,7 +66,7 @@ export default class InfiniteScrollView extends PureComponent {
if (
this.props.onEndReached &&
this._contentHeight &&
distFromEnd <= this.props.onEndReachedThreshold &&
distFromEnd <= this.props.endReachedThreshold &&
this._sentEndForContentHeight !== this._contentHeight
) {
this._sentEndForContentHeight = this._contentHeight;
Expand All @@ -77,12 +79,12 @@ export default class InfiniteScrollView extends PureComponent {
const distFromEnd = this._contentHeight - this._scrollViewHeight - this._scrollOffset;

this._maybeCallOnStartReached(distFromStart);
if (this.props.onStartReached && distFromStart > this.props.onStartReachedThreshold) {
if (this.props.onStartReached && distFromStart > this.props.startReachedThreshold) {
this._sentStartForContentHeight = null;
}

this._maybeCallOnEndReached(distFromEnd);
if (this.props.onEndReached && distFromEnd > this.props.onEndReachedThreshold) {
if (this.props.onEndReached && distFromEnd > this.props.endReachedThreshold) {
this._sentEndForContentHeight = null;
}
}
Expand All @@ -106,7 +108,12 @@ export default class InfiniteScrollView extends PureComponent {
scrollEventThrottle={config.scrollCallbackThrottle}
stickyHeaderIndices={Platform.OS === 'ios' ? this.props.stickyHeaderIndices : undefined}
autoScrollToBottom={this.props.autoScrollToBottom}
removeClippedSubviews>
removeClippedSubviews
ref={component => {
const { listRef } = this.props;
if (listRef) listRef(component);
}}
>
{this.props.children}
</AnchorScrollView>
);
Expand Down
5 changes: 4 additions & 1 deletion src/message/MessageList.js
Expand Up @@ -15,9 +15,10 @@ type Props = {
fetchingOlder: boolean,
fetchingNewer: boolean,
singleFetchProgress: boolean,
onScroll: () => void,
typingUsers?: TypingState,
listRef?: Object,
renderedMessages: any[],
onScroll: () => void,
};

export default class MessageList extends PureComponent {
Expand Down Expand Up @@ -45,6 +46,7 @@ export default class MessageList extends PureComponent {
fetchingOlder,
fetchingNewer,
singleFetchProgress,
listRef,
onScroll,
typingUsers,
renderedMessages,
Expand Down Expand Up @@ -78,6 +80,7 @@ export default class MessageList extends PureComponent {
onStartReached={actions.fetchOlder}
onEndReached={actions.fetchNewer}
autoScrollToBottom={this.autoScrollToBottom}
listRef={listRef}
onScroll={onScroll}>
<LoadingIndicator active={fetchingOlder} caughtUp={caughtUpOlder} />
{renderedMessages}
Expand Down
10 changes: 7 additions & 3 deletions src/message/MessageListContainer.js
Expand Up @@ -35,26 +35,30 @@ class MessageListContainer extends PureComponent {

render() {
const {
actions,
caughtUpOlder,
caughtUpNewer,
fetchingOlder,
fetchingNewer,
typingUsers,
renderedMessages,
narrow,
actions,
listRef,
onSend,
} = this.props;
return (
<MessageList
onScroll={this.handleMessageListScroll}
actions={actions}
caughtUpNewer={caughtUpNewer}
caughtUpOlder={caughtUpOlder}
fetchingOlder={fetchingOlder}
fetchingNewer={fetchingNewer}
typingUsers={typingUsers}
renderedMessages={renderedMessages}
narrow={narrow}
actions={actions}
listRef={listRef}
onScroll={this.handleMessageListScroll}
onSend={onSend}
/>
);
}
Expand Down
1 change: 1 addition & 0 deletions src/outbox/outboxActions.js
Expand Up @@ -46,6 +46,7 @@ export const addToOutbox = (narrow: Narrow, content: string) => async (
const auth = getAuth(state);

const html = parseMarkdown(content, users, streams, auth, realm.realm_filter, realm.realm_emoji);

dispatch(
sendMessage({
narrow,
Expand Down
4 changes: 3 additions & 1 deletion src/styles/theme.js
Expand Up @@ -133,9 +133,11 @@ export default ({ color, backgroundColor, borderColor, cardColor }: Props) => ({
fontSize: 16,
},
composeBox: {
marginTop: 2,
flexDirection: 'row',
backgroundColor: 'rgba(127, 127, 127, 0.1)',
// borderTopColor: borderColor,
borderTopColor: borderColor,
borderTopWidth: 1,
// zIndex: 2,
},
subheader: {
Expand Down