Skip to content

Commit d0646e7

Browse files
M-i-k-e-lethanshar
andauthored
Feat/sortable list no scroll (#1958)
* Initial commit * Simlpify AnimatedFlatListProps * Fix some prop * A little more refactoring * Rename * Move extra dragged style to the user (this solves some issues) * Increase threshold * Properly export SortableListItemDecorator * Fix docs, add API file and disable dragging while scrolling by default * Fix threshold criteria (mostly) * Add scrollWhileDragging to the screen * Fix screen visual bug on Android * Fix docs * Remove scroll related amd .d files * Refactor * Refactor * New implementation * Revert old changes * Oops * Move GestureHandlerRootView to the component * Move onItemLayout impl to list * Add haptic * Improve example \ default UI * Fix margin Co-authored-by: Ethan Sharabi <ethans@wix.com>
1 parent 26bfbd3 commit d0646e7

18 files changed

+443
-1
lines changed

demo/src/assets/icons/drag.png

161 Bytes
Loading

demo/src/assets/icons/drag@1.5x.png

211 Bytes
Loading

demo/src/assets/icons/drag@2x.png

279 Bytes
Loading

demo/src/assets/icons/drag@3x.png

405 Bytes
Loading

demo/src/assets/icons/drag@4x.png

587 Bytes
Loading

demo/src/configurations.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import {Assets, Colors, Typography, Spacings, Incubator} from 'react-native-ui-l
33
export const loadDemoConfigurations = () => {
44
Assets.loadAssetsGroup('icons.demo', {
55
chevronDown: require('./assets/icons/chevronDown.png'),
6+
chevronRight: require('./assets/icons/chevronRight.png'),
67
add: require('./assets/icons/add.png'),
78
camera: require('./assets/icons/cameraSelected.png'),
89
close: require('./assets/icons/close.png'),
910
dashboard: require('./assets/icons/dashboard.png'),
11+
drag: require('./assets/icons/drag.png'),
1012
image: require('./assets/icons/image.png'),
1113
plus: require('./assets/icons/plus.png'),
1214
refresh: require('./assets/icons/refresh.png'),

demo/src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ module.exports = {
111111
get SkeletonViewScreen() {
112112
return require('./screens/componentScreens/SkeletonViewScreen').default;
113113
},
114+
get SortableListScreen() {
115+
return require('./screens/componentScreens/SortableListScreen').default;
116+
},
114117
get StepperScreen() {
115118
return require('./screens/componentScreens/StepperScreen').default;
116119
},

demo/src/screens/MenuStructure.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ export const navigationData = {
8383
{title: 'Basic List', tags: 'basic list', screen: 'unicorn.lists.BasicListScreen'},
8484
{title: 'Contacts List', tags: 'list contacts', screen: 'unicorn.lists.ContactsListScreen'},
8585
{title: 'Conversation List', tags: 'list conversation', screen: 'unicorn.lists.ConversationListScreen'},
86-
{title: 'Drawer', tags: 'drawer', screen: 'unicorn.components.DrawerScreen'}
86+
{title: 'Drawer', tags: 'drawer', screen: 'unicorn.components.DrawerScreen'},
87+
{title: 'SortableList', tags: 'sortable list drag', screen: 'unicorn.components.SortableListScreen'}
8788
]
8889
},
8990
LayoutsAndTemplates: {
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import _ from 'lodash';
2+
import React, {useCallback} from 'react';
3+
import {StyleSheet} from 'react-native';
4+
import {SortableList, View, TouchableOpacity, Text, Icon, Assets, Colors} from 'react-native-ui-lib';
5+
import {renderHeader} from '../ExampleScreenPresenter';
6+
7+
interface Item {
8+
originalIndex: number;
9+
}
10+
11+
const data = _.times(30, index => {
12+
return {
13+
originalIndex: index
14+
};
15+
});
16+
17+
const SortableListScreen = () => {
18+
const keyExtractor = useCallback((item: Item) => {
19+
return `${item.originalIndex}`;
20+
}, []);
21+
22+
const onOrderChange = useCallback((newData: Item[]) => {
23+
console.log('New order:', newData);
24+
}, []);
25+
26+
const renderItem = useCallback(({item, index: _index}: {item: Item; index: number}) => {
27+
return (
28+
<TouchableOpacity
29+
style={styles.itemContainer}
30+
onPress={() => console.log('Original index is', item.originalIndex)}
31+
// overriding the BG color to anything other than white will cause Android's elevation to fail
32+
// backgroundColor={Colors.red30}
33+
centerV
34+
marginH-page
35+
>
36+
<View flex row spread centerV>
37+
<Icon source={Assets.icons.demo.drag} tintColor={Colors.$iconDisabled}/>
38+
<Text center $textDefault>
39+
{item.originalIndex}
40+
</Text>
41+
<Icon source={Assets.icons.demo.chevronRight} tintColor={Colors.$iconDefault}/>
42+
</View>
43+
</TouchableOpacity>
44+
);
45+
}, []);
46+
47+
return (
48+
<View flex bg-$backgroundDefault>
49+
{renderHeader('Sortable List', {'margin-10': true})}
50+
<View flex useSafeArea>
51+
<SortableList data={data} renderItem={renderItem} keyExtractor={keyExtractor} onOrderChange={onOrderChange}/>
52+
</View>
53+
</View>
54+
);
55+
};
56+
57+
export default SortableListScreen;
58+
const styles = StyleSheet.create({
59+
itemContainer: {
60+
height: 52,
61+
borderColor: Colors.$outlineDefault,
62+
borderBottomWidth: 1
63+
}
64+
});

demo/src/screens/componentScreens/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export function registerScreens(registrar) {
4646
registrar('unicorn.components.SkeletonViewScreen', () => require('./SkeletonViewScreen').default);
4747
registrar('unicorn.components.SliderScreen', () => require('./SliderScreen').default);
4848
registrar('unicorn.components.SortableGridListScreen', () => require('./SortableGridListScreen').default);
49+
registrar('unicorn.components.SortableListScreen', () => require('./SortableListScreen').default);
4950
registrar('unicorn.components.StackAggregatorScreen', () => require('./StackAggregatorScreen').default);
5051
registrar('unicorn.components.StepperScreen', () => require('./StepperScreen').default);
5152
registrar('unicorn.components.SwitchScreen', () => require('./SwitchScreen').default);

0 commit comments

Comments
 (0)