Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Filter clears after closing Modal on React Native #2989

Closed
dericksa opened this issue Nov 20, 2020 · 3 comments
Closed

Filter clears after closing Modal on React Native #2989

dericksa opened this issue Nov 20, 2020 · 3 comments

Comments

@dericksa
Copy link

dericksa commented Nov 20, 2020

Hello,

I've been facing a problem when trying to use RefinementList inside a modal on React Native. When the refinement occurs inside the modal and the modal is closed, for a brief moment the refined result appears and then it comes back to the previous result.

It appears that for some reason, when the modal is closed, it triggers the onSeartchStateChange with the previous search state.

I'm using Modal from 'react-native-modalbox'.

Here's the code:

              <InstantSearch
                searchState={this.state.searchState}
                onSearchStateChange={this.onSearchStateChange}
                searchClient={IAlgoliaApi.client}
                indexName={AppConfig.algoliaIndexName + '-best-seller-desc'}
               >

                <SearchBox
                    inputRef={ref => (this.textInputRef = ref)}
                    onFocus={this.onFocus}
                    input={this.state.searchInput ? this.state.searchInput : ''}
                    onEnterPress={this.onEnterPress}
                    navigation={this.props.navigation}
                    onSetValue={this.onSearchInputChange}
                    hasBackButton={true}
                    canClear={!productsIsValid}
                    rightAction={this.renderFilterButton()}
                />
                
                <Index indexName={AppConfig.algoliaIndexName + '-suggestions'}>
                    <Hits loadOnlyDistinct withoutRendering onHits={hits => this.mapSuggestion(hits)} />
                    <Configure hitsPerPage={4} distinct />
                </Index>


                <Index indexName={AppConfig.algoliaIndexName + '-best-seller-desc'}>
                    <StateResults onNewSearchResults={this.onNewSearchResults}>
                        <InfiniteHits
                            columnWrapperStyle={[styles.verticalCenterAlignedRow, styles.spaceBetween, { paddingHorizontal: 20 }]}
                            contentContainerStyle={[{ flexGrow: 1 }]}
                            showNoMore={!isShowingResults}
                            isShowingResults={isShowingResults}
                            refine={() => logDebug('')}
                            onRender={item => <ProductCard product={item} onPress={() => this.onProductPress(item)} />}
                        />
                        <Modal
                            onClosed={() => this.setState({ showFilterModal: false })}
                            isOpen={this.state.showFilterModal}
                            swipeToClose={false}
                            backdropPressToClose={false}
                            backButtonClose={true}
                        >
                            <CustomRefinementList attribute={'atributos.Cor Predominante'} />
                        </Modal>
                    </StateResults>
                </Index>

               

                <Configure hitsPerPage={20} facets={['*']} analytics={false} enablePersonalization={true} distinct />
            </InstantSearch>
@dericksa dericksa changed the title Filtering clears after closing Modal on React Native Filter clears after closing Modal on React Native Nov 20, 2020
@dericksa
Copy link
Author

I was doing some tests. So basically, if the widget is not being rendered the widget refinement is erased?

@dericksa
Copy link
Author

@Haroenv Thanks for the answer. The virtual widget workaround will serve me well 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants