@micromag/screen-keypad 0.4.56 → 0.4.58

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.
Files changed (2) hide show
  1. package/es/index.js +31 -18
  2. package/package.json +2 -2
package/es/index.js CHANGED
@@ -6,7 +6,7 @@ import { animated } from '@react-spring/web';
6
6
  import classNames from 'classnames';
7
7
  import isEmpty from 'lodash/isEmpty';
8
8
  import isString from 'lodash/isString';
9
- import { useRef, useState, useMemo, useCallback, useEffect } from 'react';
9
+ import { useRef, useState, useMemo, useEffect, useCallback } from 'react';
10
10
  import { Close, ScreenElement } from '@micromag/core/components';
11
11
  import { usePlaybackContext, usePlaybackMediaRef, useScreenState, useScreenSize, useViewerContext, useViewerWebView, useViewerInteraction, useScreenRenderContext } from '@micromag/core/contexts';
12
12
  import { useTrackScreenEvent, useDimensionObserver, useDragProgress } from '@micromag/core/hooks';
@@ -189,7 +189,6 @@ function KeypadScreen(_ref) {
189
189
  _useState6 = _slicedToArray(_useState5, 2),
190
190
  popup = _useState6[0],
191
191
  setPopup = _useState6[1];
192
- var prevShowPopupRef = useRef(showPopup);
193
192
  var _ref7 = popup || {},
194
193
  _ref7$heading = _ref7.heading,
195
194
  popupHeading = _ref7$heading === void 0 ? null : _ref7$heading,
@@ -227,6 +226,18 @@ function KeypadScreen(_ref) {
227
226
  popupInWebView = _ref10$inWebView === void 0 ? false : _ref10$inWebView,
228
227
  _ref10$boxStyle = _ref10.boxStyle,
229
228
  popupButtonBoxStyle = _ref10$boxStyle === void 0 ? null : _ref10$boxStyle;
229
+
230
+ // Skips a render loop when opening a popup
231
+ var _useState7 = useState(false),
232
+ _useState8 = _slicedToArray(_useState7, 2),
233
+ showNextPopup = _useState8[0],
234
+ setShowNextPopup = _useState8[1];
235
+ useEffect(function () {
236
+ if (showNextPopup) {
237
+ setShowNextPopup(false);
238
+ setShowPopup(true);
239
+ }
240
+ }, [showNextPopup, setShowPopup, setShowNextPopup]);
230
241
  var onItemClick = useCallback(function (e, item, index) {
231
242
  e.stopPropagation();
232
243
  if (isNotInteractive) {
@@ -247,7 +258,7 @@ function KeypadScreen(_ref) {
247
258
  });
248
259
  } else {
249
260
  setPopup(item);
250
- setShowPopup(true);
261
+ setShowNextPopup(true);
251
262
  }
252
263
  var _ref12 = heading || {},
253
264
  _ref12$body = _ref12.body,
@@ -285,10 +296,10 @@ function KeypadScreen(_ref) {
285
296
  e.stopPropagation();
286
297
  }
287
298
  }, []);
288
- var _useState7 = useState(null),
289
- _useState8 = _slicedToArray(_useState7, 2),
290
- popupDragDirection = _useState8[0],
291
- setPopupDragDirection = _useState8[1];
299
+ var _useState9 = useState(null),
300
+ _useState0 = _slicedToArray(_useState9, 2),
301
+ popupDragDirection = _useState0[0],
302
+ setPopupDragDirection = _useState0[1];
292
303
  var onPopupScrollHeightChange = useCallback(function (_ref13) {
293
304
  var _ref13$scrolleeHeight = _ref13.scrolleeHeight,
294
305
  scrolleeHeight = _ref13$scrolleeHeight === void 0 ? 0 : _ref13$scrolleeHeight;
@@ -383,15 +394,6 @@ function KeypadScreen(_ref) {
383
394
  bindPopupDrag = _useDragProgress.bind,
384
395
  popupSpring = _useDragProgress.progress,
385
396
  popupTransitioning = _useDragProgress.transitioning;
386
-
387
- // Clear popup contents after close transition completes
388
- useEffect(function () {
389
- if (prevShowPopupRef.current && !showPopup && !popupTransitioning) {
390
- console.log('clear popup');
391
- setPopup(null);
392
- }
393
- prevShowPopupRef.current = showPopup;
394
- }, [showPopup, popupTransitioning]);
395
397
  useEffect(function () {
396
398
  var keyup = function keyup(e) {
397
399
  if (e.key === 'Escape') {
@@ -495,6 +497,17 @@ function KeypadScreen(_ref) {
495
497
  setShowPopup(false);
496
498
  }
497
499
  }, [screenState, items, isView]);
500
+
501
+ // Clear popup contents after close transition completes
502
+ useEffect(function () {
503
+ if (isView && screenState === null && !showPopup && !popupTransitioning) {
504
+ // console.log('clear popup');
505
+ setPopup(null);
506
+ }
507
+ }, [isView, screenState, showPopup, popupTransitioning]);
508
+
509
+ // console.log('render keypad', { screenState, popup, showPopup, popupTransitioning });
510
+
498
511
  return /*#__PURE__*/jsxs("div", {
499
512
  ref: containerRef,
500
513
  className: classNames([styles.container, className, _defineProperty(_defineProperty({}, styles.isPlaceholder, isPlaceholder), styles.withSquareItems, withSquareItems)]),
@@ -594,7 +607,7 @@ function KeypadScreen(_ref) {
594
607
  spacing: isPlaceholder ? 2 : columnSpacing,
595
608
  items: gridItems
596
609
  })]
597
- }), popup !== null ? /*#__PURE__*/jsxs(Fragment, {
610
+ }), /*#__PURE__*/jsxs(Fragment, {
598
611
  children: [/*#__PURE__*/jsx(animated.div, {
599
612
  className: classNames([styles.popupBackdrop]),
600
613
  style: {
@@ -704,7 +717,7 @@ function KeypadScreen(_ref) {
704
717
  })
705
718
  })
706
719
  }))]
707
- }) : null]
720
+ }) ]
708
721
  }), !isPlaceholder && hasFooter ? /*#__PURE__*/jsx("div", {
709
722
  ref: footerRef,
710
723
  className: styles.footer,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micromag/screen-keypad",
3
- "version": "0.4.56",
3
+ "version": "0.4.58",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [
@@ -94,6 +94,6 @@
94
94
  "access": "public",
95
95
  "registry": "https://registry.npmjs.org/"
96
96
  },
97
- "gitHead": "8d1c7dca724abbc01da7cebbe6913c77ee27f0b7",
97
+ "gitHead": "b521da8b8c3efd5c099079ca3bd6e679b97155cf",
98
98
  "types": "es/index.d.ts"
99
99
  }