0.1.17 • Published 9 months ago

react-native-tableview-list v0.1.17

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

react-native-tableview-list

SectionList-like component backed by a UITableView (iOS only).

The aim is to have the fully native experience: swipe to delete (with correct haptics and automatic dismissal when scrolling), press and hold menus etc. Performance is probably on par with the default SectionList component.

Only renders custom cells - if you need the standard styles, use react-native-tableview. This library will also handle custom cells - but doing so breaks stuff like Context.

Screenshot 1Screenshot 2Screenshot 3

Installation

npm install react-native-tableview-list

Usage

import TableviewListView from 'react-native-tableview-list';

<TableviewListView
  sections={[{ title: 'title', key: 'key', data: [1, 2, 3] }]}
  rowHeight={50}
  renderItem={({ item }) => (
    <>
      <Text>{item}</Text>
      <View style={styles.lozenge} />
    </>
  )}
/>;

If you need a FlatList-like list, pass a single section with the title set to an empty string ('').

Props

Properties marked with an asterisk (*) are required

NameTypeDescription
sections *Section[]See below for props
renderItem *({ item, index, section }) => ReactElementRender row
keyExtractor(Row, index, sectionIndex) => stringNeeded if data does not have a key or id property
rowHeight *numberCurrently all rows must have the same, fixed height
separatorInset{ left?: number, right?: number }Margin applied to the left and right of each separator
separatorColorstringColor string or PlatformColor
cellContainerStylestyleCustomise cell style: do not chagne postion, width, or height
onPressRow({ item, index, section }) => voidCalled when a row is pressed
editingbooleanEnable indicators for moving and deleting rows
moveRows'none' or 'within-section'Allows re-ordering of rows
onMoveRow({ fromSection, fromItem, fromIndex, toSection, toItem, toIndex }) => voidCalled when a row is moved (see moveRows) - you MUST udpate your data when this is called
onDeleteRow({ item, index, section }) => voidEnables swipe to delete - you MUST delete the item when this is called
menuMenuItem[]See below for props
leadingActionsActionItem[]See below for props
trailingActionsActionItem[]See below for props
initialNumToRendernumberSee VirtualisedList
maxToRenderPerBatchnumberSee VirtualisedList
windowSizenumberSee VirtualisedList
updateCellsBatchingPeriodnumberSee VirtualisedList
ListEmptyComponentReactElementDisplayed when there's no data

Types

type Section<Row> = {
  title: string;
  key?: string;
  data: Row[];
  // Enables press and hold interaction
  menu?: MenuItem<Row>[];
  // Swipe actions for left-hand-side (in LTR layouts)
  leadingActions?: ActionItem<Row>[];
  // Swipe actions for right-hand-side (in LTR layouts)
  trailingActions?: ActionItem<Row>[];
  // Allows re-ordering of rows within a section
  // **MUST** be used with onMoveRow
  moveRows?: 'none' | 'within-section';
  // Used with moveRows property
  // You **MUST** update your data when this is called
  onMoveRow: (e: MoveRowEvent<Row>) => void;
  // Enables swipe to delete for section
  // You **MUST** delete the item when this is called
  onDeleteRow?: (e: RowEvent<Row>) => void;
};

type MenuItem<Row> = {
  title: string;
  key?: string;
  // See SF Symbols
  systemIcon: string;
  // Red text
  destructive?: boolean;
  // Greyed out
  disabled?: boolean;
  // Display children inline - rather than as a submenu
  inline?: boolean;
  // Submenu
  children?: MenuItem<Row>[];
  // On press
  onPress: (e: RowEvent<Row>) => void;
};

type ActionItem<Row> = {
  title: string;
  key?: string;
  destructive?: boolean;
  onPress?: (e: RowEvent<Row>) => void;
};

type RowEvent<Row> = {
  item: Row;
  section: Section<Row>;
  index: number;
};

type MoveRowEvent<Row> = {
  fromItem: Row;
  fromSection: Section<Row>;
  fromIndex: number;
  toItem: Row;
  toSection: Section<Row>;
  toIndex: number;
};

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

0.1.17

9 months ago

0.1.15

2 years ago

0.1.13

2 years ago

0.1.14

2 years ago

0.1.10

2 years ago

0.1.11

2 years ago

0.1.12

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.9

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.1

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.0

3 years ago