UNPKG

@livelike/react-native

Version:

LiveLike React Native package

80 lines (79 loc) 3.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LLLoadActionButtonComponent = LLLoadActionButtonComponent; var _react = _interopRequireWildcard(require("react")); var _reactNative = require("react-native"); var _hooks = require("../../hooks"); var _LLText = require("../LLText"); function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } function LLLoadActionButtonComponent(_ref) { let { onPress, label, actionInProgressLabel, styles: stylesProp } = _ref; const loadMoreStyles = (0, _hooks.useStyles)({ componentStylesFn: getLoadMoreButtonStyles, stylesProp }); const { theme } = (0, _hooks.useTheme)(); const [isLoading, setIsLoading] = (0, _react.useState)(false); const onLoad = (0, _react.useCallback)(() => { setIsLoading(true); onPress().finally(() => { setIsLoading(false); }); }, [setIsLoading, onPress]); return /*#__PURE__*/_react.default.createElement(_reactNative.View, { style: loadMoreStyles.buttonContainer }, /*#__PURE__*/_react.default.createElement(_reactNative.TouchableHighlight, { disabled: isLoading, onPress: onLoad, style: [loadMoreStyles.button, isLoading && loadMoreStyles.disabledbutton], underlayColor: theme.primaryPressedButtonBackground, activeOpacity: 1 }, /*#__PURE__*/_react.default.createElement(_LLText.LLText, { style: [loadMoreStyles.buttonText, isLoading && loadMoreStyles.disabledButtonText] }, isLoading ? actionInProgressLabel : label))); } const getLoadMoreButtonStyles = _ref2 => { let { theme } = _ref2; return _reactNative.StyleSheet.create({ buttonContainer: { display: 'flex', justifyContent: 'center', width: '100%', alignItems: 'center' }, button: { display: 'flex', justifyContent: 'center', alignItems: 'center', width: 190, height: 40, borderRadius: 8, marginBottom: 16, backgroundColor: theme.primaryButtonBackground }, disabledbutton: { backgroundColor: theme.disabledButtonBackground, width: 210 }, buttonText: { fontSize: 14, color: theme.text }, disabledButtonText: { color: theme.disabledButtonText } }); }; //# sourceMappingURL=LLLoadActionButton.js.map