mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
feat(ios): new a11y properties for managing font scale (#10260)
This commit is contained in:
committed by
GitHub
parent
2f9e5c0b84
commit
7aaa1d899d
@@ -0,0 +1,70 @@
|
||||
import * as TKUnit from '../tk-unit';
|
||||
import * as helper from '../ui-helper';
|
||||
import { isIOS, Label, StackLayout } from '@nativescript/core';
|
||||
|
||||
export function test_iosAccessibilityAdjustsFontSize_property() {
|
||||
if (isIOS) {
|
||||
const deviceFontScaleMock = 4.0;
|
||||
|
||||
const page = helper.getCurrentPage();
|
||||
const testView = new Label();
|
||||
const layout = new StackLayout();
|
||||
layout.addChild(testView);
|
||||
|
||||
page.content = layout;
|
||||
|
||||
layout.style.iosAccessibilityAdjustsFontSize = false;
|
||||
layout.style.fontScaleInternal = deviceFontScaleMock;
|
||||
|
||||
const nativeFontSize = testView.nativeTextViewProtected.font.pointSize;
|
||||
layout.style.iosAccessibilityAdjustsFontSize = true;
|
||||
const nativeFontSizeWithAdjust = testView.nativeTextViewProtected.font.pointSize;
|
||||
|
||||
TKUnit.assertEqual(nativeFontSize, testView.style.fontInternal.fontSize, 'View font size was scaled even though iosAccessibilityAdjustsFontSize is disabled');
|
||||
TKUnit.assertEqual(nativeFontSizeWithAdjust, testView.style.fontInternal.fontSize * deviceFontScaleMock, 'View font size was not scaled even though iosAccessibilityAdjustsFontSize is enabled');
|
||||
}
|
||||
}
|
||||
|
||||
export function test_iosAccessibilityMinFontScale_property() {
|
||||
if (isIOS) {
|
||||
const deviceFontScaleMock = 1.0;
|
||||
|
||||
const page = helper.getCurrentPage();
|
||||
const testView = new Label();
|
||||
const layout = new StackLayout();
|
||||
layout.addChild(testView);
|
||||
|
||||
page.content = layout;
|
||||
|
||||
layout.style.iosAccessibilityAdjustsFontSize = true;
|
||||
layout.style.fontScaleInternal = deviceFontScaleMock;
|
||||
|
||||
testView.style.iosAccessibilityMinFontScale = 2.0;
|
||||
|
||||
const nativeFontSize = testView.nativeTextViewProtected.font.pointSize;
|
||||
const expectedNativeFontSize = testView.style.fontInternal.fontSize * testView.style.iosAccessibilityMinFontScale;
|
||||
TKUnit.assertEqual(nativeFontSize, expectedNativeFontSize, 'View font size scaling does not respect iosAccessibilityMinFontScale');
|
||||
}
|
||||
}
|
||||
|
||||
export function test_iosAccessibilityMaxFontScale_property() {
|
||||
if (isIOS) {
|
||||
const deviceFontScaleMock = 4.0;
|
||||
|
||||
const page = helper.getCurrentPage();
|
||||
const testView = new Label();
|
||||
const layout = new StackLayout();
|
||||
layout.addChild(testView);
|
||||
|
||||
page.content = layout;
|
||||
|
||||
layout.style.iosAccessibilityAdjustsFontSize = true;
|
||||
layout.style.fontScaleInternal = deviceFontScaleMock;
|
||||
|
||||
testView.style.iosAccessibilityMaxFontScale = 2.0;
|
||||
|
||||
const nativeFontSize = testView.nativeTextViewProtected.font.pointSize;
|
||||
const expectedNativeFontSize = testView.style.fontInternal.fontSize * testView.style.iosAccessibilityMaxFontScale;
|
||||
TKUnit.assertEqual(nativeFontSize, expectedNativeFontSize, 'View font size scaling does not respect iosAccessibilityMaxFontScale');
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,9 @@ if (!__CI__) {
|
||||
allTests['PROFILING'] = profilingTests;
|
||||
}
|
||||
|
||||
import * as a11yPropertiesTests from './accessibility/accessibility-properties-tests';
|
||||
allTests['A11Y-PROPERTIES'] = a11yPropertiesTests;
|
||||
|
||||
import * as appSettingsTests from './application-settings/application-settings-tests';
|
||||
allTests['APPLICATION-SETTINGS'] = appSettingsTests;
|
||||
|
||||
|
||||
@@ -582,13 +582,17 @@ export function test_setting_font_properties_sets_native_font() {
|
||||
|
||||
export function test_native_font_size_with_a11y_font_scale() {
|
||||
if (isIOS) {
|
||||
const page = helper.getCurrentPage();
|
||||
const testView = new Label();
|
||||
const deviceFontScaleMock = 4.0;
|
||||
|
||||
page.content = testView;
|
||||
const page = helper.getCurrentPage();
|
||||
const testView = new Label();
|
||||
const layout = new StackLayout();
|
||||
layout.addChild(testView);
|
||||
|
||||
testView.style._fontScale = deviceFontScaleMock;
|
||||
page.content = layout;
|
||||
|
||||
layout.style.iosAccessibilityAdjustsFontSize = true;
|
||||
layout.style.fontScaleInternal = deviceFontScaleMock;
|
||||
|
||||
const nativeFontSize = testView.nativeTextViewProtected.font.pointSize;
|
||||
const expectedNativeFontSize = testView.style.fontInternal.fontSize * deviceFontScaleMock;
|
||||
|
||||
Reference in New Issue
Block a user