@@ -13,6 +13,7 @@ import { MeasureMode } from './components/text/MeasureMode';
13
13
import { TextMeasurement } from './components/text/Text' ;
14
14
import { IVideoFactory } from './components/video/IVideoFactory' ;
15
15
import { VideoFactory } from './components/video/VideoFactory' ;
16
+ import { Content } from './Content' ;
16
17
import { AnimationQuality } from './enums/AnimationQuality' ;
17
18
import { DisplayState } from './enums/DisplayState' ;
18
19
import { FocusDirection } from './enums/FocusDirection' ;
@@ -67,6 +68,15 @@ export interface IViewportCharacteristics {
67
68
shape ?: ViewportShape ;
68
69
/** Dots per inch */
69
70
dpi : number ;
71
+ /** Providing the min & max will turn on auto-sizing feature */
72
+ /** The minimum width of the viewport, in pixels */
73
+ minWidth ?: number ;
74
+ /** The maximum width of the viewport, in pixels */
75
+ maxWidth ?: number ;
76
+ /** The minimum height of the viewport, in pixels */
77
+ minHeight ?: number ;
78
+ /** The maximum height of the viewport, in pixels */
79
+ maxHeight ?: number ;
70
80
}
71
81
72
82
export interface IEnvironmentBase {
@@ -110,8 +120,20 @@ export interface IConfigurationChangeOptions extends IEnvironmentBase {
110
120
width ?: number ;
111
121
/** Viewport Height in pixels */
112
122
height ?: number ;
123
+ /** Providing the min & max will turn on auto-sizing feature. Must provide all of the 6 values:
124
+ * minWidth, maxWidth, minHeight, maxHeight, width, height
125
+ */
126
+ /** The minimum width of the viewport, in pixels */
127
+ minWidth ?: number ;
128
+ /** The maximum width of the viewport, in pixels */
129
+ maxWidth ?: number ;
130
+ /** The minimum height of the viewport, in pixels */
131
+ minHeight ?: number ;
132
+ /** The maximum height of the viewport, in pixels */
133
+ maxHeight ?: number ;
113
134
/** APL theme. Usually 'light' or 'dark' */
114
135
docTheme ?: string ;
136
+ theme ?: string ;
115
137
/** Device mode. If no provided "HUB" is used. */
116
138
mode ?: DeviceMode ;
117
139
/** Relative size of fonts to display as specified by the OS accessibility settings */
@@ -250,6 +272,12 @@ export interface IAPLOptions {
250
272
*/
251
273
onOpenUrl ?: ( source : string ) => Promise < boolean > ;
252
274
275
+ /**
276
+ * Callback for view size update during auto-resizing. width and height in pixels
277
+ * Runtime should return quickly as this method blocks the rendering path
278
+ */
279
+ onViewportSizeUpdate ?: ( pixelWidth : number , pixelHeight : number ) => void ;
280
+
253
281
/**
254
282
* Contains developer tool options
255
283
*/
@@ -315,6 +343,8 @@ export default abstract class APLRenderer<Options = any> {
315
343
*/
316
344
protected abstract getAudioPlayerFactory ( ) : IAudioPlayerFactory ;
317
345
346
+ public content : Content ;
347
+
318
348
/** A reference to the APL root context */
319
349
public context : APL . Context ;
320
350
@@ -403,6 +433,24 @@ export default abstract class APLRenderer<Options = any> {
403
433
*/
404
434
private isEdge : boolean = browserIsEdge ( window . navigator . userAgent ) ;
405
435
436
+ /**
437
+ * @internal
438
+ * @ignore
439
+ */
440
+ private lastKnownViewWidth : number = 0 ;
441
+
442
+ /**
443
+ * @internal
444
+ * @ignore
445
+ */
446
+ private lastKnownViewHeight : number = 0 ;
447
+
448
+ /**
449
+ * @internal
450
+ * @ignore
451
+ */
452
+ protected isAutoSizing : boolean = false ;
453
+
406
454
public get options ( ) : Options {
407
455
return this . mOptions as any as Options ;
408
456
}
@@ -423,7 +471,9 @@ export default abstract class APLRenderer<Options = any> {
423
471
}
424
472
425
473
this . view = mOptions . view ;
426
- this . setViewSize ( mOptions . viewport . width , mOptions . viewport . height ) ;
474
+ this . lastKnownViewWidth = mOptions . viewport . width ;
475
+ this . lastKnownViewHeight = mOptions . viewport . height ;
476
+ this . setViewSize ( this . lastKnownViewWidth , this . lastKnownViewHeight ) ;
427
477
if ( mOptions . viewport . shape === 'ROUND' ) {
428
478
this . view . style . clipPath = 'circle(50%)' ;
429
479
} else {
@@ -507,6 +557,9 @@ export default abstract class APLRenderer<Options = any> {
507
557
if ( mOptions . onResizingIgnored ) {
508
558
this . onResizingIgnored = mOptions . onResizingIgnored ;
509
559
}
560
+ if ( mOptions . onViewportSizeUpdate ) {
561
+ this . onViewportSizeUpdate = mOptions . onViewportSizeUpdate ;
562
+ }
510
563
511
564
this . maxTimeDeltaBetweenFrames = ( 1000 * this . TOLERANCE / this . MAXFPS ) ;
512
565
}
@@ -533,6 +586,10 @@ export default abstract class APLRenderer<Options = any> {
533
586
this . requestId = requestAnimationFrame ( this . update ) ;
534
587
}
535
588
589
+ public async loadPackages ( ) : Promise < boolean > {
590
+ return true ;
591
+ }
592
+
536
593
/**
537
594
* Sets the renderer view size in pixels
538
595
* @param width width in pixels
@@ -560,10 +617,23 @@ export default abstract class APLRenderer<Options = any> {
560
617
* @param configurationChangeOptions The configuration change options to provide to core.
561
618
*/
562
619
public onConfigurationChange ( configurationChangeOptions : IConfigurationChangeOptions ) : void {
563
- if ( ! this . supportsResizing && ( configurationChangeOptions . width || configurationChangeOptions . height ) ) {
620
+ if ( configurationChangeOptions . minWidth && configurationChangeOptions . maxWidth &&
621
+ configurationChangeOptions . maxHeight && configurationChangeOptions . minHeight &&
622
+ configurationChangeOptions . minWidth > configurationChangeOptions . maxWidth &&
623
+ configurationChangeOptions . minHeight > configurationChangeOptions . maxHeight ) {
624
+ throw new Error ( `Invalid Configuration Change Options. minWidth > maxWidth and minHeight > maxHeight` ) ;
625
+ }
626
+
627
+ if ( configurationChangeOptions . minWidth && configurationChangeOptions . maxWidth &&
628
+ configurationChangeOptions . maxHeight && configurationChangeOptions . minHeight &&
629
+ configurationChangeOptions . minWidth < configurationChangeOptions . maxWidth &&
630
+ configurationChangeOptions . minHeight < configurationChangeOptions . maxHeight ) {
631
+ this . isAutoSizing = true ;
632
+ }
633
+
634
+ if ( ! this . supportsResizing && ! this . isAutoSizing &&
635
+ ( configurationChangeOptions . width || configurationChangeOptions . height ) ) {
564
636
this . onResizingIgnored ( configurationChangeOptions . width , configurationChangeOptions . height ) ;
565
- configurationChangeOptions . width = undefined ;
566
- configurationChangeOptions . height = undefined ;
567
637
}
568
638
this . configurationChangeThrottle ( configurationChangeOptions ) ;
569
639
}
@@ -723,6 +793,11 @@ export default abstract class APLRenderer<Options = any> {
723
793
this . logger . warn ( `onResizeIgnored: width: ${ ignoredWidth } , height: ${ ignoredHeight } ` ) ;
724
794
}
725
795
796
+ public onViewportSizeUpdate ( width : number , height : number ) : void {
797
+ this . logger . warn ( `resize function not provided. Using default size: ${ width } x ${ height } ` ) ;
798
+ this . setViewSize ( width , height ) ;
799
+ }
800
+
726
801
/**
727
802
* Called by core when a text measure is required
728
803
* @param component The component to measure
@@ -734,7 +809,13 @@ export default abstract class APLRenderer<Options = any> {
734
809
*/
735
810
public onMeasure ( component : APL . Component , measureWidth : number , widthMode : MeasureMode ,
736
811
measureHeight : number , heightMode : MeasureMode ) {
737
- const { width, height} = this . mOptions . viewport ;
812
+ let { width, height} = this . mOptions . viewport ;
813
+ if ( this . mOptions . viewport . maxWidth ) {
814
+ width = this . mOptions . viewport . maxWidth ;
815
+ }
816
+ if ( this . mOptions . viewport . maxHeight ) {
817
+ height = this . mOptions . viewport . maxHeight ;
818
+ }
738
819
const comp = new TextMeasurement ( component , width , height ) ;
739
820
comp . init ( ) ;
740
821
return comp . onMeasure ( measureWidth , widthMode , measureHeight , heightMode ) ;
@@ -986,8 +1067,13 @@ export default abstract class APLRenderer<Options = any> {
986
1067
commandFactory ( event , this ) ;
987
1068
}
988
1069
1070
+ if ( this . content && ! this . content . isReady ( ) ) {
1071
+ return ;
1072
+ }
1073
+
989
1074
if ( this . context ) {
990
1075
if ( this . context . isDirty ( ) ) {
1076
+ this . checkAndUpdateViewportSize ( ) ;
991
1077
const dirtyComponents = this . context . getDirty ( ) ;
992
1078
for ( const dirtyId of dirtyComponents ) {
993
1079
const component = this . componentMap [ dirtyId ] ;
@@ -1222,6 +1308,8 @@ export default abstract class APLRenderer<Options = any> {
1222
1308
// already rendered
1223
1309
return ;
1224
1310
}
1311
+
1312
+ this . checkAndUpdateViewportSize ( ) ;
1225
1313
const top = this . context . topComponent ( ) ;
1226
1314
this . top = componentFactory ( this , top ) as Component ;
1227
1315
this . view . appendChild ( this . top . container ) ;
@@ -1306,4 +1394,20 @@ export default abstract class APLRenderer<Options = any> {
1306
1394
}
1307
1395
}
1308
1396
}
1397
+
1398
+ /**
1399
+ * @internal
1400
+ * @ignore
1401
+ */
1402
+ private checkAndUpdateViewportSize ( ) : void {
1403
+ const newSize = this . context . getViewportPixelSize ( ) ;
1404
+
1405
+ if ( this . lastKnownViewWidth !== newSize [ 'width' ] ||
1406
+ this . lastKnownViewHeight !== newSize [ 'height' ] ) {
1407
+ this . logger . info ( 'Viewport size updated by APL Core: ' + JSON . stringify ( newSize ) ) ;
1408
+ this . lastKnownViewWidth = newSize [ 'width' ] ;
1409
+ this . lastKnownViewHeight = newSize [ 'height' ] ;
1410
+ this . onViewportSizeUpdate ( this . lastKnownViewWidth , this . lastKnownViewHeight ) ;
1411
+ }
1412
+ }
1309
1413
}
0 commit comments