Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
declare module 'react-native-search-component' {
import { ViewStyle, TextStyle } from "react-native"
import { TextStyle, NativeSyntheticEvent, TextInputChangeEventData } from "react-native"
import React from 'react'

export interface SearchComponentProps {
placeholder?: string;
placeholderTextColor?: string;
onChange: () => void;
onChange: (e: NativeSyntheticEvent<TextInputChangeEventData>) => void;
value: string;
onSearchClear?: () => void;
theme?: 'LIGHT' | 'DARK';
theme?: 'LIGHT' | 'DARK' | 'light' | 'dark';
isLoading?: boolean;
loadingTintColor?: string;
cancelColor?: string;
customSearchInputStyle?: ViewStyle;
customSearchInputStyle?: TextStyle;
customCancelTextStyle?: TextStyle;
}

Expand Down
19 changes: 11 additions & 8 deletions src/searchComponent/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import PropTypes from 'prop-types';
import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useState } from 'react';
import { ActivityIndicator, Platform, StyleSheet, Text, TextInput, TouchableOpacity, useWindowDimensions, View, ViewPropTypes } from 'react-native';
import Animated, { Easing, spring, timing, Value } from 'react-native-reanimated';
import Animated, { EasingNode, spring, timing, Value } from 'react-native-reanimated';
import Svg, { Path } from 'react-native-svg';

const styledTheme = {
Expand Down Expand Up @@ -41,6 +41,8 @@ const CloseIcon = ({ theme }) => {
}

const SearchComponent = forwardRef((props, ref) => {
const safeTheme = props?.theme.toUpperCase();

const [searchInputFocussed, setSearchInputFocussed] = useState(false);
const { width } = useWindowDimensions();
const memoizedTextInputOnFocusWidth = useMemo(() => width - (50 + 32 + 32), [width]);
Expand Down Expand Up @@ -73,7 +75,7 @@ const SearchComponent = forwardRef((props, ref) => {
timing(cancelTextOpacity, {
toValue: 1,
duration: 200,
easing: Easing.linear
easing: EasingNode.linear
}).start();
} else {
spring(textInputWidth, {
Expand All @@ -85,14 +87,15 @@ const SearchComponent = forwardRef((props, ref) => {
timing(cancelTextOpacity, {
toValue: 0,
duration: 200,
easing: Easing.linear
easing: EasingNode.linear
}).start();
}
}, [searchInputFocussed]);

return (
<Animated.View style={styles.searchInputWrapper}>
<Animated.View style={styles.searchIconWrapper}>
<SearchIcon theme={props?.theme} />
<SearchIcon theme={safeTheme} />
</Animated.View>
<Animated.View style={{ width: textInputWidth, paddingVertical: 4 }}>
<TextInput
Expand All @@ -106,13 +109,13 @@ const SearchComponent = forwardRef((props, ref) => {
style={[
styles.searchInputStyle,
{
backgroundColor: styledTheme[props?.theme].textInputBackground,
color: styledTheme[props?.theme].textColor,
backgroundColor: styledTheme[safeTheme].textInputBackground,
color: styledTheme[safeTheme].textColor,
},
props.customSearchInputStyle,
]}
placeholder={props?.placeholder}
placeholderTextColor={props?.placeholderTextColor || styledTheme[props?.theme].placeholderTextColor}
placeholderTextColor={props?.placeholderTextColor || styledTheme[safeTheme].placeholderTextColor}
/>
{
props?.isLoading ? (
Expand Down Expand Up @@ -179,7 +182,7 @@ SearchComponent.propTypes = {
onChange: PropTypes.func.isRequired,
value: PropTypes.string.isRequired,
onSearchClear: PropTypes.func,
theme: PropTypes.oneOf(['LIGHT', 'DARK']),
theme: PropTypes.oneOf(['LIGHT', 'DARK', 'light', 'dark']),
isLoading: PropTypes.bool,
loadingTintColor: PropTypes.string,
cancelColor: PropTypes.string,
Expand Down