Skip to content

Commit

Permalink
feat: ✨ Added isLoading and LoadingTintColor
Browse files Browse the repository at this point in the history
  • Loading branch information
Karthik-B-06 committed Aug 9, 2020
1 parent 590cf3e commit 749674c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
4 changes: 2 additions & 2 deletions example/RNSearch/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
SafeAreaView, StyleSheet,
Text, TouchableOpacity
} from 'react-native';
import SearchComponent from 'react-native-search-component';
import SearchComponent from './src/UISearchBar';

const App = () => {
const [theme, setTheme] = React.useState('LIGHT');
Expand All @@ -24,7 +24,7 @@ const App = () => {
<TouchableOpacity style={{ paddingVertical: 12 }} onPress={toggleTheme}>
<Text style={[styles.textStyle, { color: '#007AFF', fontSize: 18 }]}>Toggle Theme</Text>
</TouchableOpacity>
<SearchComponent value={searchTerm} theme={theme} onChange={onChange} onSearchClear={onSearchClear} />
<SearchComponent isLoading={true} value={searchTerm} theme={theme} onChange={onChange} onSearchClear={onSearchClear} />
<Text style={[themeBasedTextStyle, { textAlign: 'left', paddingLeft: 16, fontSize: 18 }]}> Search Term : {searchTerm}</Text>
</SafeAreaView>
);
Expand Down
25 changes: 19 additions & 6 deletions example/RNSearch/src/UISearchBar/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import PropTypes from 'prop-types';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { Platform, StyleSheet, TextInput, TouchableOpacity, useWindowDimensions } from 'react-native';
import { ActivityIndicator, Platform, StyleSheet, TextInput, TouchableOpacity, useWindowDimensions, View } from 'react-native';
import Animated, { Easing, spring, timing, Value } from 'react-native-reanimated';
import Svg, { Path } from 'react-native-svg';

Expand Down Expand Up @@ -56,7 +56,7 @@ const SearchComponent = (props) => {
const handlePressCancel = useCallback(() => {
searchTextInput?.blur();
props?.onSearchClear();
})
});
useEffect(() => {
if (searchInputFocussed) {
spring(textInputWidth, {
Expand Down Expand Up @@ -109,7 +109,11 @@ const SearchComponent = (props) => {
placeholderTextColor={props?.placeholderTextColor || styledTheme[props?.theme].placeholderTextColor}
/>
{
(searchInputFocussed && props?.value?.length > 0) && (
props?.isLoading ? (
<View style={styles.loadingIconWrapper} >
<ActivityIndicator size='small' color={props?.loadingTintColor} />
</View>
) : (searchInputFocussed && props?.value?.length > 0) && (
<TouchableOpacity style={styles.closeIconWrapper} onPress={handleClearSearch}>
<CloseIcon />
</TouchableOpacity>
Expand Down Expand Up @@ -154,7 +158,12 @@ const styles = StyleSheet.create({
position: 'absolute',
right: 8,
top: Platform.OS === 'android' ? 21 : 18
}
},
loadingIconWrapper: {
position: 'absolute',
right: 10,
top: Platform.OS === 'android' ? 18 : 15
},
})


Expand All @@ -164,7 +173,9 @@ SearchComponent.propTypes = {
onChange: PropTypes.func.isRequired,
value: PropTypes.string.isRequired,
onSearchClear: PropTypes.func,
theme: PropTypes.oneOf(['LIGHT', 'DARK'])
theme: PropTypes.oneOf(['LIGHT', 'DARK']),
isLoading: PropTypes.bool,
loadingTintColor: PropTypes.string,
}


Expand All @@ -174,7 +185,9 @@ SearchComponent.defaultProps = {
onChange: () => { },
value: '',
onSearchClear: () => { },
theme: 'LIGHT'
theme: 'LIGHT',
isLoading: false,
loadingTintColor: '#636366',
}

export default SearchComponent;

0 comments on commit 749674c

Please sign in to comment.