mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
feat(core): first class a11y support (#8909)
This commit is contained in:
committed by
Nathan Walker
parent
577b1e9dad
commit
f2e21a50a7
@@ -3,9 +3,44 @@ import { Background } from '../styling/background';
|
||||
import { SliderBase, valueProperty, minValueProperty, maxValueProperty } from './slider-common';
|
||||
import { colorProperty, backgroundColorProperty, backgroundInternalProperty } from '../styling/style-properties';
|
||||
import { Color } from '../../color';
|
||||
import { AccessibilityDecrementEventData, AccessibilityIncrementEventData } from '.';
|
||||
|
||||
export * from './slider-common';
|
||||
|
||||
@NativeClass()
|
||||
class TNSSlider extends UISlider {
|
||||
public owner: WeakRef<Slider>;
|
||||
|
||||
public static initWithOwner(owner: WeakRef<Slider>) {
|
||||
const slider = TNSSlider.new() as TNSSlider;
|
||||
slider.owner = owner;
|
||||
|
||||
return slider;
|
||||
}
|
||||
|
||||
public accessibilityIncrement() {
|
||||
const owner = this.owner.get();
|
||||
if (!owner) {
|
||||
this.value += 10;
|
||||
} else {
|
||||
this.value = owner._handlerAccessibilityIncrementEvent();
|
||||
}
|
||||
|
||||
this.sendActionsForControlEvents(UIControlEvents.ValueChanged);
|
||||
}
|
||||
|
||||
public accessibilityDecrement() {
|
||||
const owner = this.owner.get();
|
||||
if (!owner) {
|
||||
this.value += 10;
|
||||
} else {
|
||||
this.value = owner._handlerAccessibilityDecrementEvent();
|
||||
}
|
||||
|
||||
this.sendActionsForControlEvents(UIControlEvents.ValueChanged);
|
||||
}
|
||||
}
|
||||
|
||||
@NativeClass
|
||||
class SliderChangeHandlerImpl extends NSObject {
|
||||
private _owner: WeakRef<Slider>;
|
||||
@@ -30,11 +65,11 @@ class SliderChangeHandlerImpl extends NSObject {
|
||||
}
|
||||
|
||||
export class Slider extends SliderBase {
|
||||
nativeViewProtected: UISlider;
|
||||
nativeViewProtected: TNSSlider;
|
||||
private _changeHandler: NSObject;
|
||||
|
||||
public createNativeView() {
|
||||
return UISlider.new();
|
||||
public createNativeView(): TNSSlider {
|
||||
return TNSSlider.initWithOwner(new WeakRef(this));
|
||||
}
|
||||
|
||||
public initNativeView(): void {
|
||||
@@ -47,7 +82,7 @@ export class Slider extends SliderBase {
|
||||
nativeView.addTargetActionForControlEvents(this._changeHandler, 'sliderValueChanged', UIControlEvents.ValueChanged);
|
||||
}
|
||||
|
||||
public disposeNativeView() {
|
||||
public disposeNativeView(): void {
|
||||
this._changeHandler = null;
|
||||
super.disposeNativeView();
|
||||
}
|
||||
@@ -98,4 +133,36 @@ export class Slider extends SliderBase {
|
||||
[backgroundInternalProperty.setNative](value: Background) {
|
||||
//
|
||||
}
|
||||
|
||||
private getAccessibilityStep(): number {
|
||||
if (!this.accessibilityStep || this.accessibilityStep <= 0) {
|
||||
return 10;
|
||||
}
|
||||
|
||||
return this.accessibilityStep;
|
||||
}
|
||||
|
||||
public _handlerAccessibilityIncrementEvent(): number {
|
||||
const args: AccessibilityIncrementEventData = {
|
||||
object: this,
|
||||
eventName: SliderBase.accessibilityIncrementEvent,
|
||||
value: this.value + this.getAccessibilityStep(),
|
||||
};
|
||||
|
||||
this.notify(args);
|
||||
|
||||
return args.value;
|
||||
}
|
||||
|
||||
public _handlerAccessibilityDecrementEvent(): number {
|
||||
const args: AccessibilityDecrementEventData = {
|
||||
object: this,
|
||||
eventName: SliderBase.accessibilityIncrementEvent,
|
||||
value: this.value - this.getAccessibilityStep(),
|
||||
};
|
||||
|
||||
this.notify(args);
|
||||
|
||||
return args.value;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user