@telefonica/mistica 10.27.0 → 10.28.0

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/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # [10.28.0](https://github.com/Telefonica/mistica-web/compare/v10.27.0...v10.28.0) (2022-03-01)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **popover:** Fix size in iOS when rendered offscreen ([#431](https://github.com/Telefonica/mistica-web/issues/431)) ([9cb3a29](https://github.com/Telefonica/mistica-web/commit/9cb3a290ea2b6c434c715bb7c18bca9678c5a006))
7
+
8
+
9
+ ### Features
10
+
11
+ * **Carousel:** autoplay only move when carousel is visible ([#430](https://github.com/Telefonica/mistica-web/issues/430)) ([fa74b04](https://github.com/Telefonica/mistica-web/commit/fa74b04e1d6171809ea8a5c1522cb0622b9dfc01))
12
+
1
13
  # [10.27.0](https://github.com/Telefonica/mistica-web/compare/v10.26.0...v10.27.0) (2022-02-25)
2
14
 
3
15
 
package/dist/carousel.js CHANGED
@@ -18,6 +18,8 @@ var _themeVariantContext = require("./theme-variant-context");
18
18
  var _color = require("./utils/color");
19
19
  var _image = require("./image");
20
20
  var _dom = require("./utils/dom");
21
+ var _platform = require("./utils/platform");
22
+ var _documentVisibility = require("./utils/document-visibility");
21
23
  function _interopRequireDefault(obj) {
22
24
  return obj && obj.__esModule ? obj : {
23
25
  default: obj
@@ -131,6 +133,11 @@ function _unsupportedIterableToArray(o, minLen) {
131
133
  if (n === "Map" || n === "Set") return Array.from(n);
132
134
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
133
135
  }
136
+ var useShouldAutoplay = function useShouldAutoplay(autoplay, ref) {
137
+ var isDocumentVisible = (0, _documentVisibility).useDocumentVisibility();
138
+ var isInViewport = (0, _hooks).useIsInViewport(ref, false);
139
+ return isInViewport && isDocumentVisible && !!autoplay;
140
+ };
134
141
  var useBulletsStyles = (0, _jss).createUseStyles(function(theme) {
135
142
  return {
136
143
  bullet: _defineProperty({
@@ -268,6 +275,7 @@ var useStyles = (0, _jss).createUseStyles(function(theme) {
268
275
  }
269
276
  })),
270
277
  item: (_obj2 = {
278
+ scrollSnapStop: (0, _platform).isAndroid(theme.platformOverrides) ? 'always' : 'normal',
271
279
  scrollSnapAlign: 'start',
272
280
  flexShrink: 0,
273
281
  width: function width(param) {
@@ -525,8 +533,9 @@ var BaseCarousel = function BaseCarousel(param) {
525
533
  }, [
526
534
  scrollPositions
527
535
  ]);
536
+ var shouldAutoplay = useShouldAutoplay(!!autoplay, carouselRef);
528
537
  React.useEffect(function() {
529
- if (autoplay) {
538
+ if (shouldAutoplay && autoplay) {
530
539
  var time = typeof autoplay === 'boolean' ? DEFAULT_AUTOPLAY_TIME : autoplay.time;
531
540
  var loop = typeof autoplay === 'object' && autoplay.loop;
532
541
  var interval = setInterval(function() {
@@ -547,7 +556,8 @@ var BaseCarousel = function BaseCarousel(param) {
547
556
  }, [
548
557
  autoplay,
549
558
  goNext,
550
- scrollRight1
559
+ scrollRight1,
560
+ shouldAutoplay
551
561
  ]);
552
562
  var currentPageIndex = calcCurrentPageIndex(scrollLeft1, pagesScrollPositions);
553
563
  React.useEffect(function() {
@@ -756,8 +766,9 @@ var Slideshow = function Slideshow(param) {
756
766
  }, [
757
767
  items.length
758
768
  ]);
769
+ var shouldAutoplay = useShouldAutoplay(!!autoplay, carouselRef);
759
770
  React.useEffect(function() {
760
- if (autoplay) {
771
+ if (shouldAutoplay && autoplay) {
761
772
  var time = typeof autoplay === 'boolean' ? DEFAULT_AUTOPLAY_TIME : autoplay.time;
762
773
  var loop = typeof autoplay === 'object' && autoplay.loop;
763
774
  var interval = setInterval(function() {
@@ -778,7 +789,8 @@ var Slideshow = function Slideshow(param) {
778
789
  }, [
779
790
  autoplay,
780
791
  goNext,
781
- scrollRight2
792
+ scrollRight2,
793
+ shouldAutoplay
782
794
  ]);
783
795
  React.useEffect(function() {
784
796
  if (onPageChange) {
package/dist/hooks.d.ts CHANGED
@@ -17,3 +17,10 @@ export declare const useWindowSize: () => {
17
17
  export declare const useWindowHeight: () => number;
18
18
  export declare const useWindowWidth: () => number;
19
19
  export declare const useIsomorphicLayoutEffect: typeof React.useLayoutEffect;
20
+ declare type IntersectionObserverOptions = {
21
+ root?: Element | Document | null;
22
+ rootMargin?: string;
23
+ threshold?: number | number[];
24
+ };
25
+ export declare const useIsInViewport: (ref: React.RefObject<HTMLElement>, defaultValue: boolean, options?: IntersectionObserverOptions | undefined) => boolean;
26
+ export {};
package/dist/hooks.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- exports.useIsomorphicLayoutEffect = exports.useWindowWidth = exports.useWindowHeight = exports.useWindowSize = exports.useAriaId = exports.useElementDimensions = exports.useScreenSize = exports.useDisableBodyScroll = exports.useTheme = void 0;
5
+ exports.useIsInViewport = exports.useIsomorphicLayoutEffect = exports.useWindowWidth = exports.useWindowHeight = exports.useWindowSize = exports.useAriaId = exports.useElementDimensions = exports.useScreenSize = exports.useDisableBodyScroll = exports.useTheme = void 0;
6
6
  var React = _interopRequireWildcard(require("react"));
7
7
  var _themeContext = _interopRequireDefault(require("./theme-context"));
8
8
  var _screenSizeContext = _interopRequireDefault(require("./screen-size-context"));
@@ -217,3 +217,32 @@ var useWindowWidth = function useWindowWidth() {
217
217
  exports.useWindowWidth = useWindowWidth;
218
218
  var useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
219
219
  exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect;
220
+ var useIsInViewport = function useIsInViewport(ref, defaultValue, options) {
221
+ var ref7 = _slicedToArray(React.useState(defaultValue), 2), isInViewport = ref7[0], setIsInViewport = ref7[1];
222
+ React.useEffect(function() {
223
+ if (!ref.current) {
224
+ return;
225
+ }
226
+ if (typeof window.IntersectionObserver === 'undefined') {
227
+ return function() {};
228
+ }
229
+ var observer = new IntersectionObserver(function(entries) {
230
+ setIsInViewport(entries[0].isIntersecting);
231
+ }, {
232
+ root: options === null || options === void 0 ? void 0 : options.root,
233
+ rootMargin: options === null || options === void 0 ? void 0 : options.rootMargin,
234
+ threshold: options === null || options === void 0 ? void 0 : options.threshold
235
+ });
236
+ observer.observe(ref.current);
237
+ return function() {
238
+ observer.disconnect();
239
+ };
240
+ }, [
241
+ ref,
242
+ options === null || options === void 0 ? void 0 : options.root,
243
+ options === null || options === void 0 ? void 0 : options.rootMargin,
244
+ options === null || options === void 0 ? void 0 : options.threshold
245
+ ]);
246
+ return isInViewport;
247
+ };
248
+ exports.useIsInViewport = useIsInViewport;
@@ -19,3 +19,14 @@ declare export var useWindowSize: () => {
19
19
  declare export var useWindowHeight: () => number;
20
20
  declare export var useWindowWidth: () => number;
21
21
  declare export var useIsomorphicLayoutEffect: typeof React.useLayoutEffect;
22
+ declare type IntersectionObserverOptions = {
23
+ root?: Element | Document | null,
24
+ rootMargin?: string,
25
+ threshold?: number | Array<number>,
26
+ };
27
+ declare export var useIsInViewport: (
28
+ ref: React.Ref<HTMLElement>,
29
+ defaultValue: boolean,
30
+ options?: IntersectionObserverOptions | void
31
+ ) => boolean;
32
+ declare export {};
package/dist/index.d.ts CHANGED
@@ -87,8 +87,9 @@ export { default as IconError } from './icons/icon-error';
87
87
  export { default as IconSuccess } from './icons/icon-success';
88
88
  export { default as IconSuccessVivo } from './icons/icon-success-vivo';
89
89
  export { default as Circle } from './circle';
90
- export { useTheme, useScreenSize, useElementDimensions, useAriaId, useWindowSize, useWindowHeight, useWindowWidth, } from './hooks';
90
+ export { useTheme, useScreenSize, useElementDimensions, useAriaId, useWindowSize, useWindowHeight, useWindowWidth, useIsInViewport, } from './hooks';
91
91
  export type { ThemeConfig, ColorScheme } from './theme';
92
+ export { useDocumentVisibility } from './utils/document-visibility';
92
93
  export { ThemeVariant, useIsInverseVariant } from './theme-variant-context';
93
94
  export type { Skin, SkinName } from './skins/types';
94
95
  export { VIVO_SKIN, O2_CLASSIC_SKIN, O2_SKIN, MOVISTAR_SKIN, TELEFONICA_SKIN, BLAU_SKIN, } from './skins/constants';
package/dist/index.js CHANGED
@@ -818,6 +818,18 @@ Object.defineProperty(exports, "useWindowWidth", {
818
818
  return _hooks.useWindowWidth;
819
819
  }
820
820
  });
821
+ Object.defineProperty(exports, "useIsInViewport", {
822
+ enumerable: true,
823
+ get: function() {
824
+ return _hooks.useIsInViewport;
825
+ }
826
+ });
827
+ Object.defineProperty(exports, "useDocumentVisibility", {
828
+ enumerable: true,
829
+ get: function() {
830
+ return _documentVisibility.useDocumentVisibility;
831
+ }
832
+ });
821
833
  Object.defineProperty(exports, "ThemeVariant", {
822
834
  enumerable: true,
823
835
  get: function() {
@@ -8366,6 +8378,7 @@ var _iconSuccess = _interopRequireDefault(require("./icons/icon-success"));
8366
8378
  var _iconSuccessVivo = _interopRequireDefault(require("./icons/icon-success-vivo"));
8367
8379
  var _circle = _interopRequireDefault(require("./circle"));
8368
8380
  var _hooks = require("./hooks");
8381
+ var _documentVisibility = require("./utils/document-visibility");
8369
8382
  var _themeVariantContext = require("./theme-variant-context");
8370
8383
  var _constants = require("./skins/constants");
8371
8384
  var _utils = require("./skins/utils");
@@ -143,8 +143,10 @@ declare export {
143
143
  useWindowSize,
144
144
  useWindowHeight,
145
145
  useWindowWidth,
146
+ useIsInViewport,
146
147
  } from "./hooks";
147
148
  export type { ThemeConfig, ColorScheme } from "./theme";
149
+ declare export { useDocumentVisibility } from "./utils/document-visibility";
148
150
  declare export {
149
151
  ThemeVariant,
150
152
  useIsInverseVariant,
@@ -3,5 +3,5 @@ Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
5
  exports.PACKAGE_VERSION = void 0;
6
- var PACKAGE_VERSION = '10.27.0';
6
+ var PACKAGE_VERSION = '10.28.0';
7
7
  exports.PACKAGE_VERSION = PACKAGE_VERSION;
package/dist/popover.js CHANGED
@@ -204,8 +204,9 @@ var getPosition = function getPosition() {
204
204
  var position = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : defaultPositionDesktop, isTabletOrSmaller = arguments.length > 1 ? arguments[1] : void 0;
205
205
  return isTabletOrSmaller && (position === 'left' || position === 'right') ? defaultPositionMobile : position;
206
206
  };
207
- var getWidth = function getWidth(isTabletOrSmaller, width) {
208
- return isTabletOrSmaller ? window.innerWidth - marginLeftRightMobile * 2 : getWidthDesktop(width);
207
+ var getWidth = function getWidth(isTabletOrSmaller, isIos, width) {
208
+ // in iOS, when the webview is rendered offscreen (eg. acccount tab), window.innerWidth value is wrong, it returns strange values like 0 or 80.
209
+ return isTabletOrSmaller ? (isIos ? window.screen.width : window.innerWidth) - marginLeftRightMobile * 2 : getWidthDesktop(width);
209
210
  };
210
211
  var getPositionStyles = function getPositionStyles(position, width, targetPosition, isTabletOrSmaller) {
211
212
  var containerStylesByPos = {
@@ -278,12 +279,12 @@ var getTargetPosition = function getTargetPosition(targetWrapper) {
278
279
  };
279
280
  var Popover = function Popover(param) {
280
281
  var description = param.description, title = param.title, onClose = param.onClose, trackingEvent = param.trackingEvent, position = param.position, width = param.width, target = param.target, asset = param.asset, _isVisible = param.isVisible, isVisible = _isVisible === void 0 ? true : _isVisible;
281
- var ref = (0, _hooks).useTheme(), texts = ref.texts, colors = ref.colors;
282
+ var ref = (0, _hooks).useTheme(), texts = ref.texts, colors = ref.colors, isIos = ref.isIos;
282
283
  var isTabletOrSmaller = (0, _hooks).useScreenSize().isTabletOrSmaller;
283
284
  var ref1 = _slicedToArray(React.useState(null), 2), targetPosition = ref1[0], setTargetPosition = ref1[1];
284
285
  var targetWrapperRef = React.useRef(null);
285
286
  position = getPosition(position, isTabletOrSmaller);
286
- var innerWidth = getWidth(isTabletOrSmaller, width);
287
+ var innerWidth = getWidth(isTabletOrSmaller, isIos, width);
287
288
  var classes = useStyles({
288
289
  position: position
289
290
  });
@@ -21,6 +21,7 @@ var _hooks = require("./hooks");
21
21
  var _tabFocus = _interopRequireDefault(require("./tab-focus"));
22
22
  var _portal = require("./portal");
23
23
  var _modalContextProvider = _interopRequireDefault(require("./modal-context-provider"));
24
+ var _documentVisibility = require("./utils/document-visibility");
24
25
  function _interopRequireDefault(obj) {
25
26
  return obj && obj.__esModule ? obj : {
26
27
  default: obj
@@ -229,11 +230,13 @@ var ThemeContextProvider = function ThemeContextProvider(param) {
229
230
  children: /*#__PURE__*/ (0, _jsxRuntime).jsx(_modalContextProvider.default, {
230
231
  children: /*#__PURE__*/ (0, _jsxRuntime).jsx(_themeContext.default.Provider, {
231
232
  value: contextTheme,
232
- children: /*#__PURE__*/ (0, _jsxRuntime).jsx(_ariaIdGetterContext.default.Provider, {
233
- value: getAriaId,
234
- children: /*#__PURE__*/ (0, _jsxRuntime).jsx(_screenSizeContextProvider.default, {
235
- children: /*#__PURE__*/ (0, _jsxRuntime).jsx(_dialog.default, {
236
- children: children
233
+ children: /*#__PURE__*/ (0, _jsxRuntime).jsx(_documentVisibility.DocumentVisibilityProvider, {
234
+ children: /*#__PURE__*/ (0, _jsxRuntime).jsx(_ariaIdGetterContext.default.Provider, {
235
+ value: getAriaId,
236
+ children: /*#__PURE__*/ (0, _jsxRuntime).jsx(_screenSizeContextProvider.default, {
237
+ children: /*#__PURE__*/ (0, _jsxRuntime).jsx(_dialog.default, {
238
+ children: children
239
+ })
237
240
  })
238
241
  })
239
242
  })
@@ -0,0 +1,8 @@
1
+ import * as React from 'react';
2
+ declare type Props = {
3
+ hidden?: boolean;
4
+ children: React.ReactNode;
5
+ };
6
+ export declare const DocumentVisibilityProvider: React.FC<Props>;
7
+ export declare const useDocumentVisibility: () => boolean;
8
+ export {};
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ exports.useDocumentVisibility = exports.DocumentVisibilityProvider = void 0;
6
+ var _jsxRuntime = require("react/jsx-runtime");
7
+ var React = _interopRequireWildcard(require("react"));
8
+ var _hooks = require("../hooks");
9
+ var _platform = require("./platform");
10
+ function _interopRequireWildcard(obj) {
11
+ if (obj && obj.__esModule) {
12
+ return obj;
13
+ } else {
14
+ var newObj = {};
15
+ if (obj != null) {
16
+ for(var key in obj){
17
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
18
+ var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
19
+ if (desc.get || desc.set) {
20
+ Object.defineProperty(newObj, key, desc);
21
+ } else {
22
+ newObj[key] = obj[key];
23
+ }
24
+ }
25
+ }
26
+ }
27
+ newObj.default = obj;
28
+ return newObj;
29
+ }
30
+ }
31
+ function _arrayLikeToArray(arr, len) {
32
+ if (len == null || len > arr.length) len = arr.length;
33
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
34
+ return arr2;
35
+ }
36
+ function _arrayWithHoles(arr) {
37
+ if (Array.isArray(arr)) return arr;
38
+ }
39
+ function _iterableToArrayLimit(arr, i) {
40
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
41
+ if (_i == null) return;
42
+ var _arr = [];
43
+ var _n = true;
44
+ var _d = false;
45
+ var _s, _e;
46
+ try {
47
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
48
+ _arr.push(_s.value);
49
+ if (i && _arr.length === i) break;
50
+ }
51
+ } catch (err) {
52
+ _d = true;
53
+ _e = err;
54
+ } finally{
55
+ try {
56
+ if (!_n && _i["return"] != null) _i["return"]();
57
+ } finally{
58
+ if (_d) throw _e;
59
+ }
60
+ }
61
+ return _arr;
62
+ }
63
+ function _nonIterableRest() {
64
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
65
+ }
66
+ function _slicedToArray(arr, i) {
67
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
68
+ }
69
+ function _unsupportedIterableToArray(o, minLen) {
70
+ if (!o) return;
71
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
72
+ var n = Object.prototype.toString.call(o).slice(8, -1);
73
+ if (n === "Object" && o.constructor) n = o.constructor.name;
74
+ if (n === "Map" || n === "Set") return Array.from(n);
75
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
76
+ }
77
+ var isDocumentVisible = function isDocumentVisible() {
78
+ return typeof document !== 'undefined' && document.visibilityState === 'visible';
79
+ };
80
+ var DocumentVisibilityContext = /*#__PURE__*/ React.createContext(true);
81
+ var DocumentVisibilityProvider = function DocumentVisibilityProvider(param) {
82
+ var hidden = param.hidden, children = param.children;
83
+ var platformOverrides = (0, _hooks).useTheme().platformOverrides;
84
+ var ref = _slicedToArray(React.useState(!hidden), 2), visible = ref[0], setVisible = ref[1];
85
+ React.useEffect(function() {
86
+ var visibilitychangeCallback = function visibilitychangeCallback() {
87
+ setVisible(isDocumentVisible());
88
+ };
89
+ var focusCallback = function focusCallback() {
90
+ setVisible(true);
91
+ };
92
+ var blurCallback = function blurCallback() {
93
+ setVisible(false);
94
+ };
95
+ setVisible(isDocumentVisible());
96
+ document.addEventListener('visibilitychange', visibilitychangeCallback);
97
+ document.addEventListener('focus', focusCallback);
98
+ document.addEventListener('blur', blurCallback);
99
+ return function() {
100
+ document.removeEventListener('visibilitychange', visibilitychangeCallback);
101
+ document.removeEventListener('focus', focusCallback);
102
+ document.removeEventListener('blur', blurCallback);
103
+ };
104
+ }, []);
105
+ // Workaround for this bug: https://jira.tuenti.io/jira/browse/ACCOUNT-10938
106
+ // In Android, after ~10 minutes of inactivity, when a background webview receives focus (back navigation from another webview),
107
+ // visibility change event is not fired, this causes problems like the navigation bar not being updated
108
+ var isVisibleNow = isDocumentVisible();
109
+ if ((0, _platform).isAndroid(platformOverrides) && isVisibleNow !== visible) {
110
+ setVisible(isVisibleNow);
111
+ }
112
+ return(/*#__PURE__*/ (0, _jsxRuntime).jsx(DocumentVisibilityContext.Provider, {
113
+ value: visible,
114
+ children: children
115
+ }));
116
+ };
117
+ exports.DocumentVisibilityProvider = DocumentVisibilityProvider;
118
+ var useDocumentVisibility = function useDocumentVisibility() {
119
+ return React.useContext(DocumentVisibilityContext);
120
+ };
121
+ exports.useDocumentVisibility = useDocumentVisibility;
@@ -0,0 +1,10 @@
1
+ // @flow
2
+
3
+ import * as React from "react";
4
+ declare type Props = {
5
+ hidden?: boolean,
6
+ children: React.Node,
7
+ };
8
+ declare export var DocumentVisibilityProvider: React.ComponentType<Props>;
9
+ declare export var useDocumentVisibility: () => boolean;
10
+ declare export {};
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import * as React from 'react';
3
3
  import IconChevronLeftRegular from './generated/mistica-icons/icon-chevron-left-regular';
4
4
  import IconChevronRightRegular from './generated/mistica-icons/icon-chevron-right-regular';
5
- import { useScreenSize, useTheme } from './hooks';
5
+ import { useIsInViewport, useScreenSize, useTheme } from './hooks';
6
6
  import Inline from './inline';
7
7
  import { createUseStyles } from './jss';
8
8
  import Stack from './stack';
@@ -13,6 +13,8 @@ import { useIsInverseVariant, ThemeVariant } from './theme-variant-context';
13
13
  import { applyAlpha } from './utils/color';
14
14
  import { DisableBorderRadiusProvider } from './image';
15
15
  import { getPrefixedDataAttributes, listenResize } from './utils/dom';
16
+ import { isAndroid } from './utils/platform';
17
+ import { useDocumentVisibility } from './utils/document-visibility';
16
18
  function _arrayLikeToArray(arr, len) {
17
19
  if (len == null || len > arr.length) len = arr.length;
18
20
  for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
@@ -99,6 +101,11 @@ function _unsupportedIterableToArray(o, minLen) {
99
101
  if (n === "Map" || n === "Set") return Array.from(n);
100
102
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
101
103
  }
104
+ var useShouldAutoplay = function(autoplay, ref) {
105
+ var isDocumentVisible = useDocumentVisibility();
106
+ var isInViewport = useIsInViewport(ref, false);
107
+ return isInViewport && isDocumentVisible && !!autoplay;
108
+ };
102
109
  var useBulletsStyles = createUseStyles(function(theme) {
103
110
  return {
104
111
  bullet: _defineProperty({
@@ -235,6 +242,7 @@ var useStyles = createUseStyles(function(theme) {
235
242
  }
236
243
  })),
237
244
  item: (_obj2 = {
245
+ scrollSnapStop: isAndroid(theme.platformOverrides) ? 'always' : 'normal',
238
246
  scrollSnapAlign: 'start',
239
247
  flexShrink: 0,
240
248
  width: function(param) {
@@ -492,8 +500,9 @@ var BaseCarousel = function(param) {
492
500
  }, [
493
501
  scrollPositions
494
502
  ]);
503
+ var shouldAutoplay = useShouldAutoplay(!!autoplay, carouselRef);
495
504
  React.useEffect(function() {
496
- if (autoplay) {
505
+ if (shouldAutoplay && autoplay) {
497
506
  var time = typeof autoplay === 'boolean' ? DEFAULT_AUTOPLAY_TIME : autoplay.time;
498
507
  var loop = typeof autoplay === 'object' && autoplay.loop;
499
508
  var interval = setInterval(function() {
@@ -514,7 +523,8 @@ var BaseCarousel = function(param) {
514
523
  }, [
515
524
  autoplay,
516
525
  goNext,
517
- scrollRight1
526
+ scrollRight1,
527
+ shouldAutoplay
518
528
  ]);
519
529
  var currentPageIndex = calcCurrentPageIndex(scrollLeft1, pagesScrollPositions);
520
530
  React.useEffect(function() {
@@ -721,8 +731,9 @@ export var Slideshow = function(param) {
721
731
  }, [
722
732
  items.length
723
733
  ]);
734
+ var shouldAutoplay = useShouldAutoplay(!!autoplay, carouselRef);
724
735
  React.useEffect(function() {
725
- if (autoplay) {
736
+ if (shouldAutoplay && autoplay) {
726
737
  var time = typeof autoplay === 'boolean' ? DEFAULT_AUTOPLAY_TIME : autoplay.time;
727
738
  var loop = typeof autoplay === 'object' && autoplay.loop;
728
739
  var interval = setInterval(function() {
@@ -743,7 +754,8 @@ export var Slideshow = function(param) {
743
754
  }, [
744
755
  autoplay,
745
756
  goNext,
746
- scrollRight2
757
+ scrollRight2,
758
+ shouldAutoplay
747
759
  ]);
748
760
  React.useEffect(function() {
749
761
  if (onPageChange) {
package/dist-es/hooks.js CHANGED
@@ -180,3 +180,31 @@ export var useWindowWidth = function() {
180
180
  // To get around it, we can conditionally useEffect on the server (no-op) and
181
181
  // useLayoutEffect in the browser
182
182
  export var useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
183
+ export var useIsInViewport = function(ref, defaultValue, options) {
184
+ var ref7 = _slicedToArray(React.useState(defaultValue), 2), isInViewport = ref7[0], setIsInViewport = ref7[1];
185
+ React.useEffect(function() {
186
+ if (!ref.current) {
187
+ return;
188
+ }
189
+ if (typeof window.IntersectionObserver === 'undefined') {
190
+ return function() {};
191
+ }
192
+ var observer = new IntersectionObserver(function(entries) {
193
+ setIsInViewport(entries[0].isIntersecting);
194
+ }, {
195
+ root: options === null || options === void 0 ? void 0 : options.root,
196
+ rootMargin: options === null || options === void 0 ? void 0 : options.rootMargin,
197
+ threshold: options === null || options === void 0 ? void 0 : options.threshold
198
+ });
199
+ observer.observe(ref.current);
200
+ return function() {
201
+ observer.disconnect();
202
+ };
203
+ }, [
204
+ ref,
205
+ options === null || options === void 0 ? void 0 : options.root,
206
+ options === null || options === void 0 ? void 0 : options.rootMargin,
207
+ options === null || options === void 0 ? void 0 : options.threshold
208
+ ]);
209
+ return isInViewport;
210
+ };
package/dist-es/index.js CHANGED
@@ -91,7 +91,8 @@ export { default as IconError } from './icons/icon-error';
91
91
  export { default as IconSuccess } from './icons/icon-success';
92
92
  export { default as IconSuccessVivo } from './icons/icon-success-vivo';
93
93
  export { default as Circle } from './circle';
94
- export { useTheme, useScreenSize, useElementDimensions, useAriaId, useWindowSize, useWindowHeight, useWindowWidth } from './hooks';
94
+ export { useTheme, useScreenSize, useElementDimensions, useAriaId, useWindowSize, useWindowHeight, useWindowWidth, useIsInViewport } from './hooks';
95
+ export { useDocumentVisibility } from './utils/document-visibility';
95
96
  export { ThemeVariant, useIsInverseVariant } from './theme-variant-context';
96
97
  export { VIVO_SKIN, O2_CLASSIC_SKIN, O2_SKIN, MOVISTAR_SKIN, TELEFONICA_SKIN, BLAU_SKIN } from './skins/constants';
97
98
  export { getSkinByName } from './skins/utils';
@@ -1,2 +1,2 @@
1
1
  // DO NOT EDIT THIS FILE. It's autogenerated by set-version.js
2
- export var PACKAGE_VERSION = '10.27.0';
2
+ export var PACKAGE_VERSION = '10.28.0';
@@ -172,8 +172,9 @@ var getPosition = function() {
172
172
  var position = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : defaultPositionDesktop, isTabletOrSmaller = arguments.length > 1 ? arguments[1] : void 0;
173
173
  return isTabletOrSmaller && (position === 'left' || position === 'right') ? defaultPositionMobile : position;
174
174
  };
175
- var getWidth = function(isTabletOrSmaller, width) {
176
- return isTabletOrSmaller ? window.innerWidth - marginLeftRightMobile * 2 : getWidthDesktop(width);
175
+ var getWidth = function(isTabletOrSmaller, isIos, width) {
176
+ // in iOS, when the webview is rendered offscreen (eg. acccount tab), window.innerWidth value is wrong, it returns strange values like 0 or 80.
177
+ return isTabletOrSmaller ? (isIos ? window.screen.width : window.innerWidth) - marginLeftRightMobile * 2 : getWidthDesktop(width);
177
178
  };
178
179
  var getPositionStyles = function(position, width, targetPosition, isTabletOrSmaller) {
179
180
  var containerStylesByPos = {
@@ -246,12 +247,12 @@ var getTargetPosition = function(targetWrapper) {
246
247
  };
247
248
  var Popover = function(param) {
248
249
  var description = param.description, title = param.title, onClose = param.onClose, trackingEvent = param.trackingEvent, position = param.position, width = param.width, target = param.target, asset = param.asset, _isVisible = param.isVisible, isVisible = _isVisible === void 0 ? true : _isVisible;
249
- var ref = useTheme(), texts = ref.texts, colors = ref.colors;
250
+ var ref = useTheme(), texts = ref.texts, colors = ref.colors, isIos = ref.isIos;
250
251
  var isTabletOrSmaller = useScreenSize().isTabletOrSmaller;
251
252
  var ref1 = _slicedToArray(React.useState(null), 2), targetPosition = ref1[0], setTargetPosition = ref1[1];
252
253
  var targetWrapperRef = React.useRef(null);
253
254
  position = getPosition(position, isTabletOrSmaller);
254
- var innerWidth = getWidth(isTabletOrSmaller, width);
255
+ var innerWidth = getWidth(isTabletOrSmaller, isIos, width);
255
256
  var classes = useStyles({
256
257
  position: position
257
258
  });
@@ -16,6 +16,7 @@ import { useIsomorphicLayoutEffect } from './hooks';
16
16
  import TabFocus from './tab-focus';
17
17
  import { PortalNodesProvider } from './portal';
18
18
  import ModalContextProvider from './modal-context-provider';
19
+ import { DocumentVisibilityProvider } from './utils/document-visibility';
19
20
  function _arrayLikeToArray(arr, len) {
20
21
  if (len == null || len > arr.length) len = arr.length;
21
22
  for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
@@ -196,11 +197,13 @@ var ThemeContextProvider = function(param) {
196
197
  children: /*#__PURE__*/ _jsx(ModalContextProvider, {
197
198
  children: /*#__PURE__*/ _jsx(ThemeContext.Provider, {
198
199
  value: contextTheme,
199
- children: /*#__PURE__*/ _jsx(AriaIdGetterContext.Provider, {
200
- value: getAriaId,
201
- children: /*#__PURE__*/ _jsx(ScreenSizeContextProvider, {
202
- children: /*#__PURE__*/ _jsx(DialogRoot, {
203
- children: children
200
+ children: /*#__PURE__*/ _jsx(DocumentVisibilityProvider, {
201
+ children: /*#__PURE__*/ _jsx(AriaIdGetterContext.Provider, {
202
+ value: getAriaId,
203
+ children: /*#__PURE__*/ _jsx(ScreenSizeContextProvider, {
204
+ children: /*#__PURE__*/ _jsx(DialogRoot, {
205
+ children: children
206
+ })
204
207
  })
205
208
  })
206
209
  })
@@ -0,0 +1,93 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import * as React from 'react';
3
+ import { useTheme } from '../hooks';
4
+ import { isAndroid } from './platform';
5
+ function _arrayLikeToArray(arr, len) {
6
+ if (len == null || len > arr.length) len = arr.length;
7
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
8
+ return arr2;
9
+ }
10
+ function _arrayWithHoles(arr) {
11
+ if (Array.isArray(arr)) return arr;
12
+ }
13
+ function _iterableToArrayLimit(arr, i) {
14
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
15
+ if (_i == null) return;
16
+ var _arr = [];
17
+ var _n = true;
18
+ var _d = false;
19
+ var _s, _e;
20
+ try {
21
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
22
+ _arr.push(_s.value);
23
+ if (i && _arr.length === i) break;
24
+ }
25
+ } catch (err) {
26
+ _d = true;
27
+ _e = err;
28
+ } finally{
29
+ try {
30
+ if (!_n && _i["return"] != null) _i["return"]();
31
+ } finally{
32
+ if (_d) throw _e;
33
+ }
34
+ }
35
+ return _arr;
36
+ }
37
+ function _nonIterableRest() {
38
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
39
+ }
40
+ function _slicedToArray(arr, i) {
41
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
42
+ }
43
+ function _unsupportedIterableToArray(o, minLen) {
44
+ if (!o) return;
45
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
46
+ var n = Object.prototype.toString.call(o).slice(8, -1);
47
+ if (n === "Object" && o.constructor) n = o.constructor.name;
48
+ if (n === "Map" || n === "Set") return Array.from(n);
49
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
50
+ }
51
+ var isDocumentVisible = function() {
52
+ return typeof document !== 'undefined' && document.visibilityState === 'visible';
53
+ };
54
+ var DocumentVisibilityContext = /*#__PURE__*/ React.createContext(true);
55
+ export var DocumentVisibilityProvider = function(param) {
56
+ var hidden = param.hidden, children = param.children;
57
+ var platformOverrides = useTheme().platformOverrides;
58
+ var ref = _slicedToArray(React.useState(!hidden), 2), visible = ref[0], setVisible = ref[1];
59
+ React.useEffect(function() {
60
+ var visibilitychangeCallback = function() {
61
+ setVisible(isDocumentVisible());
62
+ };
63
+ var focusCallback = function() {
64
+ setVisible(true);
65
+ };
66
+ var blurCallback = function() {
67
+ setVisible(false);
68
+ };
69
+ setVisible(isDocumentVisible());
70
+ document.addEventListener('visibilitychange', visibilitychangeCallback);
71
+ document.addEventListener('focus', focusCallback);
72
+ document.addEventListener('blur', blurCallback);
73
+ return function() {
74
+ document.removeEventListener('visibilitychange', visibilitychangeCallback);
75
+ document.removeEventListener('focus', focusCallback);
76
+ document.removeEventListener('blur', blurCallback);
77
+ };
78
+ }, []);
79
+ // Workaround for this bug: https://jira.tuenti.io/jira/browse/ACCOUNT-10938
80
+ // In Android, after ~10 minutes of inactivity, when a background webview receives focus (back navigation from another webview),
81
+ // visibility change event is not fired, this causes problems like the navigation bar not being updated
82
+ var isVisibleNow = isDocumentVisible();
83
+ if (isAndroid(platformOverrides) && isVisibleNow !== visible) {
84
+ setVisible(isVisibleNow);
85
+ }
86
+ return(/*#__PURE__*/ _jsx(DocumentVisibilityContext.Provider, {
87
+ value: visible,
88
+ children: children
89
+ }));
90
+ };
91
+ export var useDocumentVisibility = function() {
92
+ return React.useContext(DocumentVisibilityContext);
93
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telefonica/mistica",
3
- "version": "10.27.0",
3
+ "version": "10.28.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -21,6 +21,7 @@
21
21
  "lint": "eslint --report-unused-disable-directives .",
22
22
  "ts-check": "tsc --project tsconfig.json --noEmit",
23
23
  "build": "yarn clean && node scripts/build.js",
24
+ "compile": "node scripts/compile.js",
24
25
  "clean": "rimraf dist && rimraf dist-es && rimraf dist-ts && rimraf node_modules/.cache",
25
26
  "ci": "yarn lint && yarn prettier-check && yarn ts-check && yarn circular-dependencies && yarn build && yarn storybook-static && yarn test --ci && yarn test-acceptance --ci",
26
27
  "prepublishOnly": "node scripts/prepublish-only.js",
@@ -108,6 +109,7 @@
108
109
  "node-fetch": "^2.6.1",
109
110
  "playroom": "^0.27.9",
110
111
  "prettier": "^2.5.1",
112
+ "pretty-bytes": "^5.6.0",
111
113
  "prop-types": "^15.7.2",
112
114
  "react": "17.0.2",
113
115
  "react-dom": "17.0.2",