11/* eslint-disable no-redeclare */
2- import { CSSType , Utils } from '@nativescript/core' ;
2+ import { CSSType , Font , Utils } from '@nativescript/core' ;
33import { Canvas , Paint } from './canvas.ios' ;
44import { CanvasBase } from './index.common' ;
5+ import { iosAccessibilityAdjustsFontSizeProperty , iosAccessibilityMaxFontScaleProperty , iosAccessibilityMinFontScaleProperty } from '@nativescript/core/accessibility/accessibility-properties' ;
6+ import { fontScaleInternalProperty } from '@nativescript/core/ui/styling/style-properties' ;
57
68export * from './canvas' ;
79
10+ export function adjustMinMaxFontScale ( value , view ) {
11+ let finalValue ;
12+ if ( view . iosAccessibilityAdjustsFontSize ) {
13+ finalValue = value ;
14+
15+ if ( view . iosAccessibilityMinFontScale && view . iosAccessibilityMinFontScale > value ) {
16+ finalValue = view . iosAccessibilityMinFontScale ;
17+ }
18+ if ( view . iosAccessibilityMaxFontScale && view . iosAccessibilityMaxFontScale < value ) {
19+ finalValue = view . iosAccessibilityMaxFontScale ;
20+ }
21+ } else {
22+ finalValue = 1.0 ;
23+ }
24+ return finalValue ;
25+ }
26+
827@NativeClass
928export class UICustomCanvasView extends UIView {
1029 mCanvas : Canvas ; // CGContextRef;
@@ -31,6 +50,7 @@ export class UICustomCanvasView extends UIView {
3150 }
3251 if ( ! this . mCanvas ) {
3352 this . mCanvas = new Canvas ( 0 , 0 ) ;
53+ this . mCanvas . view = this . mOwner ;
3454 }
3555 this . mCanvas . setContext ( context , size . width , size . height ) ;
3656 if ( owner . callDrawBeforeShapes ) {
@@ -96,4 +116,30 @@ export class CanvasView extends CanvasBase {
96116 this . nativeViewProtected . setNeedsDisplay ( ) ;
97117 }
98118 }
119+
120+ [ fontScaleInternalProperty . setNative ] ( value ) {
121+ const font = this . style . fontInternal || Font . default . withFontSize ( 16 ) ;
122+ const finalValue = adjustMinMaxFontScale ( value , this ) ;
123+
124+ // Request layout on font scale as it's not done automatically
125+ if ( font . fontScale !== finalValue ) {
126+ this . style . fontInternal = font . withFontScale ( finalValue ) ;
127+ this . requestLayout ( ) ;
128+ } else {
129+ if ( ! this . style . fontInternal ) {
130+ this . style . fontInternal = font ;
131+ }
132+ }
133+ }
134+ [ iosAccessibilityAdjustsFontSizeProperty . setNative ] ( value : boolean ) {
135+ this [ fontScaleInternalProperty . setNative ] ( this . style . fontScaleInternal ) ;
136+ }
137+
138+ [ iosAccessibilityMinFontScaleProperty . setNative ] ( value : number ) {
139+ this [ fontScaleInternalProperty . setNative ] ( this . style . fontScaleInternal ) ;
140+ }
141+
142+ [ iosAccessibilityMaxFontScaleProperty . setNative ] ( value : number ) {
143+ this [ fontScaleInternalProperty . setNative ] ( this . style . fontScaleInternal ) ;
144+ }
99145}
0 commit comments