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

fixed scrolling when focusing on the edit box for old message #3551

Merged
merged 4 commits into from
Jun 14, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/libs/ReportActionComposeFocusManager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import _ from 'underscore';
import React from 'react';

const composerRef = React.createRef();
let focusCallback = null;

/**
Expand Down Expand Up @@ -30,8 +32,20 @@ function clear() {
focusCallback = null;
}

/**
* Tells about the current focus state of the report action composer.
parasharrajat marked this conversation as resolved.
Show resolved Hide resolved
*
*/
function isFocused() {
if (composerRef.current) {
composerRef.current.isFocused();
}
}

export default {
composerRef,
onComposerFocus,
focus,
clear,
isFocused,
};
14 changes: 13 additions & 1 deletion src/pages/home/report/ReportActionCompose.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class ReportActionCompose extends React.Component {
this.onSelectionChange = this.onSelectionChange.bind(this);
this.emojiPopoverAnchor = null;
this.emojiSearchInput = null;
this.setTextInputRef = this.setTextInputRef.bind(this);

this.state = {
isFocused: this.shouldFocusInputOnScreenFocus,
Expand Down Expand Up @@ -202,6 +203,17 @@ class ReportActionCompose extends React.Component {
this.setState({isMenuVisible});
}

/**
* Set the TextInput Ref
*
* @param {Element} el
* @memberof ReportActionCompose
*/
setTextInputRef(el) {
ReportActionComposeFocusManager.composerRef.current = el;
this.textInput = el;
}

/**
* Focus the composer text input
*/
Expand Down Expand Up @@ -449,7 +461,7 @@ class ReportActionCompose extends React.Component {
<TextInputFocusable
autoFocus={this.shouldFocusInputOnScreenFocus}
multiline
ref={el => this.textInput = el}
ref={this.setTextInputRef}
textAlignVertical="top"
placeholder={this.props.translate('reportActionCompose.writeSomething')}
placeholderTextColor={themeColors.placeholderText}
Expand Down
7 changes: 6 additions & 1 deletion src/pages/home/report/ReportActionsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import withWindowDimensions, {windowDimensionsPropTypes} from '../../../componen
import withDrawerState, {withDrawerPropTypes} from '../../../components/withDrawerState';
import {flatListRef, scrollToBottom} from '../../../libs/ReportScrollManager';
import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize';
import ReportActionComposeFocusManager from '../../../libs/ReportActionComposeFocusManager';

const propTypes = {
/** The ID of the report actions will be created for */
Expand Down Expand Up @@ -107,7 +108,11 @@ class ReportActionsView extends React.Component {
componentDidMount() {
AppState.addEventListener('change', this.onVisibilityChange);
subscribeToReportTypingEvents(this.props.reportID);
this.keyboardEvent = Keyboard.addListener('keyboardDidShow', this.scrollToListBottom);
this.keyboardEvent = Keyboard.addListener('keyboardDidShow', () => {
if (ReportActionComposeFocusManager.isFocused()) {
this.scrollToListBottom();
}
parasharrajat marked this conversation as resolved.
Show resolved Hide resolved
});
updateLastReadActionID(this.props.reportID);

// Since we want the New marker to remain in place even if newer messages come in, we set it once on mount.
Expand Down