show/update focused element

Summary: This was already implemented in the old versin of layout inspector and got lost during the refactoring. When using talkback, the focused view is highlighted in green in the a11y inspector.

Reviewed By: passy

Differential Revision: D15294025

fbshipit-source-id: 92cc015e4bc726515e433b7b96f924246916972d
This commit is contained in:
Daniel Büchele
2019-05-10 06:16:07 -07:00
committed by Facebook Github Bot
parent e38fc0ca90
commit ffea42e57f
2 changed files with 25 additions and 2 deletions

View File

@@ -66,6 +66,18 @@ export default class Inspector extends Component<Props> {
: this.props.persistedState.elements; : this.props.persistedState.elements;
}; };
focused = () => {
if (!this.props.ax) {
return null;
}
// $FlowFixMe: Object.values returns Array<mixed>
const elements: Array<Element> = Object.values(
this.props.persistedState.AXelements,
);
return elements.find(i => i?.data?.Accessibility?.['accessibility-focused'])
?.id;
};
componentDidMount() { componentDidMount() {
this.props.client.call(this.call().GET_ROOT).then((root: Element) => { this.props.client.call(this.call().GET_ROOT).then((root: Element) => {
this.props.setPersistedState({ this.props.setPersistedState({
@@ -102,6 +114,16 @@ export default class Inspector extends Component<Props> {
this.getAndExpandPath(path); this.getAndExpandPath(path);
}, },
); );
if (this.props.ax) {
this.props.client.subscribe('axFocusEvent', () => {
// update all nodes, to find new focused node
this.getNodes(Object.keys(this.props.persistedState.AXelements), {
force: true,
ax: true,
});
});
}
} }
componentDidUpdate(prevProps: Props) { componentDidUpdate(prevProps: Props) {
@@ -234,6 +256,7 @@ export default class Inspector extends Component<Props> {
selected={this.selected()} selected={this.selected()}
root={this.root()} root={this.root()}
elements={this.elements()} elements={this.elements()}
focused={this.focused()}
/> />
) : null; ) : null;
} }

View File

@@ -27,7 +27,7 @@ const backgroundColor = props => {
if (props.selected) { if (props.selected) {
return colors.macOSTitleBarIconSelected; return colors.macOSTitleBarIconSelected;
} else if (props.focused) { } else if (props.focused) {
return colors.lime; return '#00CF52';
} else if (props.even) { } else if (props.even) {
return colors.light02; return colors.light02;
} else { } else {
@@ -39,7 +39,7 @@ const backgroundColorHover = props => {
if (props.selected) { if (props.selected) {
return colors.macOSTitleBarIconSelected; return colors.macOSTitleBarIconSelected;
} else if (props.focused) { } else if (props.focused) {
return colors.lime; return '#00CF52';
} else { } else {
return '#EBF1FB'; return '#EBF1FB';
} }