diff --git a/website/components/ListItem.js b/website/components/ListItem.js index 6ad6c326..12f39b16 100644 --- a/website/components/ListItem.js +++ b/website/components/ListItem.js @@ -5,14 +5,14 @@ import PressableOpacity from "./PressableOpacity"; const ListItem = ({ name, family, onPress }) => { return ( - + - {name} - {family} + {name} + {family} @@ -26,11 +26,14 @@ const styles = StyleSheet.create({ paddingVertical: 15, alignItems: "center", borderBottomWidth: 1, - borderBottomColor: "#e3e3e3", + borderRightWidth: 1, + borderColor: "#e3e3e3", }, textView: { flexDirection: "column", marginLeft: 20, + marginRight: 10, + flex: 1, }, name: { fontSize: 18, diff --git a/website/screens/List.js b/website/screens/List.js index 5eb9edb4..083d57d4 100644 --- a/website/screens/List.js +++ b/website/screens/List.js @@ -5,7 +5,13 @@ import React, { useImperativeHandle, forwardRef, } from "react"; -import { StyleSheet, View, FlatList, TextInput } from "react-native"; +import { + StyleSheet, + View, + FlatList, + TextInput, + useWindowDimensions +} from "react-native"; import { useDebouncedCallback } from "use-debounce"; import { IconsArray } from "../IconConstants"; import ListItem from "../components/ListItem"; @@ -188,26 +194,55 @@ const IconList = React.memo(({ query, filters, navigation }) => { const renderItem = React.useCallback( ({ item }) => { - return ; + if (!item) { + return ; + } + return ; }, [navigation] ); + const { width } = useWindowDimensions(); + + const numColumns = React.useMemo(() => { + return getNumColumns(width); + }, [width]); + + const data = React.useMemo(() => { + return padList(icons, numColumns); + }, [icons, numColumns]); + return ( ); }); -function keyExtractor(item) { - return `${item.family}-${item.name}`; +function keyExtractor(item, index) { + return item ? `${item.family}-${item.name}` : `empty-${index}`; } -const IconRow = React.memo(({ item, navigation }) => { +function getNumColumns(width, columnWidth = 300) { + const numColumns = Math.floor(width / columnWidth); + return Math.max(numColumns, 1); +} + +function padList(items = [], itemsPerRow) { + if (!Number.isInteger(itemsPerRow) || itemsPerRow <= 0) return items; + + const remainerInLastRow = items.length % itemsPerRow; + if (remainerInLastRow === 0) return items; + + return [...items, ...Array(itemsPerRow - remainerInLastRow).fill(null)]; +} + +const IconItem = React.memo(({ item, navigation }) => { return (