@micromag/screen-keypad 0.4.57 → 0.4.59

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 +25 -24
  2. package/package.json +2 -2
package/es/index.js CHANGED
@@ -135,9 +135,9 @@ function KeypadScreen(_ref) {
135
135
  _useDimensionObserver4 = _useDimensionObserver3.height,
136
136
  footerHeight = _useDimensionObserver4 === void 0 ? 0 : _useDimensionObserver4;
137
137
  var _useState = useState(false),
138
- _useState2 = _slicedToArray(_useState, 2),
139
- popupDragDisabled = _useState2[0],
140
- setPopupDragDisabled = _useState2[1];
138
+ _useState2 = _slicedToArray(_useState, 2);
139
+ _useState2[0];
140
+ var setPopupDragDisabled = _useState2[1];
141
141
  var backgroundPlaying = current && (isView || isEdit) && (isCurrentMedia || !isView);
142
142
  var mediaShouldLoad = !isPlaceholder && (current || preload);
143
143
  var isInteractivePreview = isEdit && screenState === null;
@@ -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,
@@ -311,19 +310,22 @@ function KeypadScreen(_ref) {
311
310
  }
312
311
  }, [height]);
313
312
  var computePopupProgress = useCallback(function (_ref14) {
314
- var dragActive = _ref14.active,
313
+ var _ref14$active = _ref14.active,
314
+ dragActive = _ref14$active === void 0 ? false : _ref14$active,
315
315
  _ref14$movement = _slicedToArray(_ref14.movement, 2),
316
- my = _ref14$movement[1],
316
+ _ref14$movement$ = _ref14$movement[1],
317
+ my = _ref14$movement$ === void 0 ? null : _ref14$movement$,
317
318
  _ref14$velocity = _slicedToArray(_ref14.velocity, 2),
318
- vy = _ref14$velocity[1];
319
+ _ref14$velocity$ = _ref14$velocity[1],
320
+ vy = _ref14$velocity$ === void 0 ? null : _ref14$velocity$;
319
321
  var damper = 0.5;
320
322
  var windowHeight = typeof window !== 'undefined' ? window.innerHeight : 0;
321
- var delta = windowHeight > 0 ? Math.abs(my) / windowHeight : 0;
322
- var reachedThreshold = vy > 1 || delta > 0.3;
323
+ var delta = windowHeight > 0 && my !== null ? Math.abs(my) / windowHeight : 0;
324
+ var reachedThreshold = vy !== null ? vy > 1 || delta > 0.3 : false;
323
325
  var progress = 0;
324
- if (popupDragDirection === 'top' && my < 0) {
326
+ if (popupDragDirection === 'top' && my !== null && my < 0) {
325
327
  progress = delta * damper * -1;
326
- } else if (popupDragDirection === 'bottom' && my > 0) {
328
+ } else if (popupDragDirection === 'bottom' && my !== null && my > 0) {
327
329
  progress = delta * damper;
328
330
  }
329
331
  if (!dragActive) {
@@ -341,7 +343,7 @@ function KeypadScreen(_ref) {
341
343
  } else {
342
344
  enableInteraction();
343
345
  }
344
- }, [showPopup]);
346
+ }, [showPopup, enableInteraction, disableInteraction]);
345
347
  useEffect(function () {
346
348
  function handleClickOutside(e) {
347
349
  if (!current && isView || popupInnerRef.current && !popupInnerRef.current.contains(e.target) && containerRef.current && containerRef.current.contains(e.target) && !isInteractivePreview && !isEdit && showPopup) {
@@ -375,7 +377,8 @@ function KeypadScreen(_ref) {
375
377
  }, [onCloseModal, showPopup]);
376
378
  var onResolve = useCallback(function () {}, []);
377
379
  var _useDragProgress = useDragProgress({
378
- disabled: !isView || popupDragDisabled,
380
+ disabled: true,
381
+ // !isView || popupDragDisabled, // TODO: remove drag/popupDragDisabled if we're cool with it
379
382
  progress: showPopup ? 0 : 1,
380
383
  computeProgress: computePopupProgress,
381
384
  onResolve: onResolve,
@@ -395,15 +398,6 @@ function KeypadScreen(_ref) {
395
398
  bindPopupDrag = _useDragProgress.bind,
396
399
  popupSpring = _useDragProgress.progress,
397
400
  popupTransitioning = _useDragProgress.transitioning;
398
-
399
- // Clear popup contents after close transition completes
400
- useEffect(function () {
401
- if (prevShowPopupRef.current && !showPopup && !popupTransitioning) {
402
- console.log('clear popup');
403
- setPopup(null);
404
- }
405
- prevShowPopupRef.current = showPopup;
406
- }, [showPopup, popupTransitioning]);
407
401
  useEffect(function () {
408
402
  var keyup = function keyup(e) {
409
403
  if (e.key === 'Escape') {
@@ -489,7 +483,7 @@ function KeypadScreen(_ref) {
489
483
  }, [items, screenState, buttonBoxStyle, buttonTextStyle, buttonLayout, isNotInteractive]);
490
484
  useEffect(function () {
491
485
  if (screenState === 'popup' && isPlaceholder) {
492
- setPopup(placeholderPopupBoxStyles); // @note force placeholder
486
+ setPopup(placeholderPopupBoxStyles);
493
487
  setShowPopup(true);
494
488
  }
495
489
  if (screenState === 'keypad') {
@@ -507,6 +501,13 @@ function KeypadScreen(_ref) {
507
501
  setShowPopup(false);
508
502
  }
509
503
  }, [screenState, items, isView]);
504
+
505
+ // Clear popup contents after close transition completes
506
+ useEffect(function () {
507
+ if (isView && screenState === null && !showPopup && !popupTransitioning) {
508
+ setPopup(null);
509
+ }
510
+ }, [isView, screenState, showPopup, popupTransitioning]);
510
511
  return /*#__PURE__*/jsxs("div", {
511
512
  ref: containerRef,
512
513
  className: classNames([styles.container, className, _defineProperty(_defineProperty({}, styles.isPlaceholder, isPlaceholder), styles.withSquareItems, withSquareItems)]),
@@ -716,7 +717,7 @@ function KeypadScreen(_ref) {
716
717
  })
717
718
  })
718
719
  }))]
719
- }) ]
720
+ })]
720
721
  }), !isPlaceholder && hasFooter ? /*#__PURE__*/jsx("div", {
721
722
  ref: footerRef,
722
723
  className: styles.footer,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micromag/screen-keypad",
3
- "version": "0.4.57",
3
+ "version": "0.4.59",
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": "fbe8859ecf20634ed5591afb432ff4869eb37352",
97
+ "gitHead": "e4dfd331721492c90cb0f38b3a60e91237ca990f",
98
98
  "types": "es/index.d.ts"
99
99
  }