@mbrain/epic-react-native-lib 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var p=Object.create;var y=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var v=(t,e)=>{for(var o in e)y(t,o,{get:e[o],enumerable:!0})},f=(t,e,o,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of O(e))!w.call(t,a)&&a!==o&&y(t,a,{get:()=>e[a],enumerable:!(r=k(e,a))||r.enumerable});return t};var d=(t,e,o)=>(o=t!=null?p(V(t)):{},f(e||!t||!t.__esModule?y(o,"default",{value:t,enumerable:!0}):o,t)),M=t=>f(y({},"__esModule",{value:!0}),t);var C={};v(C,{Box1:()=>g,createLocalStorage:()=>K,useOrientation:()=>h});module.exports=M(C);var l=d(require("react"),1),i=require("react-native");function g({style:t,children:e}){let[o,r]=(0,l.useState)(0);return l.default.createElement(i.View,{style:t},l.default.createElement(i.Text,{style:A.text,onPress:()=>{r(a=>a+1)}},"Box1 ",o),e)}var A=i.StyleSheet.create({text:{fontSize:20,padding:15,borderRadius:10,color:"#ffffff",backgroundColor:"#0a234a"}});var m=require("react"),s=d(require("expo-screen-orientation"),1);function h(){let[t,e]=(0,m.useState)({orientation:void 0,orientationLock:void 0});return(0,m.useEffect)(()=>{Promise.all([s.getOrientationAsync(),s.getOrientationLockAsync()]).then(([r,a])=>{e({orientation:r,orientationLock:a})});let o=s.addOrientationChangeListener(r=>{e({orientation:r.orientationInfo.orientation,orientationLock:r.orientationLock})});return()=>o.remove()},[]),t}var L=require("react"),u=require("react-native-mmkv");function K({defaults:t,storage:e=(0,u.createMMKV)()}){let o=n=>{try{let c=e.getString(String(n));return c!==void 0?JSON.parse(c):t[n]}catch(c){return console.warn(c),t[n]}};return{useLocalStorage:n=>{let[c,S]=(0,L.useState)(()=>o(n));return(0,u.useMMKVListener)(x=>{String(n)===x&&S(o(n))},e),c},setLocalStorage:(n,c)=>{try{let S=JSON.stringify(c);e.set(String(n),S)}catch(S){console.warn(S)}},getLocalStorage:n=>o(n),removeLocalStorage:n=>{try{e.remove(String(n))}catch(c){console.warn(c)}},clearAllLocalStorage:()=>{try{e.clearAll()}catch(n){console.warn(n)}},storage:e}}
1
+ "use strict";var V=Object.create;var u=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var M=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty;var A=(e,t)=>{for(var n in t)u(e,n,{get:t[n],enumerable:!0})},g=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of C(t))!E.call(e,a)&&a!==n&&u(e,a,{get:()=>t[a],enumerable:!(o=w(t,a))||o.enumerable});return e};var m=(e,t,n)=>(n=e!=null?V(M(e)):{},g(t||!e||!e.__esModule?u(n,"default",{value:e,enumerable:!0}):n,e)),b=e=>g(u({},"__esModule",{value:!0}),e);var P={};A(P,{Box1:()=>d,createLocalStorage:()=>L,useLogRouteChange:()=>k,useOrientation:()=>p});module.exports=b(P);var S=m(require("react"),1),c=require("react-native");function d({style:e,children:t}){let[n,o]=(0,S.useState)(0);return S.default.createElement(c.View,{style:e},S.default.createElement(c.Text,{style:N.text,onPress:()=>{o(a=>a+1)}},"Box1 ",n),t)}var N=c.StyleSheet.create({text:{fontSize:20,padding:15,borderRadius:10,color:"#ffffff",backgroundColor:"#0a234a"}});var f=require("react"),s=m(require("expo-screen-orientation"),1);function p(){let[e,t]=(0,f.useState)({orientation:void 0,orientationLock:void 0});return(0,f.useEffect)(()=>{Promise.all([s.getOrientationAsync(),s.getOrientationLockAsync()]).then(([o,a])=>{t({orientation:o,orientationLock:a})});let n=s.addOrientationChangeListener(o=>{t({orientation:o.orientationInfo.orientation,orientationLock:o.orientationLock})});return()=>n.remove()},[]),e}var h=require("react"),y=require("react-native-mmkv");function L({defaults:e,storage:t=(0,y.createMMKV)()}){let n=r=>{try{let i=t.getString(String(r));return i!==void 0?JSON.parse(i):e[r]}catch(i){return console.warn(i),e[r]}};return{useLocalStorage:r=>{let[i,l]=(0,h.useState)(()=>n(r));return(0,y.useMMKVListener)(v=>{String(r)===v&&l(n(r))},t),i},setLocalStorage:(r,i)=>{try{let l=JSON.stringify(i);t.set(String(r),l)}catch(l){console.warn(l)}},getLocalStorage:r=>n(r),removeLocalStorage:r=>{try{t.remove(String(r))}catch(i){console.warn(i)}},clearAllLocalStorage:()=>{try{t.clearAll()}catch(r){console.warn(r)}},storage:t}}var x=m(require("react"),1),K=require("expo-router"),O=m(require("lodash/isEmpty"),1);function k(){let e=(0,K.useNavigationContainerRef)();x.default.useEffect(()=>{if(__DEV__)return e.addListener("state",()=>{let n=e.getState(),o=R(n);o&&((0,O.default)(o.params)?console.log(`ROUTE CHANGED : ${o.name}`):console.log(`ROUTE CHANGED : ${o.name}`,o.params))})},[e])}function R(e){var t;if(!e)return null;if(e.routes&&e.routes.length>0){let n=(t=e.index)!=null?t:0,o=e.routes[n];if(!o)return null;if(o.state){let a=R(o.state);if(a)return a}return{name:o.name,params:o.params}}return null}
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import S,{useState as y}from"react";import{View as m,Text as u,StyleSheet as f}from"react-native";function d({style:a,children:t}){let[n,r]=y(0);return S.createElement(m,{style:a},S.createElement(u,{style:g.text,onPress:()=>{r(s=>s+1)}},"Box1 ",n),t)}var g=f.create({text:{fontSize:20,padding:15,borderRadius:10,color:"#ffffff",backgroundColor:"#0a234a"}});import{useEffect as h,useState as L}from"react";import*as c from"expo-screen-orientation";function K(){let[a,t]=L({orientation:void 0,orientationLock:void 0});return h(()=>{Promise.all([c.getOrientationAsync(),c.getOrientationLockAsync()]).then(([r,s])=>{t({orientation:r,orientationLock:s})});let n=c.addOrientationChangeListener(r=>{t({orientation:r.orientationInfo.orientation,orientationLock:r.orientationLock})});return()=>n.remove()},[]),a}import{useState as x}from"react";import{createMMKV as p,useMMKVListener as k}from"react-native-mmkv";function O({defaults:a,storage:t=p()}){let n=e=>{try{let o=t.getString(String(e));return o!==void 0?JSON.parse(o):a[e]}catch(o){return console.warn(o),a[e]}};return{useLocalStorage:e=>{let[o,i]=x(()=>n(e));return k(l=>{String(e)===l&&i(n(e))},t),o},setLocalStorage:(e,o)=>{try{let i=JSON.stringify(o);t.set(String(e),i)}catch(i){console.warn(i)}},getLocalStorage:e=>n(e),removeLocalStorage:e=>{try{t.remove(String(e))}catch(o){console.warn(o)}},clearAllLocalStorage:()=>{try{t.clearAll()}catch(e){console.warn(e)}},storage:t}}export{d as Box1,O as createLocalStorage,K as useOrientation};
1
+ import l,{useState as m}from"react";import{View as f,Text as y,StyleSheet as g}from"react-native";function d({style:t,children:o}){let[r,e]=m(0);return l.createElement(f,{style:t},l.createElement(y,{style:p.text,onPress:()=>{e(i=>i+1)}},"Box1 ",r),o)}var p=g.create({text:{fontSize:20,padding:15,borderRadius:10,color:"#ffffff",backgroundColor:"#0a234a"}});import{useEffect as h,useState as L}from"react";import*as c from"expo-screen-orientation";function x(){let[t,o]=L({orientation:void 0,orientationLock:void 0});return h(()=>{Promise.all([c.getOrientationAsync(),c.getOrientationLockAsync()]).then(([e,i])=>{o({orientation:e,orientationLock:i})});let r=c.addOrientationChangeListener(e=>{o({orientation:e.orientationInfo.orientation,orientationLock:e.orientationLock})});return()=>r.remove()},[]),t}import{useState as K}from"react";import{createMMKV as O,useMMKVListener as k}from"react-native-mmkv";function R({defaults:t,storage:o=O()}){let r=n=>{try{let a=o.getString(String(n));return a!==void 0?JSON.parse(a):t[n]}catch(a){return console.warn(a),t[n]}};return{useLocalStorage:n=>{let[a,s]=K(()=>r(n));return k(u=>{String(n)===u&&s(r(n))},o),a},setLocalStorage:(n,a)=>{try{let s=JSON.stringify(a);o.set(String(n),s)}catch(s){console.warn(s)}},getLocalStorage:n=>r(n),removeLocalStorage:n=>{try{o.remove(String(n))}catch(a){console.warn(a)}},clearAllLocalStorage:()=>{try{o.clearAll()}catch(n){console.warn(n)}},storage:o}}import v from"react";import{useNavigationContainerRef as V}from"expo-router";import w from"lodash/isEmpty";function C(){let t=V();v.useEffect(()=>{if(__DEV__)return t.addListener("state",()=>{let r=t.getState(),e=S(r);e&&(w(e.params)?console.log(`ROUTE CHANGED : ${e.name}`):console.log(`ROUTE CHANGED : ${e.name}`,e.params))})},[t])}function S(t){var o;if(!t)return null;if(t.routes&&t.routes.length>0){let r=(o=t.index)!=null?o:0,e=t.routes[r];if(!e)return null;if(e.state){let i=S(e.state);if(i)return i}return{name:e.name,params:e.params}}return null}export{d as Box1,R as createLocalStorage,C as useLogRouteChange,x as useOrientation};
@@ -1,3 +1,4 @@
1
1
  export { Box1 } from './components/Box1';
