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.4
  • Source
  • npm
  • Socket score

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

react-native-tree-multi-select

Tree view with multi selection using checkbox + search filtering.

npm version License Workflow Status Static Badge GitHub issues

demo

Installation

Using yarn

yarn add react-native-tree-multi-select && cd ios && pod install

using npm:

npm install react-native-tree-multi-select && cd ios && pod install

Dependencies required 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 for these dependencies.

Usage

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

const myData: TreeNode[] = [...];

export function MyAppScreen(){
  const treeViewRef = React.useRef<TreeViewRef | null>(null);
  
  // Recommended to use debounce for search function
  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"]);
  }
  
  const handleSelectionChange = (checkedIds: string[]) => {
    // NOTE: Do something with updated checkedIds here
  };
  const handleExpanded = (expandedIds: string[]) => {
    // NOTE: Do something with updated expandedIds here
  };
  
  // 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(
    // ...
    <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
treeFlashListPropsTreeFlatListPropsNoProps for the flash list
checkBoxViewStylePropsCheckBoxViewStylePropsNoProps for the checkbox view
CheckboxComponentComponentType<CheckBoxViewProps>NoA custom checkbox component
ExpandCollapseIconComponentComponentType<ExpandIconProps>NoA custom expand/collapse icon component
ExpandCollapseTouchableComponentComponentType<TouchableOpacityProps>NoA custom expand/collapse touchable component

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.

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)

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           UPI_Donation_Button           Paypal_Donation_Button


Made with create-react-native-library

Keywords

FAQs

Package last updated on 10 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