@arpitbhalla/rneui-base-dev
Version:
Cross Platform React Native UI Toolkit
99 lines (98 loc) • 5.52 kB
JavaScript
;
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SpeedDial = void 0;
var react_1 = __importDefault(require("react"));
var react_native_1 = require("react-native");
var FAB_1 = require("../FAB");
var color_1 = __importDefault(require("color"));
var helpers_1 = require("../helpers");
var SpeedDial = function (_a) {
var _b;
var _c;
var _d = _a.isOpen, isOpen = _d === void 0 ? false : _d, _e = _a.onOpen, onOpen = _e === void 0 ? function () { } : _e, _f = _a.onClose, onClose = _f === void 0 ? function () { } : _f, icon = _a.icon, openIcon = _a.openIcon, children = _a.children, _g = _a.transitionDuration, transitionDuration = _g === void 0 ? 150 : _g, style = _a.style, overlayColor = _a.overlayColor, _h = _a.theme, theme = _h === void 0 ? helpers_1.defaultTheme : _h, placement = _a.placement, labelPressable = _a.labelPressable, pressableProps = _a.backdropPressableProps, rest = __rest(_a, ["isOpen", "onOpen", "onClose", "icon", "openIcon", "children", "transitionDuration", "style", "overlayColor", "theme", "placement", "labelPressable", "backdropPressableProps"]);
var animations = react_1.default.useRef(__spreadArray([], new Array(react_1.default.Children.count(children)), true).map(function () { return new react_native_1.Animated.Value(Number(isOpen)); }));
react_1.default.useEffect(function () {
react_native_1.Animated.stagger(50, animations.current
.map(function (animation) {
return react_native_1.Animated.timing(animation, {
toValue: Number(isOpen),
duration: transitionDuration,
useNativeDriver: true,
});
})[isOpen ? 'reverse' : 'sort']()).start();
}, [isOpen, animations, children, transitionDuration]);
return (react_1.default.createElement(react_native_1.View, { style: [styles.container, style], pointerEvents: "box-none" },
react_1.default.createElement(react_native_1.Pressable, __assign({}, pressableProps, { onPress: onClose, style: [react_native_1.StyleSheet.absoluteFillObject], pointerEvents: isOpen ? 'auto' : 'none' }),
react_1.default.createElement(react_native_1.Animated.View, { style: [
react_native_1.StyleSheet.absoluteFillObject,
{
opacity: animations.current[0],
backgroundColor: overlayColor ||
(0, color_1.default)((_c = theme === null || theme === void 0 ? void 0 : theme.colors) === null || _c === void 0 ? void 0 : _c.black).alpha(0.6).rgb().toString(),
},
] })),
react_1.default.createElement(react_native_1.SafeAreaView, { pointerEvents: "box-none", style: [
{
alignItems: placement === 'left' ? 'flex-start' : 'flex-end',
},
placement && (_b = {},
_b[placement] = 0,
_b.bottom = 0,
_b.position = 'absolute',
_b),
] },
react_1.default.Children.toArray(children).map(function (ChildAction, i) { return (react_1.default.createElement(react_native_1.Animated.View, { pointerEvents: isOpen ? 'auto' : 'none', key: i, style: {
transform: [{ scale: animations.current[i] }],
opacity: animations.current[i],
} }, react_1.default.cloneElement(ChildAction, {
placement: placement,
labelPressable: labelPressable,
}))); }),
react_1.default.createElement(FAB_1.FAB, __assign({ style: [styles.fab], icon: isOpen ? openIcon : icon, theme: theme }, rest, { onPress: isOpen ? onClose : onOpen })))));
};
exports.SpeedDial = SpeedDial;
var styles = react_native_1.StyleSheet.create({
safeArea: {
alignItems: 'flex-end',
},
container: __assign(__assign({}, react_native_1.StyleSheet.absoluteFillObject), { justifyContent: 'flex-end' }),
fab: {
margin: 16,
marginTop: 0,
},
});
exports.SpeedDial.displayName = 'SpeedDial';