2
2
  export { useOrientation } from './utils/orientation';
3
3
  export { createLocalStorage } from './storage/local-storage';
4
+ export { useLogRouteChange } from './navigation/utils';
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Logs to console route path change in dev environment.
3
+ *
4
+ * ## Usage
5
+ *
6
+ * Add this hook to root layout.
7
+ *
8
+ * ```
9
+ * useLogRouteChange();
10
+ * ```
11
+ */
12
+ export declare function useLogRouteChange(): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mbrain/epic-react-native-lib",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "A set of helpful, battle-tested utilities that simplify common React Native workflows and speed up app development",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -34,7 +34,9 @@
34
34
  }
35
35
  },
36
36
  "dependencies": {
37
+ "expo-router": "^6.0.17",
37
38
  "expo-screen-orientation": "^9.0.0",
39
+ "lodash": "^4.17.21",
38
40
  "react-native-mmkv": "^4.0.1"
39
41
  },
40
42
  "peerDependencies": {
@@ -52,6 +54,7 @@
52
54
  }
53
55
  },
54
56
  "devDependencies": {
57
+ "@types/lodash": "^4.17.21",
55
58
  "@types/react": "^19.2.5",
56
59
  "@typescript-eslint/eslint-plugin": "^8.46.4",
57
60
  "@typescript-eslint/parser": "^8.46.4",