-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added SectionList and SectionHeader components + Tests (48.1.0) (#684)
* Added section list and section header components * Updated how section header child is identified to use .type * Updated extraction of props to be null safe * Fixed null checks when rendering section list * Setup for tests * Added tests for sectionlist * Added test step to ci * Removed tests from ts build * v48.1.0
- Loading branch information
1 parent
c5259bd
commit 0d9c143
Showing
23 changed files
with
1,038 additions
and
861 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 |
---|---|---|
|
@@ -31,6 +31,9 @@ jobs: | |
- name: Lint | ||
run: yarn lint | ||
|
||
- name: Test | ||
run: yarn test | ||
|
||
- name: Build | ||
run: yarn build | ||
|
||
|
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 |
---|---|---|
|
@@ -67,3 +67,5 @@ components.json | |
|
||
js.map | ||
.eslintcache | ||
|
||
**/coverage/** |
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
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
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,112 @@ | ||
import { SectionList, SectionHeader } from "@draftbit/ui"; | ||
import React from "react"; | ||
import Section, { Container } from "./Section"; | ||
import { Text, View } from "react-native"; | ||
|
||
type Food = { id: number; name: string; category: string }; | ||
|
||
const sampleData: Food[] = [ | ||
{ | ||
id: 5, | ||
name: "Onion Rings", | ||
category: "Side", | ||
}, | ||
{ | ||
id: 1, | ||
name: "Pizza", | ||
category: "Main Dish", | ||
}, | ||
{ | ||
id: 3, | ||
name: "Risotto", | ||
category: "Main Dish", | ||
}, | ||
{ | ||
id: 6, | ||
name: "Ice Cream", | ||
category: "Dessert", | ||
}, | ||
{ | ||
id: 4, | ||
name: "Fries", | ||
category: "Side", | ||
}, | ||
{ | ||
id: 7, | ||
name: "Churros", | ||
category: "Dessert", | ||
}, | ||
{ | ||
id: 2, | ||
name: "Burger", | ||
category: "Main Dish", | ||
}, | ||
]; | ||
|
||
const SwipeableViewExample: React.FC = () => { | ||
return ( | ||
<Container style={{ flex: 1 }}> | ||
<Section style={{}} title="Section List (FlatList)"> | ||
<View style={{ height: 150 }}> | ||
<SectionList | ||
listComponent="FlatList" | ||
data={sampleData} | ||
sectionKey="category" | ||
renderItem={({ item }) => ( | ||
<View> | ||
<Text>{item?.id}</Text> | ||
<Text>{item?.name}</Text> | ||
</View> | ||
)} | ||
/> | ||
</View> | ||
</Section> | ||
<Section style={{}} title="Section List (FlashList)"> | ||
<View style={{ height: 150 }}> | ||
<SectionList | ||
listComponent="FlashList" | ||
data={sampleData} | ||
sectionKey="category" | ||
estimatedItemSize={40} | ||
renderItem={({ item }) => ( | ||
<View> | ||
<Text>{item?.id}</Text> | ||
<Text>{item?.name}</Text> | ||
</View> | ||
)} | ||
/> | ||
</View> | ||
</Section> | ||
<Section style={{}} title="Section List Custom Header"> | ||
<View style={{ height: 150 }}> | ||
<SectionList | ||
data={sampleData} | ||
sectionKey="category" | ||
renderItem={({ item, section }) => ( | ||
<> | ||
<SectionHeader> | ||
<Text | ||
style={{ | ||
padding: 10, | ||
color: "green", | ||
borderWidth: 2, | ||
borderColor: "green", | ||
}} | ||
> | ||
Custom Section: {section} | ||
</Text> | ||
</SectionHeader> | ||
<View> | ||
<Text>{item?.id}</Text> | ||
<Text>{item?.name}</Text> | ||
</View> | ||
</> | ||
)} | ||
/> | ||
</View> | ||
</Section> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default SwipeableViewExample; |
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
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
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 @@ | ||
require("@shopify/flash-list/jestSetup"); |
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
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,44 @@ | ||
export type Food = { | ||
id: number; | ||
name: string; | ||
category: string; | ||
priceRange: string; | ||
}; | ||
export const mockFoodData: Food[] = [ | ||
{ | ||
id: 554, | ||
name: "Onion Rings", | ||
category: "Side", | ||
priceRange: "low", | ||
}, | ||
{ | ||
id: 145, | ||
name: "Pizza", | ||
category: "Main Dish", | ||
priceRange: "high", | ||
}, | ||
{ | ||
id: 423, | ||
name: "Risotto", | ||
category: "Main Dish", | ||
priceRange: "high", | ||
}, | ||
{ | ||
id: 642, | ||
name: "Ice Cream", | ||
category: "Dessert", | ||
priceRange: "medium", | ||
}, | ||
{ | ||
id: 463, | ||
name: "Fries", | ||
category: "Side", | ||
priceRange: "low", | ||
}, | ||
{ | ||
id: 724, | ||
name: "Churros", | ||
category: "Dessert", | ||
priceRange: "medium", | ||
}, | ||
]; |
Oops, something went wrong.