1
1
/* eslint-disable no-redeclare */
2
- import { CSSType , Utils } from '@nativescript/core' ;
2
+ import { CSSType , Font , Utils } from '@nativescript/core' ;
3
3
import { Canvas , Paint } from './canvas.ios' ;
4
4
import { 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' ;
5
7
6
8
export * from './canvas' ;
7
9
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
+
8
27
@NativeClass
9
28
export class UICustomCanvasView extends UIView {
10
29
mCanvas : Canvas ; // CGContextRef;
@@ -31,6 +50,7 @@ export class UICustomCanvasView extends UIView {
31
50
}
32
51
if ( ! this . mCanvas ) {
33
52
this . mCanvas = new Canvas ( 0 , 0 ) ;
53
+ this . mCanvas . view = this . mOwner ;
34
54
}
35
55
this . mCanvas . setContext ( context , size . width , size . height ) ;
36
56
if ( owner . callDrawBeforeShapes ) {
@@ -96,4 +116,30 @@ export class CanvasView extends CanvasBase {
96
116
this . nativeViewProtected . setNeedsDisplay ( ) ;
97
117
}
98
118
}
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
+ }
99
145
}
0 commit comments