Skip to content

Commit 8307330

Browse files
authored
SwipeableView updated to SwipeableList + SwipeableItem (46) (#664)
* Added Swipeable List component * Added handling of swipe begin and swipe end * Remove scroll view capability of SwipeableList * Refactored SwipeableView to SwipeableList + SwipeableItem * Updated Swipeable example to use the new swipeable list * Unified what right/left means in swipeable components * Changed name of onSwiped callback on swipeable item * Updated error message in swipeable item * Conditionally render text of items behind swipeable
1 parent becdc06 commit 8307330

File tree

13 files changed

+374
-182
lines changed

13 files changed

+374
-182
lines changed

example/src/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ import YoutubeExample from "./YoutubeExample";
8484

8585
import TableExample from "./TableExample";
8686

87-
import SwipeableViewExample from "./SwipeableViewExample";
87+
import SwipeableItemExample from "./SwipeableItemExample";
8888

8989
const ROUTES = {
9090
AudioPlayer: AudioPlayerExample,
@@ -137,7 +137,7 @@ const ROUTES = {
137137
BottomSheet: BottomSheetExample,
138138
Youtube: YoutubeExample,
139139
Table: TableExample,
140-
SwipeableView: SwipeableViewExample,
140+
SwipeableView: SwipeableItemExample,
141141
};
142142

143143
let customFonts = {
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import {
2+
SwipeableList,
3+
SwipeableItem,
4+
SwipeableItemButton,
5+
} from "@draftbit/ui";
6+
import React from "react";
7+
import Section, { Container } from "./Section";
8+
import { Text, View } from "react-native";
9+
10+
type User = { id: number; fullName: string };
11+
12+
const sampleData: User[] = [
13+
{
14+
id: 1,
15+
fullName: "Susan Williamson",
16+
},
17+
{
18+
id: 2,
19+
fullName: "Henrietta Wagner",
20+
},
21+
{
22+
id: 3,
23+
fullName: "Lydia Snyder",
24+
},
25+
{
26+
id: 4,
27+
fullName: "Harold Herrera",
28+
},
29+
{
30+
id: 5,
31+
fullName: "Richard Garrett",
32+
},
33+
];
34+
35+
const SwipeableViewExample: React.FC = () => {
36+
return (
37+
<Container style={{ flex: 1 }}>
38+
<Section style={{}} title="Swipeable List (FlatList)">
39+
<SwipeableList
40+
listComponent="FlatList"
41+
style={{ height: 150 }}
42+
data={sampleData}
43+
renderItem={({ item }: { item: User }) => (
44+
<SwipeableItem
45+
rightSwipeTitle="Swipe Me Right"
46+
rightSwipeIcon="check"
47+
onSwipedRight={() => {
48+
console.log("Swiped");
49+
}}
50+
>
51+
<Text>{item.fullName}</Text>
52+
<SwipeableItemButton
53+
onPress={() => {
54+
console.log("Pressed");
55+
}}
56+
title="Click Me (Left Swipe)"
57+
icon="check"
58+
revealSwipeDirection="left"
59+
/>
60+
</SwipeableItem>
61+
)}
62+
/>
63+
</Section>
64+
<Section style={{}} title="Swipeable List (FlashList)">
65+
<View style={{ height: 150 }}>
66+
<SwipeableList
67+
listComponent="FlashList"
68+
data={[...sampleData, ...sampleData]}
69+
estimatedItemSize={50}
70+
renderItem={({ item }: { item: User }) => (
71+
<SwipeableItem>
72+
<Text>{item.fullName}</Text>
73+
<SwipeableItemButton
74+
title="Click Me (Left Swipe)"
75+
icon="check"
76+
revealSwipeDirection="left"
77+
/>
78+
<SwipeableItemButton
79+
title="Click Me (Right Swipe)"
80+
icon="check"
81+
revealSwipeDirection="right"
82+
/>
83+
</SwipeableItem>
84+
)}
85+
/>
86+
</View>
87+
</Section>
88+
<Section style={{}} title="Swipeable Item without List">
89+
<SwipeableItem
90+
rightSwipeTitle="Swipe Me Right"
91+
rightSwipeIcon="check"
92+
onSwipedRight={() => {
93+
console.log("Swiped");
94+
}}
95+
leftSwipeTitle="Swipe Me Left"
96+
leftSwipeIcon="check"
97+
onSwipedLeft={() => {
98+
console.log("Swiped");
99+
}}
100+
>
101+
<Text>Some text</Text>
102+
</SwipeableItem>
103+
</Section>
104+
</Container>
105+
);
106+
};
107+
108+
export default SwipeableViewExample;

example/src/SwipeableViewExample.tsx

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)