import React from "react";
import {
Animated,
FlatList,
Dimensions,
ScrollView,
StyleSheet,
TouchableOpacity,
TouchableWithoutFeedback
} from "react-native";
import { Block, Text, Input, theme } from "galio-framework";
const { width } = Dimensions.get("screen");
import { articles, categories, argonTheme } from "../constants/";
import { Icon, Card } from "../components/";
const suggestions = [
{ id: "DJs", title: "DJs", image: categories["DJs"] },
{ id: "artists", title: "Artists", image: categories["artists"] },
{ id: "accessory", title: "Accessories", image: categories["accessory"] }
];
export default class Search extends React.Component {
state = {
results: [],
search: "",
active: false
};
animatedValue = new Animated.Value(0);
animate() {
this.animatedValue.setValue(0);
Animated.timing(this.animatedValue, {
toValue: 1,
duration: 300,
useNativeDriver: true
}).start();
}
handleSearchChange = search => {
const results = articles.filter(
item => search && item.title.toLowerCase().includes(search)
);
this.setState({ results, search });
this.animate();
};
renderSearch = () => {
const { search } = this.state;
const iconSearch = search ? (
this.setState({ search: "" })}>
) : (
);
return (
this.setState({ active: true })}
onBlur={() => this.setState({ active: false })}
onChangeText={this.handleSearchChange}
/>
);
};
renderNotFound = () => {
return (
We didn’t find "{this.state.search}" in our store.
You can see more products from other categories.
);
};
renderSuggestions = () => {
const { navigation } = this.props;
return (
item.id}
renderItem={({ item }) => (
navigation.navigate("Category", { ...item })}
>
{item.title}
)}
/>
);
};
renderDeals = () => {
return (
);
};
renderResult = result => {
const opacity = this.animatedValue.interpolate({
inputRange: [0, 1],
outputRange: [0.8, 1],
extrapolate: "clamp"
});
return (
);
};
renderResults = () => {
const { results, search } = this.state;
if (results.length === 0 && search) {
return (
{this.renderNotFound()}
{this.renderSuggestions()}
Daily Deals
{this.renderDeals()}
);
}
return (
{results.map(result => this.renderResult(result))}
);
};
render() {
return (
{this.renderSearch()}
{this.renderResults()}
);
}
}
const styles = StyleSheet.create({
searchContainer: {
width: width,
paddingHorizontal: theme.SIZES.BASE
},
search: {
height: 48,
width: width - 32,
marginHorizontal: theme.SIZES.BASE,
marginBottom: theme.SIZES.BASE,
borderWidth: 1,
borderRadius: 3
},
shadow: {
shadowColor: "black",
shadowOffset: { width: 0, height: 3 },
shadowRadius: 4,
shadowOpacity: 0.1,
elevation: 2
},
header: {
backgroundColor: theme.COLORS.WHITE,
shadowColor: "rgba(0, 0, 0, 0.2)",
shadowOffset: { width: 0, height: 2 },
shadowRadius: 8,
shadowOpacity: 1,
elevation: 2,
zIndex: 2
},
notfound: {
marginVertical: theme.SIZES.BASE * 2
},
suggestion: {
height: theme.SIZES.BASE * 1.5,
marginBottom: theme.SIZES.BASE
},
result: {
backgroundColor: theme.COLORS.WHITE,
marginBottom: theme.SIZES.BASE,
borderWidth: 0
},
resultTitle: {
flex: 1,
flexWrap: "wrap",
paddingBottom: 6
},
resultDescription: {
padding: theme.SIZES.BASE / 2
},
image: {
overflow: "hidden",
borderBottomLeftRadius: 4,
borderTopLeftRadius: 4
},
dealsContainer: {
justifyContent: "center",
paddingTop: theme.SIZES.BASE
},
deals: {
backgroundColor: theme.COLORS.WHITE,
marginBottom: theme.SIZES.BASE,
borderWidth: 0
},
dealsTitle: {
flex: 1,
flexWrap: "wrap",
paddingBottom: 6
},
dealsDescription: {
padding: theme.SIZES.BASE / 2
},
imageHorizontal: {
overflow: "hidden",
borderBottomLeftRadius: 4,
borderTopLeftRadius: 4
},
imageVertical: {
overflow: "hidden",
borderTopRightRadius: 4,
borderTopLeftRadius: 4
}
});