-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #457 from openforis/surveys-screen-search
Surveys screen search
- Loading branch information
Showing
8 changed files
with
72 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 26 additions & 6 deletions
32
src/form/Attributes/common/SearchableForm/SearchBar/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,54 @@ | ||
import React from 'react'; | ||
import {View} from 'react-native'; | ||
import throttle from 'lodash.throttle'; | ||
import moment from 'moment/moment'; | ||
import React, {useCallback, useState} from 'react'; | ||
import {Keyboard, View} from 'react-native'; | ||
|
||
import Input from 'arena-mobile-ui/components/Input'; | ||
import {TouchableIcon} from 'arena-mobile-ui/components/TouchableIcons'; | ||
|
||
import styles from './styles'; | ||
|
||
const SearchBar = ({handleStopToSearch, setSearchText}) => { | ||
const SearchBar = ({handleStopToSearch, setSearchText, autoFocus}) => { | ||
const [clear, setClear] = useState(false); | ||
|
||
const _handleStopToSearch = useCallback(() => { | ||
setClear(moment().format('x')); | ||
setSearchText(''); | ||
Keyboard.dismiss(); | ||
handleStopToSearch?.(); | ||
}, [handleStopToSearch, setSearchText]); | ||
|
||
const deboundedSearch = useCallback( | ||
text => throttle(setSearchText, 500)(text), | ||
[setSearchText], | ||
); | ||
return ( | ||
<View style={styles.selectBarContainer}> | ||
<View style={styles.selectContainer}> | ||
<Input | ||
onChangeText={setSearchText} | ||
onChangeText={deboundedSearch} | ||
defaultValue={String('')} | ||
autoFocus={true} | ||
autoFocus={autoFocus} | ||
horizontal={true} | ||
stacked={false} | ||
customStyle={styles.searchBox} | ||
hasTitle={false} | ||
onBlur={handleStopToSearch} | ||
returnKeyType="done" | ||
clear={clear} | ||
/> | ||
</View> | ||
<TouchableIcon | ||
iconName={'close'} | ||
onPress={handleStopToSearch} | ||
onPress={_handleStopToSearch} | ||
customStyle={styles.close} | ||
/> | ||
</View> | ||
); | ||
}; | ||
|
||
SearchBar.defaultValue = { | ||
autoFocus: true, | ||
}; | ||
|
||
export default SearchBar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters