import PropTypes from 'prop-types';
import React, { Component } from 'react';
import {
StyleSheet,
Text,
View,
FlatList,
TextInput,
Image,
StatusBar,
Button,
Platform,
Dimensions,
} from 'react-native';
import algoliasearch from 'algoliasearch/lite';
import {
InstantSearch,
connectSearchBox,
connectInfiniteHits,
connectRefinementList,
connectStats,
connectMenu,
connectSortBy,
connectRange,
connectCurrentRefinements,
} from 'react-instantsearch-native';
import RatingMenu from 'react-native-star-rating';
import ModalDropdown from 'react-native-modal-dropdown';
import IosIcon from 'react-native-vector-icons/Ionicons';
import MaterialIcon from 'react-native-vector-icons/MaterialIcons';
import { Actions } from 'react-native-router-flux';
import Highlight from './components/Highlight';
import Spinner from './components/Spinner';
const searchClient = algoliasearch(
'latency',
'6be0576ff61c053d5f9a3225e2a90f76'
);
const { height } = Dimensions.get('window');
const styles = StyleSheet.create({
maincontainer: {
flex: 1,
},
items: {
...Platform.select({
ios: {
height: height - 170,
},
android: { height: height - 165 },
}),
},
item: {
flexDirection: 'row',
alignItems: 'center',
backgroundColor: 'white',
},
options: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
backgroundColor: 'white',
padding: 5,
borderBottomColor: 'gray',
borderBottomWidth: 1,
},
sortBy: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
paddingLeft: 8,
},
searchBoxContainer: {
backgroundColor: '#162331',
flexDirection: 'row',
alignItems: 'center',
},
searchBox: {
backgroundColor: 'white',
height: 40,
borderWidth: 1,
padding: 10,
margin: 10,
flexGrow: 1,
...Platform.select({
ios: {
borderRadius: 5,
},
android: {},
}),
},
itemContent: {
paddingLeft: 15,
display: 'flex',
marginRight: 5,
},
itemName: {
fontSize: 15,
fontWeight: 'bold',
paddingBottom: 5,
},
itemType: {
fontSize: 13,
fontWeight: '200',
paddingBottom: 5,
},
itemPrice: {
fontSize: 15,
fontWeight: 'bold',
paddingBottom: 5,
},
starRating: { alignSelf: 'flex-start' },
filters: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
},
});
class Home extends Component {
static displayName = 'React Native example';
constructor(props) {
super(props);
this.state = {
searchState: this.props.searchState ? this.props.searchState : {},
};
}
onSearchStateChange = (nextState) => {
this.setState({ searchState: { ...this.state.searchState, ...nextState } });
};
render() {
return (
);
}
}
Home.propTypes = {
searchState: PropTypes.object,
};
export default Home;
class SearchBox extends Component {
render() {
return (
this.props.refine(text)}
value={this.props.currentRefinement}
placeholder={'Search a product...'}
clearButtonMode={'always'}
underlineColorAndroid={'white'}
spellCheck={false}
autoCorrect={false}
autoCapitalize={'none'}
/>
);
}
}
SearchBox.propTypes = {
refine: PropTypes.func.isRequired,
currentRefinement: PropTypes.string,
};
const ConnectedSearchBox = connectSearchBox(SearchBox);
class Hits extends Component {
onEndReached = () => {
if (this.props.hasMore) {
this.props.refine();
}
};
render() {
const hits =
this.props.hits.length > 0 ? (
) : null;
return hits;
}
_renderRow = ({ item: hit }) => (
${hit.price}
);
_renderSeparator = (sectionID, rowID, adjacentRowHighlighted) => (
);
}
Hits.propTypes = {
hits: PropTypes.array.isRequired,
refine: PropTypes.func.isRequired,
hasMore: PropTypes.bool.isRequired,
};
const ConnectedHits = connectInfiniteHits(Hits);
const ConnectedStats = connectStats(({ nbHits }) => (
{nbHits} products found
));
const ConnectedSortBy = connectSortBy(
({ refine, items, currentRefinement }) => {
const icon =
Platform.OS === 'ios' ? (
) : (
);
return (
item.value === currentRefinement).label
}
onSelect={(index, value) =>
refine(items.find((item) => item.label === value).value)
}
options={items.map((item) => item.label)}
renderRow={(item) => {
const itemValue = items.find((i) => i.label === item).value;
return (
{item}
);
}}
dropdownStyle={{
width: 200,
height: 110,
}}
textStyle={{ fontSize: 15 }}
/>
{icon}
);
}
);
const Filters = connectCurrentRefinements(
({ items, searchState, onSearchStateChange }) => (