rc-trigger
Advanced tools
Comparing version 5.0.0 to 5.0.1
@@ -95,4 +95,13 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2"; | ||
var motion = getMotion(props); | ||
var motion = _objectSpread({}, getMotion(props)); | ||
['onAppearEnd', 'onEnterEnd', 'onLeaveEnd'].forEach(function (eventName) { | ||
var originHandler = motion[eventName]; | ||
motion[eventName] = function (element, event) { | ||
goNextStatus(); | ||
return originHandler === null || originHandler === void 0 ? void 0 : originHandler(element, event); | ||
}; | ||
}); | ||
function onShowPrepare() { | ||
@@ -102,5 +111,11 @@ return new Promise(function (resolve) { | ||
}); | ||
} // ========================= Refs ========================= | ||
} // Go to stable directly when motion not provided | ||
React.useEffect(function () { | ||
if (!motion.motionName && status === 'motion') { | ||
goNextStatus(); | ||
} | ||
}, [motion.motionName, status]); // ========================= Refs ========================= | ||
React.useImperativeHandle(ref, function () { | ||
@@ -115,9 +130,7 @@ return { | ||
var interactiveReady = status === 'stable' || !visible; | ||
var mergedStyle = _objectSpread(_objectSpread(_objectSpread({}, stretchStyle), {}, { | ||
zIndex: zIndex | ||
}, style), {}, { | ||
opacity: interactiveReady ? undefined : 0, | ||
pointerEvents: interactiveReady ? undefined : 'none' | ||
opacity: status === 'motion' || status === 'stable' ? undefined : 0, | ||
pointerEvents: status === 'stable' ? undefined : 'none' | ||
}); // Align status | ||
@@ -124,0 +137,0 @@ |
@@ -13,3 +13,3 @@ /** | ||
declare type Func = () => void; | ||
declare const _default: (visible: boolean, doMeasure: Func) => [PopupStatus, (callback: () => void) => void]; | ||
declare const _default: (visible: boolean, doMeasure: Func) => [PopupStatus, (callback?: () => void) => void]; | ||
export default _default; |
@@ -6,3 +6,3 @@ import _regeneratorRuntime from "@babel/runtime/regenerator"; | ||
import raf from "rc-util/es/raf"; | ||
var StatusQueue = ['measure', 'align', null, 'motion', 'stable']; | ||
var StatusQueue = ['measure', 'align', null, 'motion']; | ||
export default (function (visible, doMeasure) { | ||
@@ -21,16 +21,18 @@ var _useState = useState(null), | ||
function goNextStatus(callback) { | ||
// Only align should be manually trigger | ||
setStatus(function (prev) { | ||
switch (status) { | ||
case 'align': | ||
return 'motion'; | ||
} | ||
cancelRaf(); | ||
rafRef.current = raf(function () { | ||
// Only align should be manually trigger | ||
setStatus(function (prev) { | ||
switch (status) { | ||
case 'align': | ||
return 'motion'; | ||
return prev; | ||
}); // Trigger callback in another frame | ||
case 'motion': | ||
return 'stable'; | ||
} | ||
if (callback) { | ||
cancelRaf(); | ||
rafRef.current = raf(callback); | ||
} | ||
return prev; | ||
}); | ||
callback === null || callback === void 0 ? void 0 : callback(); | ||
}); | ||
} // Init status | ||
@@ -52,3 +54,3 @@ | ||
rafRef.current = raf( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() { | ||
var nextStatus; | ||
var index, nextStatus; | ||
return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
@@ -58,9 +60,10 @@ while (1) { | ||
case 0: | ||
nextStatus = StatusQueue[StatusQueue.indexOf(status) + 1]; | ||
index = StatusQueue.indexOf(status); | ||
nextStatus = StatusQueue[index + 1]; | ||
if (nextStatus) { | ||
if (nextStatus && index !== -1) { | ||
setStatus(nextStatus); | ||
} | ||
case 2: | ||
case 3: | ||
case "end": | ||
@@ -67,0 +70,0 @@ return _context.stop(); |
@@ -114,4 +114,12 @@ "use strict"; | ||
var motion = (0, _legacyUtil.getMotion)(props); | ||
var motion = (0, _objectSpread2.default)({}, (0, _legacyUtil.getMotion)(props)); | ||
['onAppearEnd', 'onEnterEnd', 'onLeaveEnd'].forEach(function (eventName) { | ||
var originHandler = motion[eventName]; | ||
motion[eventName] = function (element, event) { | ||
goNextStatus(); | ||
return originHandler === null || originHandler === void 0 ? void 0 : originHandler(element, event); | ||
}; | ||
}); | ||
function onShowPrepare() { | ||
@@ -121,5 +129,11 @@ return new Promise(function (resolve) { | ||
}); | ||
} // ========================= Refs ========================= | ||
} // Go to stable directly when motion not provided | ||
React.useEffect(function () { | ||
if (!motion.motionName && status === 'motion') { | ||
goNextStatus(); | ||
} | ||
}, [motion.motionName, status]); // ========================= Refs ========================= | ||
React.useImperativeHandle(ref, function () { | ||
@@ -134,8 +148,7 @@ return { | ||
var interactiveReady = status === 'stable' || !visible; | ||
var mergedStyle = (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, stretchStyle), {}, { | ||
zIndex: zIndex | ||
}, style), {}, { | ||
opacity: interactiveReady ? undefined : 0, | ||
pointerEvents: interactiveReady ? undefined : 'none' | ||
opacity: status === 'motion' || status === 'stable' ? undefined : 0, | ||
pointerEvents: status === 'stable' ? undefined : 'none' | ||
}); // Align status | ||
@@ -142,0 +155,0 @@ |
@@ -13,3 +13,3 @@ /** | ||
declare type Func = () => void; | ||
declare const _default: (visible: boolean, doMeasure: Func) => [PopupStatus, (callback: () => void) => void]; | ||
declare const _default: (visible: boolean, doMeasure: Func) => [PopupStatus, (callback?: () => void) => void]; | ||
export default _default; |
@@ -20,3 +20,3 @@ "use strict"; | ||
var StatusQueue = ['measure', 'align', null, 'motion', 'stable']; | ||
var StatusQueue = ['measure', 'align', null, 'motion']; | ||
@@ -36,16 +36,18 @@ var _default = function _default(visible, doMeasure) { | ||
function goNextStatus(callback) { | ||
// Only align should be manually trigger | ||
setStatus(function (prev) { | ||
switch (status) { | ||
case 'align': | ||
return 'motion'; | ||
} | ||
cancelRaf(); | ||
rafRef.current = (0, _raf.default)(function () { | ||
// Only align should be manually trigger | ||
setStatus(function (prev) { | ||
switch (status) { | ||
case 'align': | ||
return 'motion'; | ||
return prev; | ||
}); // Trigger callback in another frame | ||
case 'motion': | ||
return 'stable'; | ||
} | ||
if (callback) { | ||
cancelRaf(); | ||
rafRef.current = (0, _raf.default)(callback); | ||
} | ||
return prev; | ||
}); | ||
callback === null || callback === void 0 ? void 0 : callback(); | ||
}); | ||
} // Init status | ||
@@ -67,3 +69,3 @@ | ||
rafRef.current = (0, _raf.default)( /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() { | ||
var nextStatus; | ||
var index, nextStatus; | ||
return _regenerator.default.wrap(function _callee$(_context) { | ||
@@ -73,9 +75,10 @@ while (1) { | ||
case 0: | ||
nextStatus = StatusQueue[StatusQueue.indexOf(status) + 1]; | ||
index = StatusQueue.indexOf(status); | ||
nextStatus = StatusQueue[index + 1]; | ||
if (nextStatus) { | ||
if (nextStatus && index !== -1) { | ||
setStatus(nextStatus); | ||
} | ||
case 2: | ||
case 3: | ||
case "end": | ||
@@ -82,0 +85,0 @@ return _context.stop(); |
{ | ||
"name": "rc-trigger", | ||
"version": "5.0.0", | ||
"version": "5.0.1", | ||
"description": "base abstract trigger component for react", | ||
@@ -5,0 +5,0 @@ "engines": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
112577
2466