-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
1,116 additions
and
197 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
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,98 @@ | ||
import React, {memo, useState} from 'react'; | ||
import { | ||
ListRenderItemInfo, | ||
Pressable, | ||
StyleSheet, | ||
Text, | ||
View, | ||
} from 'react-native'; | ||
|
||
import ReorderableList, { | ||
ReorderableListItem, | ||
ReorderableListReorderEvent, | ||
reorderItems, | ||
useReorderableDrag, | ||
} from 'react-native-reorderable-list'; | ||
|
||
interface CardProps { | ||
id: string; | ||
color: string; | ||
height: number; | ||
} | ||
|
||
const list: CardProps[] = [ | ||
{id: '0', color: 'red', height: 100}, | ||
{id: '1', color: 'blue', height: 150}, | ||
{id: '2', color: 'green', height: 80}, | ||
{id: '3', color: 'violet', height: 100}, | ||
{id: '4', color: 'orange', height: 120}, | ||
{id: '5', color: 'coral', height: 100}, | ||
{id: '6', color: 'purple', height: 110}, | ||
{id: '7', color: 'chocolate', height: 80}, | ||
{id: '8', color: 'crimson', height: 90}, | ||
{id: '9', color: 'seagreen', height: 90}, | ||
]; | ||
|
||
const Card: React.FC<CardProps> = memo(({id, color, height}) => { | ||
const drag = useReorderableDrag(); | ||
|
||
return ( | ||
<ReorderableListItem> | ||
<Pressable style={[styles.card, {height}]} onLongPress={drag}> | ||
<Text style={[styles.text, {color}]}>Card {id}</Text> | ||
</Pressable> | ||
</ReorderableListItem> | ||
); | ||
}); | ||
|
||
export const HeaderFooterScreen = () => { | ||
const [data, setData] = useState(list); | ||
|
||
const renderItem = ({item}: ListRenderItemInfo<CardProps>) => ( | ||
<Card {...item} /> | ||
); | ||
|
||
const handleReorder = ({from, to}: ReorderableListReorderEvent) => { | ||
const newData = reorderItems(data, from, to); | ||
setData(newData); | ||
}; | ||
|
||
return ( | ||
<ReorderableList | ||
data={data} | ||
onReorder={handleReorder} | ||
renderItem={renderItem} | ||
keyExtractor={item => item.id} | ||
ListHeaderComponent={ | ||
<View style={styles.block}> | ||
<Text style={styles.text}>Header</Text> | ||
</View> | ||
} | ||
ListFooterComponent={ | ||
<View style={styles.block}> | ||
<Text style={styles.text}>Footer</Text> | ||
</View> | ||
} | ||
/> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
card: { | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
margin: 6, | ||
borderRadius: 5, | ||
backgroundColor: 'white', | ||
borderWidth: 1, | ||
borderColor: '#ddd', | ||
}, | ||
text: { | ||
fontSize: 20, | ||
}, | ||
block: { | ||
height: 70, | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}, | ||
}); |
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,81 @@ | ||
import React, {memo, useState} from 'react'; | ||
import {ListRenderItemInfo, Pressable, StyleSheet, Text} from 'react-native'; | ||
|
||
import ReorderableList, { | ||
ReorderableListItem, | ||
ReorderableListReorderEvent, | ||
reorderItems, | ||
useReorderableDrag, | ||
} from 'react-native-reorderable-list'; | ||
|
||
interface CardProps { | ||
id: string; | ||
color: string; | ||
height: number; | ||
} | ||
|
||
const list: CardProps[] = [ | ||
{id: '0', color: 'red', height: 100}, | ||
{id: '1', color: 'blue', height: 150}, | ||
{id: '2', color: 'green', height: 80}, | ||
{id: '3', color: 'violet', height: 100}, | ||
{id: '4', color: 'orange', height: 120}, | ||
{id: '5', color: 'coral', height: 100}, | ||
{id: '6', color: 'purple', height: 110}, | ||
{id: '7', color: 'chocolate', height: 80}, | ||
{id: '8', color: 'crimson', height: 90}, | ||
{id: '9', color: 'seagreen', height: 90}, | ||
]; | ||
|
||
const Card: React.FC<CardProps> = memo(({id, color, height}) => { | ||
const drag = useReorderableDrag(); | ||
|
||
return ( | ||
<ReorderableListItem> | ||
<Pressable style={[styles.card, {height}]} onLongPress={drag}> | ||
<Text style={[styles.text, {color}]}>Card {id}</Text> | ||
</Pressable> | ||
</ReorderableListItem> | ||
); | ||
}); | ||
|
||
export const List = () => { | ||
const [data, setData] = useState(list); | ||
|
||
const renderItem = ({item}: ListRenderItemInfo<CardProps>) => ( | ||
<Card {...item} /> | ||
); | ||
|
||
const handleReorder = ({from, to}: ReorderableListReorderEvent) => { | ||
const newData = reorderItems(data, from, to); | ||
setData(newData); | ||
}; | ||
|
||
return ( | ||
<ReorderableList | ||
data={data} | ||
onReorder={handleReorder} | ||
renderItem={renderItem} | ||
keyExtractor={item => item.id} | ||
contentContainerStyle={styles.contentContainer} | ||
/> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
card: { | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
margin: 6, | ||
borderRadius: 5, | ||
backgroundColor: 'white', | ||
borderWidth: 1, | ||
borderColor: '#ddd', | ||
}, | ||
text: { | ||
fontSize: 20, | ||
}, | ||
contentContainer: { | ||
flexGrow: 1, | ||
}, | ||
}); |
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,22 @@ | ||
import React from 'react'; | ||
import {StyleSheet, View} from 'react-native'; | ||
|
||
import {List} from './List'; | ||
|
||
export const MultipleListsScreen = () => ( | ||
<View style={styles.container}> | ||
<List /> | ||
<View style={styles.separator} /> | ||
<List /> | ||
</View> | ||
); | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
}, | ||
separator: { | ||
height: 20, | ||
backgroundColor: 'lightblue', | ||
}, | ||
}); |
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,94 @@ | ||
import React, {memo, useState} from 'react'; | ||
import { | ||
ListRenderItemInfo, | ||
Pressable, | ||
StyleSheet, | ||
Text, | ||
View, | ||
} from 'react-native'; | ||
|
||
import { | ||
NestedReorderableList, | ||
ReorderableListItem, | ||
ReorderableListReorderEvent, | ||
reorderItems, | ||
useReorderableDrag, | ||
} from 'react-native-reorderable-list'; | ||
|
||
interface CardProps { | ||
id: string; | ||
color: string; | ||
height: number; | ||
} | ||
|
||
const list: CardProps[] = [ | ||
{id: '0', color: 'red', height: 100}, | ||
{id: '1', color: 'blue', height: 150}, | ||
{id: '2', color: 'green', height: 80}, | ||
{id: '3', color: 'violet', height: 100}, | ||
{id: '4', color: 'orange', height: 120}, | ||
]; | ||
|
||
const Card: React.FC<CardProps> = memo(({id, color, height}) => { | ||
const drag = useReorderableDrag(); | ||
|
||
return ( | ||
<ReorderableListItem> | ||
<Pressable style={[styles.card, {height}]} onLongPress={drag}> | ||
<Text style={[styles.text, {color}]}>Card {id}</Text> | ||
</Pressable> | ||
</ReorderableListItem> | ||
); | ||
}); | ||
|
||
interface NestedListProps { | ||
index: number; | ||
} | ||
|
||
export const NestedList: React.FC<NestedListProps> = ({index}) => { | ||
const [data, setData] = useState(list); | ||
|
||
const renderItem = ({item}: ListRenderItemInfo<CardProps>) => ( | ||
<Card {...item} /> | ||
); | ||
|
||
const handleReorder = ({from, to}: ReorderableListReorderEvent) => { | ||
const newData = reorderItems(data, from, to); | ||
setData(newData); | ||
}; | ||
|
||
return ( | ||
<NestedReorderableList | ||
data={data} | ||
onReorder={handleReorder} | ||
renderItem={renderItem} | ||
keyExtractor={item => item.id} | ||
scrollEnabled={false} | ||
ListHeaderComponent={ | ||
<View style={styles.header}> | ||
<Text style={styles.text}>List {index}</Text> | ||
</View> | ||
} | ||
/> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
card: { | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
margin: 6, | ||
borderRadius: 5, | ||
backgroundColor: 'white', | ||
borderWidth: 1, | ||
borderColor: '#ddd', | ||
}, | ||
text: { | ||
fontSize: 20, | ||
}, | ||
header: { | ||
height: 40, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
}, | ||
}); |
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,20 @@ | ||
import React from 'react'; | ||
import {StyleSheet} from 'react-native'; | ||
|
||
import {ScrollViewContainer} from 'react-native-reorderable-list'; | ||
|
||
import {NestedList} from './NestedList'; | ||
|
||
export const NestedListsScreen = () => ( | ||
<ScrollViewContainer style={styles.container}> | ||
<NestedList index={0} /> | ||
<NestedList index={1} /> | ||
<NestedList index={2} /> | ||
</ScrollViewContainer> | ||
); | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
}, | ||
}); |
Oops, something went wrong.