diff --git a/components/CustomHeader.js b/components/CustomHeader.js index 583324a..0a6e4f9 100644 --- a/components/CustomHeader.js +++ b/components/CustomHeader.js @@ -13,6 +13,7 @@ type Props = { hasBackButton: boolean, hasSearchField: boolean, searchCallback: Function, + shouldFocusSearchBar: boolean, leftButton: React.Node, rightButton: React.Node, title: string, @@ -34,12 +35,20 @@ export default class CustomHeader extends React.Component { hasBackButton: false, hasSearchField: false, searchCallback: () => null, + shouldFocusSearchBar: false, title: '', leftButton: , rightButton: , hasTabs: false, }; + searchBarRef: Input; + + componentDidMount() { + if (this.searchBarRef !== undefined && this.props.shouldFocusSearchBar) + this.searchBarRef.focus(); + } + getSearchBar() { return ( { icon={'magnify'} color={ThemeManager.getCurrentThemeVariables().toolbarBtnColor}/> this.searchBarRef = ref} placeholder={i18n.t('proximoScreen.search')} placeholderTextColor={ThemeManager.getCurrentThemeVariables().toolbarPlaceholderColor} onChangeText={(text) => this.props.searchCallback(text)}/> diff --git a/screens/Proximo/ProximoListScreen.js b/screens/Proximo/ProximoListScreen.js index 3280582..cea1dae 100644 --- a/screens/Proximo/ProximoListScreen.js +++ b/screens/Proximo/ProximoListScreen.js @@ -61,15 +61,18 @@ export default class ProximoListScreen extends React.Component { modalRef: { current: null | Modalize }; originalData: Array; + navData = this.props.navigation.getParam('data', []); + shouldFocusSearchBar = this.navData['shouldFocusSearchBar']; constructor(props: any) { super(props); this.modalRef = React.createRef(); - this.originalData = this.props.navigation.getParam('data', []); + this.originalData = this.navData['data']; + } state = { - currentlyDisplayedData: this.props.navigation.getParam('data', []).sort(sortPrice), + currentlyDisplayedData: this.navData['data'].sort(sortPrice), currentSortMode: sortMode.price, isSortReversed: false, sortPriceIcon: '', @@ -310,6 +313,7 @@ export default class ProximoListScreen extends React.Component { navigation={nav} hasSearchField={true} searchCallback={(text) => this.search(text)} + shouldFocusSearchBar={this.shouldFocusSearchBar} rightButton={this.getSortMenu()}/> diff --git a/screens/Proximo/ProximoMainScreen.js b/screens/Proximo/ProximoMainScreen.js index f04044f..6108348 100644 --- a/screens/Proximo/ProximoMainScreen.js +++ b/screens/Proximo/ProximoMainScreen.js @@ -101,25 +101,54 @@ export default class ProximoMainScreen extends FetchedDataSectionList { } getRightButton() { + let searchScreenData = { + shouldFocusSearchBar: true, + data: { + type: { + id: "0", + name: i18n.t('proximoScreen.all'), + icon: 'star' + }, + data: this.getAvailableArticles(this.state.fetchedData.articles, undefined) + }, + }; + + return ( - this.props.navigation.navigate('ProximoAboutScreen')}> - - + + this.props.navigation.navigate('ProximoListScreen', searchScreenData)}> + + + this.props.navigation.navigate('ProximoAboutScreen')}> + + + ); } getRenderItem(item: Object, section: Object, data: Object) { + let dataToSend = { + shouldFocusSearchBar: false, + data: item, + }; if (item.data.length > 0) { return ( { - this.props.navigation.navigate('ProximoListScreen', item); + this.props.navigation.navigate('ProximoListScreen', dataToSend); }} >