@24i/bigscreen-sdk 1.0.4-alpha.2106 → 1.0.4-alpha.2112

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@24i/bigscreen-sdk",
3
- "version": "1.0.4-alpha.2106",
3
+ "version": "1.0.4-alpha.2112",
4
4
  "description": "SmartApps BIGscreen SDK monorepo",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -40,7 +40,7 @@ If you use it in combination with *JSAnimations* then you will need only static
40
40
 
41
41
  ## JSAnimations
42
42
  Create your own instance in your component. To start the animation you call start and pass callback;
43
- ```javascript
43
+ ```ts
44
44
  animations = new JSAnimations();
45
45
  ...
46
46
  animations.start(from, to, timeInMs, AnimationUtils.ease).onFrame(this.onFrame);
@@ -50,6 +50,17 @@ animations.start(from, to, timeInMs, AnimationUtils.ease).onFrame(this.onFrame);
50
50
  If you start another animation (with the same instance) before the previous ends.
51
51
  Then the from is not what you passed but current position of running animation.
52
52
 
53
+ ## Frame callback
54
+ Frame callback is called each time animation progresses. It has two parameters.
55
+ Parameter `value` is the current value of the animation between `from` and `to`.
56
+ Parameter `percentage` is optional and it is the percentual progress of the animation
57
+ between 0 and 1. The value is not linear, it is based on the ease function used in
58
+ the animation.
59
+
60
+ ```ts
61
+ frameCallback = (value: number, percentage?: number) => void;
62
+ ```
63
+
53
64
  ## Timing Example
54
65
  Time | Call | Result
55
66
  ---|---|---
@@ -63,7 +74,7 @@ To the root of your package add this file:
63
74
  __mocks__/@24i/smartapps-bigscreenen-animations.ts
