-
Notifications
You must be signed in to change notification settings - Fork 3k
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 Desktop - CMD + K is slow and laggy #3601 #3760
Changes from 1 commit
2d74cbc
bdc8dad
9b13f15
141592a
2a18f5c
4fe5bbf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,8 @@ import withLocalize, {withLocalizePropTypes} from './withLocalize'; | |
const propTypes = { | ||
/** Callback to fire when a row is tapped */ | ||
onSelectRow: PropTypes.func, | ||
filterAdapter: PropTypes.func, | ||
getCustomHeaderMessage: PropTypes.func, | ||
|
||
/** Sections for the section list */ | ||
sections: PropTypes.arrayOf(PropTypes.shape({ | ||
|
@@ -28,21 +30,12 @@ const propTypes = { | |
shouldShow: PropTypes.bool, | ||
})).isRequired, | ||
|
||
/** Value in the search input field */ | ||
value: PropTypes.string.isRequired, | ||
|
||
/** Callback fired when text changes */ | ||
onChangeText: PropTypes.func.isRequired, | ||
|
||
/** Optional placeholder text for the selector */ | ||
placeholderText: PropTypes.string, | ||
|
||
/** Options that have already been selected */ | ||
selectedOptions: PropTypes.arrayOf(optionPropTypes), | ||
|
||
/** Optional header message */ | ||
headerMessage: PropTypes.string, | ||
|
||
/** Whether we can select multiple options */ | ||
canSelectMultipleOptions: PropTypes.bool, | ||
|
||
|
@@ -69,9 +62,10 @@ const propTypes = { | |
|
||
const defaultProps = { | ||
onSelectRow: () => {}, | ||
filterAdapter: () => {}, | ||
getCustomHeaderMessage: () => {}, | ||
placeholderText: '', | ||
selectedOptions: [], | ||
headerMessage: '', | ||
canSelectMultipleOptions: false, | ||
hideSectionHeaders: false, | ||
disableArrowKeysActions: false, | ||
|
@@ -86,8 +80,10 @@ class OptionsSelector extends Component { | |
super(props); | ||
|
||
this.handleKeyPress = this.handleKeyPress.bind(this); | ||
this.onChangeText = this.onChangeText.bind(this); | ||
this.selectRow = this.selectRow.bind(this); | ||
this.viewableItems = []; | ||
this.searchValue = ''; | ||
|
||
this.state = { | ||
focusedIndex: 0, | ||
|
@@ -98,6 +94,17 @@ class OptionsSelector extends Component { | |
this.textInput.focus(); | ||
} | ||
|
||
/** | ||
* Updates sections filtered by searchValue | ||
* | ||
* @param {String} searchValue | ||
*/ | ||
onChangeText(searchValue) { | ||
const sections = this.props.filterAdapter(searchValue); | ||
this.searchValue = searchValue; | ||
this.setState({sections}); | ||
} | ||
|
||
/** | ||
* Scrolls to the focused index within the SectionList | ||
* | ||
|
@@ -188,16 +195,16 @@ class OptionsSelector extends Component { | |
} | ||
|
||
render() { | ||
const headerMessage = this.props.getCustomHeaderMessage(this.searchValue); | ||
return ( | ||
<View style={[styles.flex1]}> | ||
<View style={[styles.ph5, styles.pv3]}> | ||
<TextInputWithFocusStyles | ||
styleFocusIn={[styles.textInputReversedFocus]} | ||
ref={el => this.textInput = el} | ||
style={[styles.textInput]} | ||
value={this.props.value} | ||
onChangeText={this.props.onChangeText} | ||
onKeyPress={this.handleKeyPress} | ||
onChangeText={this.onChangeText} | ||
placeholder={this.props.placeholderText | ||
|| this.props.translate('optionsSelector.nameEmailOrPhoneNumber')} | ||
placeholderTextColor={themeColors.placeholderText} | ||
|
@@ -207,12 +214,12 @@ class OptionsSelector extends Component { | |
ref={el => this.list = el} | ||
optionHoveredStyle={styles.hoveredComponentBG} | ||
onSelectRow={this.selectRow} | ||
sections={this.props.sections} | ||
sections={this.state.sections || this.props.sections} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we just initialize the state with the sections from props? |
||
focusedIndex={this.state.focusedIndex} | ||
selectedOptions={this.props.selectedOptions} | ||
canSelectMultipleOptions={this.props.canSelectMultipleOptions} | ||
hideSectionHeaders={this.props.hideSectionHeaders} | ||
headerMessage={this.props.headerMessage} | ||
headerMessage={headerMessage} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't need a separate variable for this, let's just put |
||
disableFocusOptions={this.props.disableArrowKeysActions} | ||
hideAdditionalOptionStates={this.props.hideAdditionalOptionStates} | ||
forceTextUnreadStyle={this.props.forceTextUnreadStyle} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import _ from 'underscore'; | ||
import React, {Component} from 'react'; | ||
import {View} from 'react-native'; | ||
import {View, Text} from 'react-native'; | ||
import PropTypes from 'prop-types'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import OptionsSelector from '../components/OptionsSelector'; | ||
|
@@ -14,8 +13,6 @@ import withWindowDimensions, {windowDimensionsPropTypes} from '../components/wit | |
import {fetchOrCreateChatReport} from '../libs/actions/Report'; | ||
import HeaderWithCloseButton from '../components/HeaderWithCloseButton'; | ||
import ScreenWrapper from '../components/ScreenWrapper'; | ||
import Timing from '../libs/actions/Timing'; | ||
import CONST from '../CONST'; | ||
import FullScreenLoadingIndicator from '../components/FullscreenLoadingIndicator'; | ||
import withLocalize, {withLocalizePropTypes} from '../components/withLocalize'; | ||
import compose from '../libs/compose'; | ||
|
@@ -62,11 +59,10 @@ class SearchPage extends Component { | |
constructor(props) { | ||
super(props); | ||
|
||
Timing.start(CONST.TIMING.SEARCH_RENDER); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We still want the Timing I believe, can we get this added back but maybe put where it belongs now? |
||
|
||
this.selectReport = this.selectReport.bind(this); | ||
this.onChangeText = this.onChangeText.bind(this); | ||
this.debouncedUpdateOptions = _.debounce(this.updateOptions.bind(this), 300); | ||
this.filterAdapter = this.filterAdapter.bind(this); | ||
this.getCustomHeaderMessage = this.getCustomHeaderMessage.bind(this); | ||
this.lazyLoad = this.lazyLoad.bind(this); | ||
|
||
const { | ||
recentReports, | ||
|
@@ -79,20 +75,25 @@ class SearchPage extends Component { | |
props.betas, | ||
); | ||
|
||
this.state = { | ||
searchValue: '', | ||
recentReports, | ||
personalDetails, | ||
userToInvite, | ||
}; | ||
this.recentReports = recentReports; | ||
this.personalDetails = personalDetails; | ||
this.userToInvite = userToInvite; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Won't these need to be left in state so this can re-render with changes to these values? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't know that the SearchPage needs to re-render when updating props, but just found Onyx component wrapper. |
||
} | ||
|
||
componentDidMount() { | ||
Timing.end(CONST.TIMING.SEARCH_RENDER); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The timing isn't getting ended so this will just be an infinite timer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I added it. Sorry for forgetting. |
||
} | ||
|
||
onChangeText(searchValue = '') { | ||
this.setState({searchValue}, this.debouncedUpdateOptions); | ||
/** | ||
* Returns header message given searchValue | ||
* @param {String} searchValue | ||
* @returns {String} header messae | ||
*/ | ||
getCustomHeaderMessage(searchValue = '') { | ||
return getHeaderMessage( | ||
(this.recentReports.length + this.personalDetails.length) !== 0, | ||
Boolean(this.userToInvite), | ||
searchValue, | ||
); | ||
} | ||
|
||
/** | ||
|
@@ -101,17 +102,37 @@ class SearchPage extends Component { | |
* @returns {Array} | ||
*/ | ||
getSections() { | ||
return this.filterAdapter(''); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you need to rename this method / update the comment now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I renamed it to searchSections. |
||
|
||
|
||
/** | ||
* Returns the sections needed for the OptionsSelector | ||
* @param {String} searchValue | ||
* @returns {Array} | ||
*/ | ||
filterAdapter(searchValue) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confused at why this is called filterAdapter There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regarding this, honestly, I was also confused because I am not sure which type of design pattern is preferred in this project. |
||
const { | ||
recentReports, | ||
personalDetails, | ||
userToInvite, | ||
} = getSearchOptions( | ||
this.props.reports, | ||
this.props.personalDetails, | ||
searchValue, | ||
this.props.betas, | ||
); | ||
const sections = [{ | ||
title: this.props.translate('common.recents'), | ||
data: this.state.recentReports.concat(this.state.personalDetails), | ||
data: recentReports.concat(personalDetails), | ||
shouldShow: true, | ||
indexOffset: 0, | ||
}]; | ||
|
||
if (this.state.userToInvite) { | ||
if (userToInvite) { | ||
sections.push(({ | ||
undefined, | ||
data: [this.state.userToInvite], | ||
data: [userToInvite], | ||
shouldShow: true, | ||
indexOffset: 0, | ||
})); | ||
|
@@ -120,22 +141,10 @@ class SearchPage extends Component { | |
return sections; | ||
} | ||
|
||
updateOptions() { | ||
const { | ||
recentReports, | ||
personalDetails, | ||
userToInvite, | ||
} = getSearchOptions( | ||
this.props.reports, | ||
this.props.personalDetails, | ||
this.state.searchValue, | ||
this.props.betas, | ||
); | ||
this.setState({ | ||
userToInvite, | ||
recentReports, | ||
personalDetails, | ||
}); | ||
lazyLoad() { | ||
// eslint-disable-next-line no-console | ||
console.log('lazyLoad', this.state.readyToLoad); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't still need this log line |
||
this.setState({readyToLoad: true}); | ||
} | ||
|
||
/** | ||
|
@@ -149,11 +158,7 @@ class SearchPage extends Component { | |
} | ||
|
||
if (option.reportID) { | ||
this.setState({ | ||
searchValue: '', | ||
}, () => { | ||
Navigation.navigate(ROUTES.getReportRoute(option.reportID)); | ||
}); | ||
Navigation.navigate(ROUTES.getReportRoute(option.reportID)); | ||
} else { | ||
fetchOrCreateChatReport([ | ||
this.props.session.email, | ||
|
@@ -164,36 +169,38 @@ class SearchPage extends Component { | |
|
||
render() { | ||
const sections = this.getSections(); | ||
const headerMessage = getHeaderMessage( | ||
(this.state.recentReports.length + this.state.personalDetails.length) !== 0, | ||
Boolean(this.state.userToInvite), | ||
this.state.searchValue, | ||
); | ||
return ( | ||
<ScreenWrapper> | ||
{({didScreenTransitionEnd}) => ( | ||
<> | ||
<HeaderWithCloseButton | ||
title={this.props.translate('common.search')} | ||
onCloseButtonPress={() => Navigation.dismissModal(true)} | ||
/> | ||
<View style={[styles.flex1, styles.w100, styles.pRelative]}> | ||
<FullScreenLoadingIndicator visible={!didScreenTransitionEnd} /> | ||
{didScreenTransitionEnd && ( | ||
<OptionsSelector | ||
sections={sections} | ||
value={this.state.searchValue} | ||
onSelectRow={this.selectReport} | ||
onChangeText={this.onChangeText} | ||
headerMessage={headerMessage} | ||
hideSectionHeaders | ||
hideAdditionalOptionStates | ||
showTitleTooltip | ||
/> | ||
)} | ||
</View> | ||
<KeyboardSpacer /> | ||
</> | ||
!didScreenTransitionEnd | ||
? ( | ||
<Text> | ||
... | ||
</Text> | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We definitely don't want to show the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed log again. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated everything you asked. |
||
: ( | ||
<> | ||
<HeaderWithCloseButton | ||
title={this.props.translate('common.search')} | ||
onCloseButtonPress={() => Navigation.dismissModal(true)} | ||
/> | ||
<View style={[styles.flex1, styles.w100, styles.pRelative]}> | ||
<FullScreenLoadingIndicator visible={!didScreenTransitionEnd} /> | ||
{didScreenTransitionEnd && ( | ||
<OptionsSelector | ||
sections={sections} | ||
onSelectRow={this.selectReport} | ||
filterAdapter={this.filterAdapter} | ||
getCustomHeaderMessage={this.getCustomHeaderMessage} | ||
hideSectionHeaders | ||
hideAdditionalOptionStates | ||
showTitleTooltip | ||
/> | ||
)} | ||
</View> | ||
<KeyboardSpacer /> | ||
</> | ||
) | ||
)} | ||
</ScreenWrapper> | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each prop needs a comment