Skip to content

Commit

Permalink
package refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
kurucaner committed Jan 31, 2025
1 parent e369910 commit f074b3d
Show file tree
Hide file tree
Showing 11 changed files with 246 additions and 232 deletions.
3 changes: 2 additions & 1 deletion dist/index.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ interface SmoothPushNotification {
message: string;
config?: NotificationConfig;
}

interface SmoothPushProviderProps {
defaultConfig?: NotificationConfig;
}
declare const SmoothPushProvider: react.MemoExoticComponent<({ defaultConfig }: SmoothPushProviderProps) => react_jsx_runtime.JSX.Element>;
declare const show: (params: SmoothPushNotification) => void;

export { type NotificationConfig, type SmoothPushNotification, SmoothPushProvider, type SmoothPushType, show };
export { SmoothPushProvider, show };
3 changes: 2 additions & 1 deletion dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ interface SmoothPushNotification {
message: string;
config?: NotificationConfig;
}

interface SmoothPushProviderProps {
defaultConfig?: NotificationConfig;
}
declare const SmoothPushProvider: react.MemoExoticComponent<({ defaultConfig }: SmoothPushProviderProps) => react_jsx_runtime.JSX.Element>;
declare const show: (params: SmoothPushNotification) => void;

export { type NotificationConfig, type SmoothPushNotification, SmoothPushProvider, type SmoothPushType, show };
export { SmoothPushProvider, show };
2 changes: 1 addition & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.mjs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
var B=Object.defineProperty;var z=Object.getOwnPropertySymbols;var J=Object.prototype.hasOwnProperty,K=Object.prototype.propertyIsEnumerable;var W=(e,t,o)=>t in e?B(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,x=(e,t)=>{for(var o in t||(t={}))J.call(t,o)&&W(e,o,t[o]);if(z)for(var o of z(t))K.call(t,o)&&W(e,o,t[o]);return e};import{memo as H,useEffect as Q,useMemo as k,useState as C}from"react";import{Pressable as Z,StyleSheet as $,View as L,Text as I}from"react-native";import{Gesture as ee,GestureDetector as te}from"react-native-gesture-handler";import h,{Easing as V,Extrapolation as oe,interpolate as Y,useAnimatedStyle as p,useSharedValue as c,withDelay as F,withSpring as ne,withTiming as l}from"react-native-reanimated";import{jsx as s,jsxs as G}from"react/jsx-runtime";var E,N=null,g=-180,ie=-55,y=400,M=H(({type:e,message:t,textStyle:o})=>{let d=c(0),u=c(0),r=c(0);Q(()=>{d.value=0,u.value=0,r.value=0,d.value=l(1,{duration:400,easing:V.bezier(.34,1.56,.64,1)}),u.value=F(100,l(1,{duration:500,easing:V.bezier(.65,0,.35,1)})),r.value=F(200,l(1,{duration:300,easing:V.bezier(.4,0,.2,1)}))},[e,t]);let S=p(()=>({transform:[{scale:d.value}],backgroundColor:e==="success"?"#E7F6E7":"#FEE7E7"})),w=p(()=>({opacity:u.value,transform:[{scale:Y(u.value,[0,.6,1],[.6,1.1,1],oe.CLAMP)}]})),f=p(()=>({opacity:r.value,transform:[{translateX:Y(r.value,[0,1],[-10,0])}]})),m=k(()=>e==="success"?s(I,{style:[n.icon,n.successIcon],children:"\u2713"}):e==="error"?s(I,{style:[n.icon,n.errorIcon],children:"\u2715"}):null,[e]);return t?G(L,{style:n.smoothPushContainer,children:[s(h.View,{style:[n.iconContainer,S],children:s(h.View,{style:w,children:m})}),s(h.View,{style:[n.messageContainer,f],children:s(I,{style:[n.toastMessage,o],numberOfLines:3,children:t})})]}):null});M.displayName="SmoothPush";var se=H(({defaultConfig:e})=>{let[t,o]=C(null),[d,u]=C(null),[r,S]=C(e!=null?e:{}),{duration:w=6e3,position:f="top",offset:m=60,maxWidth:D=400,swipeThreshold:U=ie,stickColor:A="#ffcad4",onPress:P,onClose:v}=r,a=c(g),T=c(!1),b=c(!1),O=p(()=>({transform:[{translateY:a.value}]})),_=ee.Pan().onStart(i=>{"worklet";T.value=!0,i.translationY=a.value}).onUpdate(i=>{"worklet";i.translationY>0?a.value=i.translationY/15:a.value=i.translationY}).onEnd(i=>{"worklet";T.value=!1,i.translationY<U?a.value=l(g,{duration:y}):a.value=ne(0),b.value&&(a.value=l(g,{duration:y}))}),R=()=>{a.value=l(g,{duration:y}),v==null||v()};E=i=>{b.value=!1,N&&clearTimeout(N),u(i.toastType),o(i.message),S(x(x({},e),i.config)),a.value=l(0,{duration:y}),N=setTimeout(()=>{T.value||R(),b.value=!0},w)};let X=()=>{P==null||P(),R()},j=k(()=>[n.container,{[f]:m,maxWidth:D},r.containerStyle,O],[f,m,D,r.containerStyle,O]),q=k(()=>[n.stick,{backgroundColor:A}],[A]);return s(te,{gesture:_,children:G(h.View,{style:j,children:[s(h.View,{style:n.blurContainer,children:s(Z,{onPress:X,style:n.notification,children:s(M,{type:d,message:t,textStyle:r.textStyle})})}),s(L,{style:q})]})})});se.displayName="SmoothPushProvider";var n=$.create({container:{width:"90%",maxWidth:400,position:"absolute",top:60,zIndex:9999,alignSelf:"center",borderRadius:10,overflow:"hidden",borderWidth:1,borderColor:"#f5f3f4"},blurContainer:{flex:1,backgroundColor:"rgba(255, 255, 255, 0.95)",borderRadius:10,padding:10,shadowColor:"#000",shadowOffset:{width:0,height:2},shadowOpacity:.1,shadowRadius:8,elevation:5},notification:{flexDirection:"row",alignItems:"center",gap:12},stick:{height:4,width:40,position:"absolute",bottom:8,alignSelf:"center",borderRadius:2,backgroundColor:"#ffcad4"},notificationText:{flex:1,color:"#333333",fontSize:16},smoothPushContainer:{flexDirection:"row",alignItems:"center",gap:12,paddingVertical:8,paddingHorizontal:6},iconContainer:{width:28,height:28,borderRadius:14,justifyContent:"center",alignItems:"center"},icon:{fontSize:16,fontWeight:"700"},successIcon:{color:"#2E7D32"},errorIcon:{color:"#D32F2F"},messageContainer:{flex:1,paddingRight:4},toastMessage:{fontSize:14,lineHeight:18,color:"#1a1a1a",fontWeight:"500"}}),he=e=>{E&&E(e)};export{se as SmoothPushProvider,he as show};
var Q=Object.defineProperty;var Y=Object.getOwnPropertySymbols;var Z=Object.prototype.hasOwnProperty,$=Object.prototype.propertyIsEnumerable;var L=(t,e,o)=>e in t?Q(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,I=(t,e)=>{for(var o in e||(e={}))Z.call(e,o)&&L(t,o,e[o]);if(Y)for(var o of Y(e))$.call(e,o)&&L(t,o,e[o]);return t};import{memo as rt,useCallback as _,useMemo as G,useState as D}from"react";import{Pressable as at,View as lt}from"react-native";import{Gesture as ut,GestureDetector as ct}from"react-native-gesture-handler";import U,{useAnimatedStyle as mt,useSharedValue as O,withSpring as ht,withTiming as g}from"react-native-reanimated";import{StyleSheet as j}from"react-native";var i=j.create({container:{width:"90%",maxWidth:400,position:"absolute",top:60,zIndex:9999,alignSelf:"center",borderRadius:10,overflow:"hidden",borderWidth:1,borderColor:"#f5f3f4"},blurContainer:{flex:1,backgroundColor:"rgba(255, 255, 255, 0.95)",borderRadius:10,padding:10,shadowColor:"#000",shadowOffset:{width:0,height:2},shadowOpacity:.1,shadowRadius:8,elevation:5},notification:{flexDirection:"row",alignItems:"center",gap:12},stick:{height:4,width:40,position:"absolute",bottom:8,alignSelf:"center",borderRadius:2,backgroundColor:"#ffcad4"},smoothPushContainer:{flexDirection:"row",alignItems:"center",gap:12,paddingVertical:8,paddingHorizontal:6},iconContainer:{width:28,height:28,borderRadius:14,justifyContent:"center",alignItems:"center"},icon:{fontSize:16,fontWeight:"700"},successIcon:{color:"#2E7D32"},errorIcon:{color:"#D32F2F"},messageContainer:{flex:1,paddingRight:4},toastMessage:{fontSize:14,lineHeight:18,color:"#1a1a1a",fontWeight:"500"}});import{memo as tt,useEffect as et}from"react";import{Text as b,View as ot}from"react-native";import x,{Easing as C,Extrapolation as it,interpolate as F,useAnimatedStyle as N,useSharedValue as V,withDelay as M,withTiming as A}from"react-native-reanimated";import{jsx as l,jsxs as nt}from"react/jsx-runtime";var E=tt(({type:t,message:e,textStyle:o})=>{let u=V(0),a=V(0),s=V(0);et(()=>{u.value=0,a.value=0,s.value=0,u.value=A(1,{duration:400,easing:C.bezier(.34,1.56,.64,1)}),a.value=M(100,A(1,{duration:500,easing:C.bezier(.65,0,.35,1)})),s.value=M(200,A(1,{duration:300,easing:C.bezier(.4,0,.2,1)}))},[t,e]);let y=N(()=>({transform:[{scale:u.value}],backgroundColor:t==="success"?"#E7F6E7":"#FEE7E7"})),P=N(()=>({opacity:a.value,transform:[{scale:F(a.value,[0,.6,1],[.6,1.1,1],it.CLAMP)}]})),m=N(()=>({opacity:s.value,transform:[{translateX:F(s.value,[0,1],[-10,0])}]})),h=()=>t==="success"?l(b,{style:[i.icon,i.successIcon],children:"\u2713"}):t==="error"?l(b,{style:[i.icon,i.errorIcon],children:"\u2715"}):null;return e?nt(ot,{style:i.smoothPushContainer,children:[l(x.View,{style:[i.iconContainer,y],children:l(x.View,{style:P,children:h()})}),l(x.View,{style:[i.messageContainer,m],children:l(b,{style:[i.toastMessage,o],numberOfLines:3,children:e})})]}):null});E.displayName="SmoothPush";import{jsx as c,jsxs as ft}from"react/jsx-runtime";var k,R=null,dt=rt(({defaultConfig:t})=>{let[e,o]=D(null),[u,a]=D(null),[s,y]=D(t!=null?t:{}),{duration:P=6e3,position:m="top",offset:h=60,maxWidth:z=400,swipeThreshold:X=-55,stickColor:H="#ffcad4",onPress:d,onClose:f}=s,r=O(-180),v=O(!1),w=O(!1),W=mt(()=>({transform:[{translateY:r.value}]})),q=ut.Pan().onStart(n=>{v.value=!0,n.translationY=r.value}).onUpdate(n=>{n.translationY>0?r.value=n.translationY/15:r.value=n.translationY}).onEnd(n=>{v.value=!1,n.translationY<X?r.value=g(-180,{duration:400}):r.value=ht(0),w.value&&(r.value=g(-180,{duration:400}))}),T=_(()=>{r.value=g(-180,{duration:400}),f==null||f()},[f]),B=_(()=>{d==null||d(),T()},[d,T]);k=n=>{w.value=!1,R&&clearTimeout(R),a(n.toastType),o(n.message),y(I(I({},t),n.config)),r.value=g(0,{duration:400}),R=setTimeout(()=>{v.value||T(),w.value=!0},P)};let J=G(()=>[i.container,{[m]:h,maxWidth:z},s.containerStyle,W],[m,h,z,s.containerStyle,W]),K=G(()=>[i.stick,{backgroundColor:H}],[H]);return c(ct,{gesture:q,children:ft(U.View,{style:J,children:[c(U.View,{style:i.blurContainer,children:c(at,{onPress:B,style:i.notification,children:c(E,{type:u,message:e,textStyle:s.textStyle})})}),c(lt,{style:K})]})})});dt.displayName="SmoothPushProvider";var Ot=t=>{k&&k(t)};export{dt as SmoothPushProvider,Ot as show};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "smooth-push",
"version": "1.5.9",
"version": "1.5.10",
"author": "CK",
"repository": {
"type": "git",
Expand Down
3 changes: 3 additions & 0 deletions src/consts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const INITIAL_POSITION = -180;
export const SWIPE_THRESHOLD = -55;
export const DURATION = 400;
Loading

0 comments on commit f074b3d

Please sign in to comment.