element expanding
Summary: Previously nodes were always marked as expanded, when they were loaded. In some cases this caused a node to be marked as expanded, but its children not being loaded. This changes the behaviour to only mark a node as expanded, once its children are loaded. Reviewed By: jknoxville Differential Revision: D14209814 fbshipit-source-id: f825d6a066373be932e42b9612a1bf78877b12aa
This commit is contained in:
committed by
Facebook Github Bot
parent
f12144be38
commit
5f5a38f1fe
@@ -137,32 +137,29 @@ export default class Inspector extends Component<Props> {
|
|||||||
// element has no children so we're as deep as we can be
|
// element has no children so we're as deep as we can be
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return this.getChildren(element.id, {}, true).then(
|
return this.getChildren(element.id, {}).then((elements: Array<Element>) => {
|
||||||
(elements: Array<Element>) => {
|
if (element.children.length >= 2) {
|
||||||
if (element.children.length >= 2) {
|
// element has two or more children so we can stop expanding
|
||||||
// element has two or more children so we can stop expanding
|
return;
|
||||||
return;
|
}
|
||||||
}
|
return this.performInitialExpand(this.elements()[element.children[0]]);
|
||||||
return this.performInitialExpand(this.elements()[element.children[0]]);
|
});
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getChildren(
|
async getChildren(
|
||||||
id: ElementID,
|
id: ElementID,
|
||||||
options: GetNodesOptions,
|
options: GetNodesOptions,
|
||||||
expanded?: boolean,
|
|
||||||
): Promise<Array<Element>> {
|
): Promise<Array<Element>> {
|
||||||
if (!this.elements()[id]) {
|
if (!this.elements()[id]) {
|
||||||
await this.getNodes([id], options, expanded);
|
await this.getNodes([id], options);
|
||||||
}
|
}
|
||||||
return this.getNodes(this.elements()[id].children, options, expanded);
|
this.updateElement(id, {expanded: true});
|
||||||
|
return this.getNodes(this.elements()[id].children, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
getNodes(
|
getNodes(
|
||||||
ids: Array<ElementID> = [],
|
ids: Array<ElementID> = [],
|
||||||
options: GetNodesOptions,
|
options: GetNodesOptions,
|
||||||
expanded?: boolean,
|
|
||||||
): Promise<Array<Element>> {
|
): Promise<Array<Element>> {
|
||||||
const {forAccessibilityEvent} = options;
|
const {forAccessibilityEvent} = options;
|
||||||
|
|
||||||
@@ -174,12 +171,7 @@ export default class Inspector extends Component<Props> {
|
|||||||
selected: false,
|
selected: false,
|
||||||
})
|
})
|
||||||
.then(({elements}) => {
|
.then(({elements}) => {
|
||||||
elements.forEach(e => {
|
elements.forEach(e => this.updateElement(e.id, e));
|
||||||
if (typeof expanded === 'boolean') {
|
|
||||||
e.expanded = expanded;
|
|
||||||
}
|
|
||||||
this.updateElement(e.id, e);
|
|
||||||
});
|
|
||||||
return elements;
|
return elements;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -188,11 +180,9 @@ export default class Inspector extends Component<Props> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getAndExpandPath(path: Array<ElementID>) {
|
getAndExpandPath(path: Array<ElementID>) {
|
||||||
return Promise.all(path.map(id => this.getChildren(id, {}, true))).then(
|
return Promise.all(path.map(id => this.getChildren(id, {}))).then(() => {
|
||||||
() => {
|
this.onElementSelected(path[path.length - 1]);
|
||||||
this.onElementSelected(path[path.length - 1]);
|
});
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onElementSelected = debounce((selectedKey: ElementID) => {
|
onElementSelected = debounce((selectedKey: ElementID) => {
|
||||||
|
|||||||
@@ -33,11 +33,13 @@ type State = {|
|
|||||||
searchResults: ?ElementSearchResultSet,
|
searchResults: ?ElementSearchResultSet,
|
||||||
|};
|
|};
|
||||||
|
|
||||||
|
export type ElementMap = {[key: ElementID]: Element};
|
||||||
|
|
||||||
export type PersistedState = {|
|
export type PersistedState = {|
|
||||||
rootElement: ?ElementID,
|
rootElement: ?ElementID,
|
||||||
rootAXElement: ?ElementID,
|
rootAXElement: ?ElementID,
|
||||||
elements: {[key: ElementID]: Element},
|
elements: ElementMap,
|
||||||
AXelements: {[key: ElementID]: Element},
|
AXelements: ElementMap,
|
||||||
|};
|
|};
|
||||||
|
|
||||||
export default class Layout extends FlipperPlugin<State, void, PersistedState> {
|
export default class Layout extends FlipperPlugin<State, void, PersistedState> {
|
||||||
@@ -59,6 +61,7 @@ export default class Layout extends FlipperPlugin<State, void, PersistedState> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
// reset the data, as it might be outdated
|
||||||
this.props.setPersistedState(Layout.defaultPersistedState);
|
this.props.setPersistedState(Layout.defaultPersistedState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user