-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathApp.tsx
More file actions
43 lines (39 loc) · 1.21 KB
/
App.tsx
File metadata and controls
43 lines (39 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import React from 'react';
import { SafeAreaView, Text, View } from 'react-native';
import { TreeDataTypes, TreeSelect } from 'react-native-tree-selection';
import { StaticData } from './constants/StaticData';
import { styles } from './theme';
import { isArray, isEmpty } from 'lodash';
const childKey = 'data';
const App = () => {
const customRenderItem = (item: TreeDataTypes):JSX.Element => {
console.log('customRenderItem', item);
const hasChildren = isArray(item?.[childKey]) && !isEmpty(item[childKey]);
return(
<View>
{hasChildren ?
<Text>Custom Parent Render: {item.title}</Text> :
<Text>Custom Child Render: {item.title}</Text>
}
</View>
)
};
return (
<SafeAreaView style={styles.container}>
<TreeSelect
data={StaticData}
onParentPress={(item: TreeDataTypes) => {
console.log('onPressParent', item);
}}
onChildPress={(item: TreeDataTypes) => {
console.log('onPressChild', item);
}}
onCheckBoxPress={(item: TreeDataTypes[]) => {
console.log('onCheckBox', item);
}}
renderItem={customRenderItem}
/>
</SafeAreaView>
);
};
export default App;