New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-native-tree-multi-select

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-tree-multi-select

Tree view with multi selection using checkbox

  • 0.8.9
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
74
decreased by-56.98%
Maintainers
1
Weekly downloads
 
Created
Source

react-native-tree-multi-select

Super-fast Tree view with multi-selection capabilities, using checkboxes and search filtering.

npm version License Workflow Status Static Badge GitHub issues

demo

Installation

Using yarn

yarn add react-native-tree-multi-select

using npm:

npm install react-native-tree-multi-select

Dependencies that need to be installed for this library to work:

  1. @shopify/flash-list
  2. react-native-paper
  3. react-native-vector-icons

Make sure to follow the native-related installation instructions for these dependencies.

Usage

import {
  TreeView,
  type TreeNode,
  type TreeViewRef
} from 'react-native-tree-multi-select';

// Refer to the Properties table below or the example app for the TreeNode type
const myData: TreeNode[] = [...];

export function TreeViewUsageExample(){
  const treeViewRef = React.useRef<TreeViewRef | null>(null);
  
  // It's recommended to use debounce for the search function (refer to the example app)
  function triggerSearch(text: string){
    // Pass search text to the tree along with the keys on which search is to be done(optional)
    treeViewRef.current?.setSearchText(text, ["name"]);
  }
  
  // Callback functions for check and expand state changes:
  const handleSelectionChange = (checkedIds: string[]) => {
    // NOTE: Do something with updated checkedIds here
  };
  const handleExpanded = (expandedIds: string[]) => {
    // NOTE: Do something with updated expandedIds here
  };

  // Expand collapse calls using ref
  const expandAllPress = () => treeViewRef.current?.expandAll?.();
  const collapseAllPress = () => treeViewRef.current?.collapseAll?.();

  // Multi-selection function calls using ref
  const onSelectAllPress = () => treeViewRef.current?.selectAll?.();
  const onUnselectAllPress = () => treeViewRef.current?.unselectAll?.();
  const onSelectAllFilteredPress = () => treeViewRef.current?.selectAllFiltered?.();
  const onUnselectAllFilteredPress = () => treeViewRef.current?.unselectAllFiltered?.();
  
  return(
    // ... Remember to keep a fixed height for the parent. Read Flash List docs to know why
    <TreeView
      ref={treeViewRef}
      data={myData}
      onCheck={handleSelectionChange}
      onExpand={handleExpanded}
    />
  );
}

Properties

PropertyTypeRequiredDescription
dataTreeNode[]YesAn array of TreeNode objects
onCheck(checkedIds: string[]) => voidNoCallback when a checkbox is checked
onExpand(expandedIds: string[]) => voidNoCallback when a node is expanded
preselectedIdsstring[]NoAn array of ids that should be preselected
indentationMultipliernumberNoIndentation (marginStart) per level (defaults to 15)
treeFlashListPropsTreeFlatListPropsNoProps for the flash list
checkBoxViewStylePropsCheckBoxViewStylePropsNoProps for the checkbox view
CheckboxComponentComponentType<CheckBoxViewProps>NoA custom checkbox component. Defaults to React Native Paper's Checkbox
ExpandCollapseIconComponentComponentType<ExpandIconProps>NoA custom expand/collapse icon component
ExpandCollapseTouchableComponentComponentType<TouchableOpacityProps>
(React Native's TouchableOpacityProps)
NoA custom expand/collapse touchable component
TreeNode
PropertyTypeRequiredDescription
idstringYesUnique identifier for the node
namestringYesThe display name of the node
childrenTreeNode[]NoAn array of child TreeNode objects
[key: string]anyNoAny additional properties for the node
(May be useful to perform search on)
TreeViewRef
PropertyTypeDescription
selectAll() => voidSelects all nodes
unselectAll() => voidUnselects all nodes
selectAllFiltered() => voidSelects all filtered nodes
unselectAllFiltered() => voidUnselects all filtered nodes
expandAll() => voidExpands all nodes
collapseAll() => voidCollapses all nodes
setSearchText(searchText: string, searchKeys?: string[]) => voidSet the search text and optionally the search keys. Default search key is "name"

Recommended to call this inside a debounced function if you find any performance issue otherwise.
CheckBoxViewStyleProps
PropertyTypeRequiredDescription
outermostParentViewStyleStyleProp<ViewStyle>NoOptional style modifier for the outermost parent view.
checkboxParentViewStyleStyleProp<ViewStyle>NoOptional style modifier for the checkbox parent view.
textTouchableStyleStyleProp<ViewStyle>NoOptional style modifier for the text touchable style.
checkboxPropsCheckboxPropsNoOptional props for the checkbox component.
textPropsTextProps
(React Native)
NoOptional props for the text component.
CheckboxProps

All properties of RNPaperCheckboxAndroidProps(from react-native-paper) except for onPress and status

TreeFlatListProps

All properties of FlashListProps(from @shopify/flash-list) except for data and renderItem

ExpandIconProps
PropertyTypeRequiredDescription
isExpandedbooleanYesIndicates if the icon is expanded

More customization options are on the way 🙌


Contributing

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

License

MIT

Support the project

LiberPay_Donation_Button           Paypal_Donation_Button           Paypal_Donation_Button


Made with create-react-native-library

Keywords

FAQs

Package last updated on 12 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc