PLT-4376 iOS and Android: Keep the keyboard open after sending a message (#4377)
* Force keyboard to retain focus on submitting post on mobile * Fix lint error * Allow keyboard to stay closed if the keyboard was closed earlier before submitting * Increase delay time and add to comment * Remove pass through props on suggestion box
Этот коммит содержится в:
коммит произвёл
Harrison Healey
родитель
f79f607a47
Коммит
dbdd719c51
@@ -37,6 +37,7 @@ export default class CreateComment extends React.Component {
|
|||||||
this.commentMsgKeyPress = this.commentMsgKeyPress.bind(this);
|
this.commentMsgKeyPress = this.commentMsgKeyPress.bind(this);
|
||||||
this.handleChange = this.handleChange.bind(this);
|
this.handleChange = this.handleChange.bind(this);
|
||||||
this.handleKeyDown = this.handleKeyDown.bind(this);
|
this.handleKeyDown = this.handleKeyDown.bind(this);
|
||||||
|
this.handleBlur = this.handleBlur.bind(this);
|
||||||
this.handleUploadClick = this.handleUploadClick.bind(this);
|
this.handleUploadClick = this.handleUploadClick.bind(this);
|
||||||
this.handleUploadStart = this.handleUploadStart.bind(this);
|
this.handleUploadStart = this.handleUploadStart.bind(this);
|
||||||
this.handleFileUploadComplete = this.handleFileUploadComplete.bind(this);
|
this.handleFileUploadComplete = this.handleFileUploadComplete.bind(this);
|
||||||
@@ -58,7 +59,8 @@ export default class CreateComment extends React.Component {
|
|||||||
fileInfos: draft.fileInfos,
|
fileInfos: draft.fileInfos,
|
||||||
submitting: false,
|
submitting: false,
|
||||||
ctrlSend: PreferenceStore.getBool(Constants.Preferences.CATEGORY_ADVANCED_SETTINGS, 'send_on_ctrl_enter'),
|
ctrlSend: PreferenceStore.getBool(Constants.Preferences.CATEGORY_ADVANCED_SETTINGS, 'send_on_ctrl_enter'),
|
||||||
showPostDeletedModal: false
|
showPostDeletedModal: false,
|
||||||
|
lastBlurAt: 0
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,6 +168,10 @@ export default class CreateComment extends React.Component {
|
|||||||
fileInfos: [],
|
fileInfos: [],
|
||||||
serverError: null
|
serverError: null
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const fasterThanHumanWillClick = 150;
|
||||||
|
const forceFocus = (Date.now() - this.state.lastBlurAt < fasterThanHumanWillClick);
|
||||||
|
this.focusTextbox(forceFocus);
|
||||||
}
|
}
|
||||||
|
|
||||||
commentMsgKeyPress(e) {
|
commentMsgKeyPress(e) {
|
||||||
@@ -316,8 +322,8 @@ export default class CreateComment extends React.Component {
|
|||||||
return this.state.fileInfos.length + this.state.uploadsInProgress.length;
|
return this.state.fileInfos.length + this.state.uploadsInProgress.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
focusTextbox() {
|
focusTextbox(keepFocus = false) {
|
||||||
if (!Utils.isMobile()) {
|
if (keepFocus || !Utils.isMobile()) {
|
||||||
this.refs.textbox.focus();
|
this.refs.textbox.focus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -334,6 +340,10 @@ export default class CreateComment extends React.Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleBlur() {
|
||||||
|
this.setState({lastBlurAt: Date.now()});
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let serverError = null;
|
let serverError = null;
|
||||||
if (this.state.serverError) {
|
if (this.state.serverError) {
|
||||||
@@ -397,6 +407,7 @@ export default class CreateComment extends React.Component {
|
|||||||
onKeyPress={this.commentMsgKeyPress}
|
onKeyPress={this.commentMsgKeyPress}
|
||||||
onKeyDown={this.handleKeyDown}
|
onKeyDown={this.handleKeyDown}
|
||||||
value={this.state.message}
|
value={this.state.message}
|
||||||
|
onBlur={this.handleBlur}
|
||||||
createMessage={Utils.localizeMessage('create_comment.addComment', 'Add a comment...')}
|
createMessage={Utils.localizeMessage('create_comment.addComment', 'Add a comment...')}
|
||||||
initialText=''
|
initialText=''
|
||||||
supportsCommands={false}
|
supportsCommands={false}
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ export default class CreatePost extends React.Component {
|
|||||||
this.onPreferenceChange = this.onPreferenceChange.bind(this);
|
this.onPreferenceChange = this.onPreferenceChange.bind(this);
|
||||||
this.getFileCount = this.getFileCount.bind(this);
|
this.getFileCount = this.getFileCount.bind(this);
|
||||||
this.handleKeyDown = this.handleKeyDown.bind(this);
|
this.handleKeyDown = this.handleKeyDown.bind(this);
|
||||||
|
this.handleBlur = this.handleBlur.bind(this);
|
||||||
this.sendMessage = this.sendMessage.bind(this);
|
this.sendMessage = this.sendMessage.bind(this);
|
||||||
this.focusTextbox = this.focusTextbox.bind(this);
|
this.focusTextbox = this.focusTextbox.bind(this);
|
||||||
this.showPostDeletedModal = this.showPostDeletedModal.bind(this);
|
this.showPostDeletedModal = this.showPostDeletedModal.bind(this);
|
||||||
@@ -71,7 +72,8 @@ export default class CreatePost extends React.Component {
|
|||||||
ctrlSend: PreferenceStore.getBool(Constants.Preferences.CATEGORY_ADVANCED_SETTINGS, 'send_on_ctrl_enter'),
|
ctrlSend: PreferenceStore.getBool(Constants.Preferences.CATEGORY_ADVANCED_SETTINGS, 'send_on_ctrl_enter'),
|
||||||
fullWidthTextBox: PreferenceStore.get(Preferences.CATEGORY_DISPLAY_SETTINGS, Preferences.CHANNEL_DISPLAY_MODE, Preferences.CHANNEL_DISPLAY_MODE_DEFAULT) === Preferences.CHANNEL_DISPLAY_MODE_FULL_SCREEN,
|
fullWidthTextBox: PreferenceStore.get(Preferences.CATEGORY_DISPLAY_SETTINGS, Preferences.CHANNEL_DISPLAY_MODE, Preferences.CHANNEL_DISPLAY_MODE_DEFAULT) === Preferences.CHANNEL_DISPLAY_MODE_FULL_SCREEN,
|
||||||
showTutorialTip: false,
|
showTutorialTip: false,
|
||||||
showPostDeletedModal: false
|
showPostDeletedModal: false,
|
||||||
|
lastBlurAt: 0
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,6 +130,10 @@ export default class CreatePost extends React.Component {
|
|||||||
} else {
|
} else {
|
||||||
this.sendMessage(post);
|
this.sendMessage(post);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fasterThanHumanWillClick = 150;
|
||||||
|
const forceFocus = (Date.now() - this.state.lastBlurAt < fasterThanHumanWillClick);
|
||||||
|
this.focusTextbox(forceFocus);
|
||||||
}
|
}
|
||||||
|
|
||||||
sendMessage(post) {
|
sendMessage(post) {
|
||||||
@@ -171,8 +177,8 @@ export default class CreatePost extends React.Component {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
focusTextbox() {
|
focusTextbox(keepFocus = false) {
|
||||||
if (!Utils.isMobile()) {
|
if (keepFocus || !Utils.isMobile()) {
|
||||||
this.refs.textbox.focus();
|
this.refs.textbox.focus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -405,6 +411,10 @@ export default class CreatePost extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleBlur() {
|
||||||
|
this.setState({lastBlurAt: Date.now()});
|
||||||
|
}
|
||||||
|
|
||||||
showPostDeletedModal() {
|
showPostDeletedModal() {
|
||||||
this.setState({
|
this.setState({
|
||||||
showPostDeletedModal: true
|
showPostDeletedModal: true
|
||||||
@@ -495,6 +505,7 @@ export default class CreatePost extends React.Component {
|
|||||||
onKeyPress={this.postMsgKeyPress}
|
onKeyPress={this.postMsgKeyPress}
|
||||||
onKeyDown={this.handleKeyDown}
|
onKeyDown={this.handleKeyDown}
|
||||||
value={this.state.message}
|
value={this.state.message}
|
||||||
|
onBlur={this.handleBlur}
|
||||||
createMessage={Utils.localizeMessage('create_post.write', 'Write a message...')}
|
createMessage={Utils.localizeMessage('create_post.write', 'Write a message...')}
|
||||||
channelId={this.state.channelId}
|
channelId={this.state.channelId}
|
||||||
id='post_textbox'
|
id='post_textbox'
|
||||||
@@ -536,4 +547,4 @@ export default class CreatePost extends React.Component {
|
|||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -227,5 +227,6 @@ SuggestionBox.propTypes = {
|
|||||||
|
|
||||||
// explicitly name any input event handlers we override and need to manually call
|
// explicitly name any input event handlers we override and need to manually call
|
||||||
onChange: React.PropTypes.func,
|
onChange: React.PropTypes.func,
|
||||||
|
onBlur: React.PropTypes.func,
|
||||||
onKeyDown: React.PropTypes.func
|
onKeyDown: React.PropTypes.func
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ export default class Textbox extends React.Component {
|
|||||||
this.onRecievedError = this.onRecievedError.bind(this);
|
this.onRecievedError = this.onRecievedError.bind(this);
|
||||||
this.handleKeyPress = this.handleKeyPress.bind(this);
|
this.handleKeyPress = this.handleKeyPress.bind(this);
|
||||||
this.handleKeyDown = this.handleKeyDown.bind(this);
|
this.handleKeyDown = this.handleKeyDown.bind(this);
|
||||||
|
this.handleBlur = this.handleBlur.bind(this);
|
||||||
this.handleHeightChange = this.handleHeightChange.bind(this);
|
this.handleHeightChange = this.handleHeightChange.bind(this);
|
||||||
this.showPreview = this.showPreview.bind(this);
|
this.showPreview = this.showPreview.bind(this);
|
||||||
|
|
||||||
@@ -84,6 +85,12 @@ export default class Textbox extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleBlur(e) {
|
||||||
|
if (this.props.onBlur) {
|
||||||
|
this.props.onBlur(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
handleHeightChange(height) {
|
handleHeightChange(height) {
|
||||||
const textbox = $(this.refs.message.getTextbox());
|
const textbox = $(this.refs.message.getTextbox());
|
||||||
const wrapper = $(this.refs.wrapper);
|
const wrapper = $(this.refs.wrapper);
|
||||||
@@ -209,6 +216,7 @@ export default class Textbox extends React.Component {
|
|||||||
onChange={this.props.onChange}
|
onChange={this.props.onChange}
|
||||||
onKeyPress={this.handleKeyPress}
|
onKeyPress={this.handleKeyPress}
|
||||||
onKeyDown={this.handleKeyDown}
|
onKeyDown={this.handleKeyDown}
|
||||||
|
onBlur={this.handleBlur}
|
||||||
onHeightChange={this.handleHeightChange}
|
onHeightChange={this.handleHeightChange}
|
||||||
style={{visibility: this.state.preview ? 'hidden' : 'visible'}}
|
style={{visibility: this.state.preview ? 'hidden' : 'visible'}}
|
||||||
listComponent={SuggestionList}
|
listComponent={SuggestionList}
|
||||||
@@ -255,5 +263,6 @@ Textbox.propTypes = {
|
|||||||
onKeyPress: React.PropTypes.func.isRequired,
|
onKeyPress: React.PropTypes.func.isRequired,
|
||||||
createMessage: React.PropTypes.string.isRequired,
|
createMessage: React.PropTypes.string.isRequired,
|
||||||
onKeyDown: React.PropTypes.func,
|
onKeyDown: React.PropTypes.func,
|
||||||
|
onBlur: React.PropTypes.func,
|
||||||
supportsCommands: React.PropTypes.bool.isRequired
|
supportsCommands: React.PropTypes.bool.isRequired
|
||||||
};
|
};
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user