Skip to content

Commit 3bd6d9b

Browse files
authored
perf: disable accessibility for layout views (#10482)
a11y is enabled by default on controls still, this just disables on layouts alone as unnecessary. It can be enabled on a per layout view basis if needed anytime.
1 parent d34a439 commit 3bd6d9b

File tree

6 files changed

+25
-13
lines changed

6 files changed

+25
-13
lines changed

packages/core/accessibility/accessibility-properties.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ function makePropertyEnumConverter<T>(enumValues) {
2626

2727
export const accessibilityEnabledProperty = new CssProperty<Style, boolean>({
2828
name: 'accessible',
29+
defaultValue: true,
2930
cssName: 'a11y-enabled',
3031
valueConverter: booleanConverter,
3132
});

packages/core/ui/core/view-base/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { AlignSelf, FlexGrow, FlexShrink, FlexWrapBefore, Order } from '../../la
22
import { Page } from '../../page';
33
import { CoreTypes } from '../../../core-types';
44
import { Property, CssProperty, CssAnimationProperty, InheritedProperty, clearInheritedProperties, propagateInheritableProperties, propagateInheritableCssProperties, initNativeView } from '../properties';
5-
import { setupAccessibleView } from '../../../accessibility';
65
import { CSSUtils } from '../../../css/system-classes';
76
import { Source } from '../../../utils/debug';
87
import { Binding, BindingOptions } from '../bindable';
@@ -599,7 +598,6 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
599598

600599
return true;
601600
});
602-
setupAccessibleView(<any>this);
603601

604602
this._emit('loaded');
605603
}

packages/core/ui/core/view/index.android.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -820,8 +820,9 @@ export class View extends ViewCommon {
820820

821821
[accessibilityEnabledProperty.setNative](value: boolean): void {
822822
this.nativeViewProtected.setFocusable(!!value);
823-
824-
updateAccessibilityProperties(this);
823+
if (value) {
824+
updateAccessibilityProperties(this);
825+
}
825826
}
826827

827828
[accessibilityIdentifierProperty.setNative](value: string): void {
@@ -1257,6 +1258,15 @@ export class View extends ViewCommon {
12571258

12581259
export class ContainerView extends View {
12591260
public iosOverflowSafeArea: boolean;
1261+
1262+
constructor() {
1263+
super();
1264+
/**
1265+
* mark accessible as false without triggering proerty change
1266+
* equivalent to changing the default
1267+
*/
1268+
this.style[accessibilityEnabledProperty.key] = false;
1269+
}
12601270
}
12611271

12621272
export class CustomLayoutView extends ContainerView implements CustomLayoutViewDefinition {

packages/core/ui/core/view/index.d.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,6 @@ export abstract class View extends ViewCommon {
228228
*/
229229
color: Color;
230230

231-
/**
232-
* If `true` the element is an accessibility element and all the children will be treated as a single selectable component.
233-
*/
234-
accessible: boolean;
235-
236231
/**
237232
* Hide the view and its children from the a11y service
238233
*/

packages/core/ui/core/view/index.ios.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,8 +677,9 @@ export class View extends ViewCommon implements ViewDefinition {
677677

678678
[accessibilityEnabledProperty.setNative](value: boolean): void {
679679
this.nativeViewProtected.isAccessibilityElement = !!value;
680-
681-
updateAccessibilityProperties(this);
680+
if (value) {
681+
updateAccessibilityProperties(this);
682+
}
682683
}
683684

684685
[accessibilityIdentifierProperty.getDefault](): string {
@@ -1062,6 +1063,11 @@ export class ContainerView extends View {
10621063
constructor() {
10631064
super();
10641065
this.iosOverflowSafeArea = true;
1066+
/**
1067+
* mark accessible as false without triggering proerty change
1068+
* equivalent to changing the default
1069+
*/
1070+
this.style[accessibilityEnabledProperty.key] = false;
10651071
}
10661072
}
10671073

packages/core/ui/core/view/view-common.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { EventData } from '../../../data/observable';
1212
import { Trace } from '../../../trace';
1313
import { CoreTypes } from '../../../core-types';
1414
import { ViewHelper } from './view-helper';
15+
import { setupAccessibleView } from '../../../accessibility';
1516

1617
import { PercentLength } from '../../styling/style-properties';
1718

@@ -177,6 +178,9 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
177178
}
178179
}
179180
super.onLoaded();
181+
if (this.accessible) {
182+
setupAccessibleView(this);
183+
}
180184
}
181185

182186
public _closeAllModalViewsInternal(): boolean {
@@ -810,11 +814,9 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
810814

811815
get accessible(): boolean {
812816
return this.style.accessible;
813-
// return this._accessible;
814817
}
815818
set accessible(value: boolean) {
816819
this.style.accessible = value;
817-
// this._accessible = value;
818820
}
819821

820822
get accessibilityHidden(): boolean {

0 commit comments

Comments
 (0)