Skip to content

Commit

Permalink
Merge pull request #8535 from rushatgabhane/fix-6069
Browse files Browse the repository at this point in the history
Fix Input is lost upon opening search page
  • Loading branch information
Luke9389 committed Apr 21, 2022
2 parents 0d97ece + 36db09a commit 32d8f02
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 30 deletions.
43 changes: 28 additions & 15 deletions src/components/OptionsSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import styles from '../styles/styles';
import optionPropTypes from './optionPropTypes';
import withLocalize, {withLocalizePropTypes} from './withLocalize';
import TextInput from './TextInput';
import FullScreenLoadingIndicator from './FullscreenLoadingIndicator';

const propTypes = {
/** Wether we should wait before focusing the TextInput, useful when using transitions */
Expand Down Expand Up @@ -70,6 +71,9 @@ const propTypes = {
/** Whether to autofocus the search input on mount */
autoFocus: PropTypes.bool,

/** Whether to show options list */
shouldShowOptions: PropTypes.bool,

...withLocalizePropTypes,
};

Expand All @@ -87,6 +91,7 @@ const defaultProps = {
showTitleTooltip: false,
shouldFocusOnSelectRow: false,
autoFocus: true,
shouldShowOptions: true,
};

class OptionsSelector extends Component {
Expand Down Expand Up @@ -131,6 +136,10 @@ class OptionsSelector extends Component {
* @param {SyntheticEvent} e
*/
handleKeyPress(e) {
if (!this.list) {
return;
}

// We are mapping over all the options to combine them into a single array and also saving the section index
// index within that section so we can navigate
const allOptions = _.reduce(this.props.sections, (options, section, sectionIndex) => (
Expand Down Expand Up @@ -238,21 +247,25 @@ class OptionsSelector extends Component {
selectTextOnFocus
/>
</View>
<OptionsList
ref={el => this.list = el}
optionHoveredStyle={styles.hoveredComponentBG}
onSelectRow={this.selectRow}
sections={this.props.sections}
focusedIndex={this.state.focusedIndex}
selectedOptions={this.props.selectedOptions}
canSelectMultipleOptions={this.props.canSelectMultipleOptions}
hideSectionHeaders={this.props.hideSectionHeaders}
headerMessage={this.props.headerMessage}
disableFocusOptions={this.props.disableArrowKeysActions}
hideAdditionalOptionStates={this.props.hideAdditionalOptionStates}
forceTextUnreadStyle={this.props.forceTextUnreadStyle}
showTitleTooltip={this.props.showTitleTooltip}
/>
{this.props.shouldShowOptions
? (
<OptionsList
ref={el => this.list = el}
optionHoveredStyle={styles.hoveredComponentBG}
onSelectRow={this.selectRow}
sections={this.props.sections}
focusedIndex={this.state.focusedIndex}
selectedOptions={this.props.selectedOptions}
canSelectMultipleOptions={this.props.canSelectMultipleOptions}
hideSectionHeaders={this.props.hideSectionHeaders}
headerMessage={this.props.headerMessage}
disableFocusOptions={this.props.disableArrowKeysActions}
hideAdditionalOptionStates={this.props.hideAdditionalOptionStates}
forceTextUnreadStyle={this.props.forceTextUnreadStyle}
showTitleTooltip={this.props.showTitleTooltip}
/>
)
: <FullScreenLoadingIndicator />}
</View>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Animated} from 'react-native';
import variables from '../../../styles/variables';
import getCardStyles from '../../../styles/cardStyles';

export default (
isSmallScreenWidth,
Expand All @@ -19,7 +20,7 @@ export default (
}), inverted);

const opacity = Animated.multiply(progress, inverted);
const cardStyle = {};
const cardStyle = getCardStyles(isSmallScreenWidth, screen.width);

if (isFullScreenModal && !isSmallScreenWidth) {
cardStyle.opacity = opacity;
Expand Down
25 changes: 11 additions & 14 deletions src/pages/SearchPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ 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';
import personalDetailsPropType from './personalDetailsPropType';
Expand Down Expand Up @@ -177,19 +176,17 @@ class SearchPage extends Component {
onCloseButtonPress={() => Navigation.dismissModal(true)}
/>
<View style={[styles.flex1, styles.w100, styles.pRelative]}>
{!didScreenTransitionEnd && <FullScreenLoadingIndicator />}
{didScreenTransitionEnd && (
<OptionsSelector
sections={sections}
value={this.state.searchValue}
onSelectRow={this.selectReport}
onChangeText={this.onChangeText}
headerMessage={headerMessage}
hideSectionHeaders
hideAdditionalOptionStates
showTitleTooltip
/>
)}
<OptionsSelector
sections={sections}
value={this.state.searchValue}
onSelectRow={this.selectReport}
onChangeText={this.onChangeText}
headerMessage={headerMessage}
hideSectionHeaders
hideAdditionalOptionStates
showTitleTooltip
shouldShowOptions={didScreenTransitionEnd}
/>
</View>
<KeyboardSpacer />
</>
Expand Down
16 changes: 16 additions & 0 deletions src/styles/cardStyles/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import variables from '../variables';

/**
* Get card style for cardStyleInterpolator
* @param {Boolean} isSmallScreenWidth
* @param {Number} screenWidth
* @returns {Object}
*/
export default function getCardStyles(isSmallScreenWidth, screenWidth) {
return {
position: 'fixed',
width: isSmallScreenWidth ? screenWidth : variables.sideBarWidth,
right: 0,
height: '100%',
};
}
3 changes: 3 additions & 0 deletions src/styles/cardStyles/index.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function getCardStyles() {
return {};
}

0 comments on commit 32d8f02

Please sign in to comment.