@gaddario98/react-native-core
Version:
```bash npm install @gaddario98/native ```
124 lines (123 loc) • 5.06 kB
JavaScript
import {jsx,jsxs}from'react/jsx-runtime';import {useCoreConfig}from'@gaddario98/react-core';import {useMemo}from'react';import {useAuthValue}from'../auth/index.mjs';import {useTranslation}from'../localization/index.mjs';import {useNotification}from'@gaddario98/react-core/notifications';import {createAsyncStoragePersister}from'@tanstack/query-async-storage-persister';import {storage,setReactNativeStorage}from'../state/index.mjs';import {DefaultView,Element}from'../pages/index.mjs';import {KeyboardAvoidingView,Platform,View,ActivityIndicator,Text}from'react-native';import {c}from'react/compiler-runtime';var asyncStoragePersister = createAsyncStoragePersister({
storage: storage
});
var DEFAULT_PADDING = 16;
var useReactNativeCoreConfig = function useReactNativeCoreConfig(props) {
var auth = useAuthValue();
var _useTranslation = useTranslation(),
translateText = _useTranslation.t;
var _useNotification = useNotification(),
showNotification = _useNotification.showNotification;
useCoreConfig({
apiConfig: 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: useMemo(function () {
return props.localization;
}, [props.localization]),
pages: useMemo(function () {
var _a_0;
return Object.assign(Object.assign({}, (_a_0 = props.pages) !== null && _a_0 !== void 0 ? _a_0 : {}), {
authValues: auth,
FooterContainer: Element,
HeaderContainer: Element,
ItemsContainer: function ItemsContainer(_ref) {
var children = _ref.children;
return jsx(View, {
style: {
paddingHorizontal: DEFAULT_PADDING,
flexDirection: "row",
alignItems: "center",
flexWrap: "wrap",
width: "100%"
},
children: children
});
},
BodyContainer: DefaultView,
PageContainer: function PageContainer(_ref2) {
var children_0 = _ref2.children,
id = _ref2.id;
return jsx(View, {
style: {
flex: 1
},
id: id,
children: children_0
}, id);
},
LoaderComponent: function LoaderComponent(_ref3) {
var loading = _ref3.loading,
message = _ref3.message;
return loading && jsxs(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: [jsx(ActivityIndicator, {
size: "small",
style: {
marginRight: 8
}
}), jsx(Text, {
children: message !== null && message !== void 0 ? message : "Caricamento in corso..."
})]
});
}
});
}, [auth, props.pages]),
form: useMemo(function () {
return {
translateText: translateText,
showNotification: showNotification,
formFieldContainer: function formFieldContainer(_ref4) {
var children_1 = _ref4.children;
return jsx(KeyboardAvoidingView, {
behavior: Platform.OS === "ios" ? "padding" : undefined,
children: children_1
});
}
};
}, [showNotification, translateText])
});
};setReactNativeStorage();
var ReactNativeCoreProvider = function ReactNativeCoreProvider(t0) {
var $ = 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;
};export{ReactNativeCoreProvider,asyncStoragePersister,useReactNativeCoreConfig};//# sourceMappingURL=index.mjs.map