Skip to content

Commit ff97918

Browse files
committed
feat: add an extra callback prop called onNodeExpanded to get response from user action
1 parent 1a766fd commit ff97918

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/Nodes.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ export class JSONNestedNode extends React.PureComponent {
236236
shouldExpandNode: PropTypes.func,
237237
sortObjectKeys: PropTypes.oneOfType([PropTypes.func, PropTypes.bool]),
238238
styling: PropTypes.func.isRequired,
239+
onNodeExpanded: PropTypes.func,
239240
}
240241

241242
static defaultProps = {
@@ -260,7 +261,14 @@ export class JSONNestedNode extends React.PureComponent {
260261
}
261262
}
262263

263-
handlePress = () => this.setState({ expanded: !this.state.expanded })
264+
handlePress = () => {
265+
const { onNodeExpanded, keyPath, data, level } = this.props
266+
const { expanded } = this.state
267+
this.setState({ expanded: !expanded })
268+
if (onNodeExpanded) {
269+
onNodeExpanded(!expanded, keyPath, data, level)
270+
}
271+
}
264272

265273
render() {
266274
const {

src/types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ declare module 'react-native-json-tree' {
2222
postprocessValue?: (value: Renderable) => any;
2323
sortObjectKeys?: boolean | ((a: Renderable, b: Renderable) => number);
2424
shouldExpandNode?: (_keyName: any, _data: any, level: number) => boolean;
25+
onNodeExpanded?: (expanded: boolean, keyPath: any, data: any, level: number) => void;
2526
theme?: Theme;
2627
valueRenderer?: (value: Renderable | undefined) => ReactNode;
2728
}

0 commit comments

Comments
 (0)