64
75
  ```
65
76
  with this content
66
- ```js
77
+ ```ts
67
78
  export { AnimationUtils } from '@24i/bigscreen-sdk/animations';
68
79
  export { JSAnimations } from '@24i/bigscreen-sdk/animations/mock';
69
80
 
@@ -162,16 +162,22 @@ export class AnimationUtils {
162
162
  static easeInOutBack: EasingType = [0.68, -0.55, 0.265, 1.55];
163
163
 
164
164
  /**
165
- * Returns value at given percentage
165
+ * Returns value at given time percentage with percentage in easing function
166
166
  * @param {number} min - minimal value
167
167
  * @param {number} max - maximal value
168
168
  * @param {number} percentage - percentage of time
169
169
  * @param {EasingType} easingFunction - easing function for calculation
170
- * @returns {number} calculated value
171
- */
172
- xInTime(min: number, max: number, percentage: number, easingFunction: EasingType): number {
173
- const percentageInTime = this.getPercentageAt(percentage, easingFunction);
174
- return this.linearInterpolation(min, max, percentageInTime);
170
+ * @returns {Object} calculated value and percentual value in easing
171
+ */
172
+ xInTime(min: number, max: number, percentage: number, easingFunction: EasingType): {
173
+ value: number,
174
+ percentage: number,
175
+ } {
176
+ const percentageInEasing = this.getPercentageAt(percentage, easingFunction);
177
+ return {
178
+ value: this.linearInterpolation(min, max, percentageInEasing),
179
+ percentage: percentageInEasing,
180
+ };
175
181
  }
176
182
 
177
183
  /**
@@ -71,10 +71,12 @@ export class JSAnimations {
71
71
  easingFunction: EasingType = AnimationUtils.ease;
72
72
 
73
73
  /**
74
- * @member {FrameCallback} frameCallback - callback being called on evry frame
74
+ * @member {FrameCallback} frameCallback - callback being called on every frame
75
75
  * @private
76
+ * @param {number} value - current value of the animation
77
+ * @param {number} [percentage] - current progress of the animation in percents
76
78
  */
77
- frameCallback?: (value: number) => void;
79
+ frameCallback?: (value: number, percentage?: number) => void;
78
80
 
79
81
  /**
80
82
  * Starts animation
@@ -115,7 +117,7 @@ export class JSAnimations {
115
117
  this.animationRunning = false;
116
118
  }
117
119
  const timePercentage = this.currentTime / this.animationTime;
118
- const value = this.animations.xInTime(
120
+ const { value, percentage } = this.animations.xInTime(
119
121
  this.from,
120
122
  this.to,
121
123
  timePercentage,
@@ -123,7 +125,7 @@ export class JSAnimations {
123
125
  );
124
126
  this.currentPosition = value;
125
127
  if (this.frameCallback) {
126
- this.frameCallback(value);
128
+ this.frameCallback(value, percentage);
127
129
  }
128
130
  if (this.animationRunning) {
129
131
  this.animationFrameID = window.requestAnimationFrame(this.frame);
@@ -134,7 +136,7 @@ export class JSAnimations {
134
136
  * Frame callback handler
135
137
  * @param {FrameCallback} callback - callback to run on every animation frame
136
138
  */
137
- onFrame(callback: (value: number) => void) {
139
+ onFrame(callback: (value: number, percentage?: number) => void) {
138
140
  if (typeof callback === 'function') {
139
141
  this.frameCallback = callback;
140
142
  }
@@ -53,7 +53,7 @@ export class EnvironmentListItem extends Component<Props> implements Item<ItemDa
53
53
  trimRows() {
54
54
  const { leadingEllipses } = this.props;
55
55
  if (leadingEllipses) {
56
- trimWithLeadingEllipsis(this.labelRef.current!);
56
+ trimWithLeadingEllipsis(this.labelRef.current!, 2);
57
57
  }
58
58
  }
59
59
 
@@ -43,7 +43,11 @@
43
43
  padding-right: $environment-config-name-padding-right;
44
44
  line-height: $environment-config-name-height;
45
45
  height: $environment-config-name-height;
46
+ max-width: $environment-config-name-width;
47
+ text-align: left;
46
48
  white-space: nowrap;
49
+ overflow: hidden;
50
+ text-overflow: ellipsis;
47
51
  }
48
52
  }
49
53
 
@@ -9,6 +9,7 @@ $environment-config-name-font-size: 22px;
9
9
  $environment-config-name-padding-left: 12px;
10
10
  $environment-config-name-padding-right: 7px;
11
11
  $environment-config-name-height: 33px;
12
+ $environment-config-name-width: 400px;
12
13
 
13
14
  $environment-list-width: 479px;
14
15
 
@@ -9,6 +9,7 @@ $environment-config-name-font-size: 15px;
9
9
  $environment-config-name-padding-left: 8px;
10
10
  $environment-config-name-padding-right: 5px;
11
11
  $environment-config-name-height: 22px;
12
+ $environment-config-name-width: 200px;
12
13
 
13
14
  $environment-list-width: 319px;
14
15
 
@@ -20,6 +20,7 @@ This package contains a prepared Electronic Program Guide component.
20
20
  - `fetchPrograms` - the function to fetch more programs for a channel in a given time range
21
21
  - `timelineWidthMs` - optional - the width of the timeline (the part where the programs are) in milliseconds (defaults to `90 minutes`)
22
22
  - `scrollStepMs` - optional - the amount of movement step left/right in milliseconds (defaults to `0.5 hours`)
23
+ - `idleTimerMs` - optional - the amount of ms without user input after which epg jumps to the current time (defaults to `scrollStepMs`)
23
24
  - `timelineSectionWidthMs` - optional - the width of timeline header section (above rows) in milliseconds (defaults to `0.5 hours`)
24
25
  - `limitFromMs` - optional - left limit for movement (cannot go more into history) (defaults to `-Infinity`)
25
26
  - `limitToMs` - optional - right limit for movement (cannot go further into future) (defaults to `Infinity`)
@@ -15,6 +15,7 @@ import { TimelineSection } from './TimelineSection';
15
15
  import { EpgMouseNavigation } from './MouseNavigation';
16
16
  import { DataManager } from './DataManager';
17
17
  import { InputEvents } from './InputEvents';
18
+ import { IdleController } from './IdleController';
18
19
  import { shouldRenderDatePicker, clamp } from './utils';
19
20
  import {
20
21
  Props,
@@ -73,7 +74,9 @@ export class Epg<
73
74
 
74
75
  focused: EpgFocus = 'epg';
75
76
 
76
- private readonly inputEvents = new InputEvents(this);
77
+ private readonly idleController: IdleController;
78
+
79
+ private readonly inputEvents: InputEvents;
77
80
 
78
81
  static defaultProps = {
79
82
  timelineWidthMs: DEFAULT_TIMELINE_WIDTH_IN_MIN * MINUTE_IN_MS,
@@ -128,7 +131,7 @@ export class Epg<
128
131
  constructor(props: Props<T, U, V, W>) {
129
132
  super(props);
130
133
  const {
131
- initialTimestamp, timeProvider,
134
+ initialTimestamp, timeProvider, scrollStepMs, idleTimerMs,
132
135
  channelData, timelineWidthMs, fetchPrograms,
133
136
  } = this.props;
134
137
 
@@ -143,6 +146,8 @@ export class Epg<
143
146
  this.dataManagers = map(channelData, (channel) => (
144
147
  new DataManager(channel, timelineWidthMs, fetchPrograms, this)
145
148
  ));
149
+ this.idleController = new IdleController(idleTimerMs ?? scrollStepMs, this.onIdle);
150
+ this.inputEvents = new InputEvents(this, this.idleController.onKeyDown);
146
151
  }
147
152
 
148
153
  componentDidMount() {
@@ -153,6 +158,7 @@ export class Epg<
153
158
 
154
159
  componentWillUnmount() {
155
160
  this.time.destroy();
161
+ this.idleController.clear();
156
162
  }
157
163
 
158
164
  private readonly onDatePickerChange = (timestamp: number) => {
@@ -211,6 +217,13 @@ export class Epg<
211
217
  }
212
218
  };
213
219
 
220
+ private readonly onIdle = () => {
221
+ const now = this.time.getCurrentTime();
222
+ this.setCurrentTime(now);
223
+ this.setFocusTimestamp(now);
224
+ this.setFocusToEpg();
225
+ };
226
+
214
227
  setFocusTimestamp(timestamp: number, allowScroll = true) {
215
228
  const { timelineWidthMs, scrollStepMs, limitFromMs, limitToMs } = this.props;
216
229
  this.focusTimestamp = timestamp;
@@ -363,6 +376,10 @@ export class Epg<
363
376
  return this.inputEvents.isVerticallyFastScrolling();
364
377
  }
365
378
 
379
+ isFocusInRows = () => {
380
+ return this.focused === 'epg';
381
+ };
382
+
366
383
  render() {
367
384
  const {
368
385
  datePickerProps, timelineWidthPx, channelHeaderWidthPx, scrollStepMs, rowHeightPx,
@@ -426,6 +443,7 @@ export class Epg<
426
443
  onMouseEnter={this.onMouseEnter}
427
444
  renderChannelHeader={renderChannelHeader}
428
445
  renderProgram={renderProgram}
446
+ isFocusInRows={this.isFocusInRows}
429
447
  />
430
448
  <EpgMouseNavigation
431
449
  // @ts-ignore - needed to convert fallback (false) to interface
@@ -0,0 +1,25 @@
1
+ import { createTimeout } from '@24i/bigscreen-sdk/utils/timers';
2
+
3
+ export class IdleController {
4
+ private timeout = createTimeout();
5
+
6
+ constructor(
7
+ private intervalMs: number,
8
+ private onIdleCallback: () => void,
9
+ ) {
10
+ this.timeout.set(this.onTimeout, this.intervalMs);
11
+ }
12
+
13
+ onKeyDown = () => {
14
+ this.timeout.set(this.onTimeout, this.intervalMs);
15
+ };
16
+
17
+ onTimeout = () => {
18
+ this.timeout.set(this.onTimeout, this.intervalMs);
19
+ this.onIdleCallback();
20
+ };
21
+
22
+ clear() {
23
+ this.timeout.clear();
24
+ }
25
+ }
@@ -23,6 +23,7 @@ export class InputEvents {
23
23
 
24
24
  constructor(
25
25
  private readonly epg: InternalEpg<any, any, any, any>,
26
+ private readonly onUserInput: () => void,
26
27
  ) {}
27
28
 
28
29
  onKeyDown = (event: KeyboardEvent) => {
@@ -44,6 +45,7 @@ export class InputEvents {
44
45
  this.stopFastHorizontalScrolling();
45
46
  this.stopFastVerticalScrolling();
46
47
  }
48
+ this.onUserInput();
47
49
  };
48
50
 
49
51
  onKeyUp = (event: KeyboardEvent) => {
@@ -188,6 +190,7 @@ export class InputEvents {
188
190
 
189
191
  onWheel = (e: WheelEvent) => {
190
192
  const processed = e.deltaY > 0 ? this.onWheelDown() : this.onWheelUp();
193
+ this.onUserInput();
191
194
  if (processed) {
192
195
  stopEvent(e);
193
196
  this.setVerticalScroll(ARROWS_FACTOR);
@@ -266,21 +269,25 @@ export class InputEvents {
266
269
  }
267
270
 
268
271
  onMouseClickUp = () => {
272
+ this.onUserInput();
269
273
  this.onUp();
270
274
  this.fakeMouseClickStop();
271
275
  };
272
276
 
273
277
  onMouseClickDown = () => {
278
+ this.onUserInput();
274
279
  this.onDown();
275
280
  this.fakeMouseClickStop();
276
281
  };
277
282
 
278
283
  onMouseClickLeft = () => {
284
+ this.onUserInput();
279
285
  this.onLeft();
280
286
  this.fakeMouseClickStop();
281
287
  };
282
288
 
283
289
  onMouseClickRight = () => {
290
+ this.onUserInput();
284
291
  this.onRight();
285
292
  this.fakeMouseClickStop();
286
293
  };
@@ -72,6 +72,7 @@ export class RowsManager<
72
72
  }
73
73
 
74
74
  onFastScrollingEnd() {
75
+ const { isFocusInRows } = this.props;
75
76
  this.isFastScrolling = false;
76
77
  if (this.coiBeforeFastScrolling < this.channelOffsetIndex) {
77
78
  const { navigatableRows } = this.props;
@@ -82,7 +83,7 @@ export class RowsManager<
82
83
  this.updateRowsBackward();
83
84
  }
84
85
  // it is same if we scroll horizontally and at that case we do not need to do anything
85
- this.focusCurrentRowAtTimestamp();
86
+ if (isFocusInRows()) this.focusCurrentRowAtTimestamp();
86
87
  this.setCurrentRowActive();
87
88
  forEach(this.rows, ({ current: row }) => {
88
89
  row!.onFastScrollingEnd();
@@ -212,6 +212,14 @@ type RenderTimeProp<T extends TimelineSection> = {
212
212
  renderTime: TimeRenderer<T>,
213
213
  };
214
214
 
215
+ type IsFocusInRowsProp = {
216
+ /**
217
+ * Returns whether the focus is in Rows part of the epg.
218
+ * @returns true fif cosu is in rows part, false otherwise
219
+ */
220
+ isFocusInRows: () => boolean,
221
+ };
222
+
215
223
  type RowHeightPxProp = {
216
224
  /**
217
225
  * The height of the EPG row in pixels
@@ -233,6 +241,14 @@ type ScrollStepMsProp = {
233
241
  scrollStepMs: number,
234
242
  };
235
243
 
244
+ type IdleTimerMsProp = {
245
+ /**
246
+ * The number of milliseconds of inactivity (no input) after which EPG starts jumps
247
+ * to the current time.
248
+ */
249
+ idleTimerMs: number,
250
+ };
251
+
236
252
  type TimeProp = {
237
253
  /**
238
254
  * The time interface that provides current time and time change events
@@ -806,6 +822,7 @@ export type RowsManagerProps<
806
822
  & OnFocusChangeProp<U>
807
823
  & RenderChannelHeaderProp<T>
808
824
  & RenderProgramProp<U>
825
+ & IsFocusInRowsProp
809
826
  );
810
827
 
811
828
  /**
@@ -1250,6 +1267,7 @@ export type Props<
1250
1267
  & FetchProgramsProp
1251
1268
  & Partial<TimelineWidthMsProp>
1252
1269
  & Partial<ScrollStepMsProp>
1270
+ & Partial<IdleTimerMsProp>
1253
1271
  & Partial<TimelineSectionWidthMsProp>
1254
1272
  & Partial<LimitFromMsProp>
1255
1273
  & Partial<LimitToMsProp>
@@ -1267,7 +1285,6 @@ export type Props<
1267
1285
  & Partial<RenderTimeProp<W>>
1268
1286
  & Partial<DatePickerProp>
1269
1287
  & Partial<PluginsProp<U>>
1270
-
1271
1288
  );
1272
1289
 
1273
1290
  /**
@@ -152,8 +152,7 @@
152
152
  }
153
153
 
154
154
  &.caps-active .key.key-shift .key-background::before {
155
- content: '';
155
+ content: '';
156
156
  position: absolute;
157
- font-size: 0.35em;
158
157
  }
159
158
  }
@@ -1,12 +1,12 @@
1
1
  const ELLIPSIS = '...';
2
2
 
3
- export const trimWithLeadingEllipsis = (row: HTMLSpanElement) => {
3
+ export const trimWithLeadingEllipsis = (row: HTMLSpanElement, requestedNumberOfLines: number) => {
4
4
  if (row && row.textContent != null) {
5
5
  row.style.visibility = 'hidden';
6
6
  const lineHeightString = window.getComputedStyle(row, null).getPropertyValue('line-height');
7
7
  const lineHeight = parseInt(lineHeightString, 10);
8
8
  let numberOfLines = row.offsetHeight / lineHeight;
9
- if (numberOfLines >= 2) {
9
+ if (numberOfLines > requestedNumberOfLines) {
10
10
  const originalTextContent = row.textContent;
11
11
  row.textContent = ELLIPSIS;
12
12
  let stringBuffer = '';
@@ -17,7 +17,7 @@ export const trimWithLeadingEllipsis = (row: HTMLSpanElement) => {
17
17
  row.textContent = `${ELLIPSIS}${stringBuffer}`;
18
18
  currentPosition -= 1;
19
19
  numberOfLines = Math.floor(row.offsetHeight / lineHeight);
20
- } while (numberOfLines < 2 && currentPosition >= 0);
20
+ } while (numberOfLines <= requestedNumberOfLines && currentPosition >= 0);
21
21
  row.textContent = `${ELLIPSIS}${stringBuffer.substring(1)}`;
22
22
  }
23
23
  row.style.visibility = '';