UNPKG

@gaddario98/react-native-core

Version:
124 lines (123 loc) 5.36 kB
'use strict';var jsxRuntime=require('react/jsx-runtime'),reactCore=require('@gaddario98/react-core'),react=require('react'),index_ts$1=require('../auth/index.js'),index_ts$2=require('../localization/index.js'),notifications=require('@gaddario98/react-core/notifications'),queryAsyncStoragePersister=require('@tanstack/query-async-storage-persister'),index_ts=require('../state/index.js'),index_ts$3=require('../pages/index.js'),reactNative=require('react-native'),compilerRuntime=require('react/compiler-runtime');var asyncStoragePersister = queryAsyncStoragePersister.createAsyncStoragePersister({ storage: index_ts.storage }); var DEFAULT_PADDING = 16; var useReactNativeCoreConfig = function useReactNativeCoreConfig(props) { var auth = index_ts$1.useAuthValue(); var _useTranslation = index_ts$2.useTranslation(), translateText = _useTranslation.t; var _useNotification = notifications.useNotification(), showNotification = _useNotification.showNotification; reactCore.useCoreConfig({ apiConfig: react.useMemo(function () { var _a, _b, _c, _d, _e; return Object.assign(Object.assign({ validateAuthFn: function validateAuthFn() { return true; }, showNotification: showNotification }, (_a = props.apiConfig) !== null && _a !== void 0 ? _a : {}), { defaultHeaders: Object.assign({ Authorization: (auth === null || auth === void 0 ? void 0 : auth.token) ? "Bearer ".concat(auth.token) : "" }, (_c = (_b = props.apiConfig) === null || _b === void 0 ? void 0 : _b.defaultHeaders) !== null && _c !== void 0 ? _c : {}), persistOptions: Object.assign({ persister: asyncStoragePersister, maxAge: Infinity, buster: "persister-v1" }, (_e = (_d = props.apiConfig) === null || _d === void 0 ? void 0 : _d.persistOptions) !== null && _e !== void 0 ? _e : {}) }); }, [auth === null || auth === void 0 ? void 0 : auth.token, props.apiConfig, showNotification]), localization: react.useMemo(function () { return props.localization; }, [props.localization]), pages: react.useMemo(function () { var _a_0; return Object.assign(Object.assign({}, (_a_0 = props.pages) !== null && _a_0 !== void 0 ? _a_0 : {}), { authValues: auth, FooterContainer: index_ts$3.Element, HeaderContainer: index_ts$3.Element, ItemsContainer: function ItemsContainer(_ref) { var children = _ref.children; return jsxRuntime.jsx(reactNative.View, { style: { paddingHorizontal: DEFAULT_PADDING, flexDirection: "row", alignItems: "center", flexWrap: "wrap", width: "100%" }, children: children }); }, BodyContainer: index_ts$3.DefaultView, PageContainer: function PageContainer(_ref2) { var children_0 = _ref2.children, id = _ref2.id; return jsxRuntime.jsx(reactNative.View, { style: { flex: 1 }, id: id, children: children_0 }, id); }, LoaderComponent: function LoaderComponent(_ref3) { var loading = _ref3.loading, message = _ref3.message; return loading && jsxRuntime.jsxs(reactNative.View, { style: { position: "relative", top: 0, marginHorizontal: DEFAULT_PADDING, marginTop: DEFAULT_PADDING, zIndex: 1000, left: 0, right: 0, flexDirection: "row", alignItems: "center", padding: DEFAULT_PADDING, backgroundColor: "#e3f2fd", borderRadius: 8 }, children: [jsxRuntime.jsx(reactNative.ActivityIndicator, { size: "small", style: { marginRight: 8 } }), jsxRuntime.jsx(reactNative.Text, { children: message !== null && message !== void 0 ? message : "Caricamento in corso..." })] }); } }); }, [auth, props.pages]), form: react.useMemo(function () { return { translateText: translateText, showNotification: showNotification, formFieldContainer: function formFieldContainer(_ref4) { var children_1 = _ref4.children; return jsxRuntime.jsx(reactNative.KeyboardAvoidingView, { behavior: reactNative.Platform.OS === "ios" ? "padding" : undefined, children: children_1 }); } }; }, [showNotification, translateText]) }); };index_ts.setReactNativeStorage(); var ReactNativeCoreProvider = function ReactNativeCoreProvider(t0) { var $ = compilerRuntime.c(2); var children = t0.children, coreConfig = t0.coreConfig; var t1; if ($[0] !== coreConfig) { t1 = coreConfig !== null && coreConfig !== void 0 ? coreConfig : {}; $[0] = coreConfig; $[1] = t1; } else { t1 = $[1]; } useReactNativeCoreConfig(t1); return children; };exports.ReactNativeCoreProvider=ReactNativeCoreProvider;exports.asyncStoragePersister=asyncStoragePersister;exports.useReactNativeCoreConfig=useReactNativeCoreConfig;//# sourceMappingURL=index.js.map