-
Notifications
You must be signed in to change notification settings - Fork 891
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enhance RecommendationCard with grid layout for routes
- Added Grid component to display routes in a two-column layout. - Introduced TouchableOpacity for route items to improve user interaction. - Adjusted styles for better responsiveness and visual appeal. Signed-off-by: Innei <i@innei.in>
- Loading branch information
Showing
2 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { cn } from "@follow/utils" | ||
import type { PropsWithChildren } from "react" | ||
import * as React from "react" | ||
import { useMemo } from "react" | ||
import type { StyleProp, ViewStyle } from "react-native" | ||
import { View } from "react-native" | ||
|
||
interface GridProps { | ||
columns: number | ||
gap: number | ||
|
||
style?: StyleProp<ViewStyle> | ||
className?: string | ||
} | ||
const placeholder = <View className="flex-1 shrink-0" /> | ||
export const Grid = ({ | ||
columns, | ||
gap, | ||
children, | ||
style, | ||
className, | ||
}: GridProps & PropsWithChildren) => { | ||
const rowsChildren = useMemo(() => { | ||
const childrenArray = React.Children.toArray(children) | ||
const rows = [] | ||
for (let i = 0; i < childrenArray.length; i += columns) { | ||
const row = childrenArray.slice(i, i + columns) | ||
|
||
// Fill row if columns is greater than row length | ||
if (row.length < columns) { | ||
row.push(...Array.from({ length: columns - row.length }, () => placeholder)) | ||
} | ||
rows.push(row) | ||
} | ||
return rows | ||
}, [children, columns]) | ||
return ( | ||
<View className={cn("w-full flex-1", className)} style={[{ gap }, style]}> | ||
{rowsChildren.map((row, index) => ( | ||
<View key={index} className="flex flex-row" style={{ gap }}> | ||
{row.map((child, index) => ( | ||
<View key={index} className="flex-1 shrink-0"> | ||
{child} | ||
</View> | ||
))} | ||
</View> | ||
))} | ||
</View> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters