@neko-os/ui 0.0.11 → 0.0.12

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.
@@ -1 +1 @@
1
- import _toConsumableArray from"@babel/runtime/helpers/toConsumableArray";var _jsxFileName="/Users/christianstorch/Apps/nekoapps/libs/neko-ui/src/abstractions/AnimatedView.native.js";import{map,prop}from'ramda';import Animated,{useAnimatedStyle}from'react-native-reanimated';import{jsx as _jsx}from"react/jsx-runtime";export function AbsAnimatedView(_ref){var children=_ref.children,style=_ref.style,_ref$animatedStyles=_ref.animatedStyles,animatedStyles=_ref$animatedStyles===void 0?[]:_ref$animatedStyles;return _jsx(Animated.View,{style:[style].concat(_toConsumableArray(animatedStyles)),children:children});}
1
+ import _toConsumableArray from"@babel/runtime/helpers/toConsumableArray";var _jsxFileName="/Users/christianstorch/Apps/nekoapps/libs/neko-ui/src/abstractions/AnimatedView.native.js";import Animated from'react-native-reanimated';import{jsx as _jsx}from"react/jsx-runtime";export function AbsAnimatedView(_ref){var children=_ref.children,style=_ref.style,_ref$animatedStyles=_ref.animatedStyles,animatedStyles=_ref$animatedStyles===void 0?[]:_ref$animatedStyles;return _jsx(Animated.View,{style:[style].concat(_toConsumableArray(animatedStyles)),children:children});}
@@ -1 +1 @@
1
- import{useAnimatedEffect as useAnimatedEffectNative}from"./animatedEffects.native";export var useAnimatedEffects=useAnimatedEffectNative;
1
+ import _objectWithoutProperties from"@babel/runtime/helpers/objectWithoutProperties";import _slicedToArray from"@babel/runtime/helpers/slicedToArray";var _excluded=["open","onClose","lazy","unmountOnClose"];import{pipe}from'ramda';import{useSharedValue}from'react-native-reanimated';import React from'react';import{useFadeEffect}from"./fadeEffect";import{useScaleEffect}from"./scaleEffect";import{useSlideEffect}from"./slideEffect";export function useAnimatedEffects(_ref){var _ref2=_slicedToArray(_ref,2),values=_ref2[0],_ref2$=_ref2[1],_ref2$$open=_ref2$.open,open=_ref2$$open===void 0?true:_ref2$$open,onClose=_ref2$.onClose,_ref2$$lazy=_ref2$.lazy,lazy=_ref2$$lazy===void 0?false:_ref2$$lazy,_ref2$$unmountOnClose=_ref2$.unmountOnClose,unmountOnClose=_ref2$$unmountOnClose===void 0?false:_ref2$$unmountOnClose,props=_objectWithoutProperties(_ref2$,_excluded);var unmountTimerRef=React.useRef();var _React$useState=React.useState(0),_React$useState2=_slicedToArray(_React$useState,2),totalDuration=_React$useState2[0],setTotalDuration=_React$useState2[1];var _React$useState3=React.useState(open||!lazy),_React$useState4=_slicedToArray(_React$useState3,2),hasOpened=_React$useState4[0],setHasOpened=_React$useState4[1];var _React$useState5=React.useState(open||!lazy),_React$useState6=_slicedToArray(_React$useState5,2),render=_React$useState6[0],setRender=_React$useState6[1];var useRegisterEffect=function useRegisterEffect(effect){React.useEffect(function(){if(!(effect!=null&&effect.duration))return;setTotalDuration(function(v){return v>effect.duration?v:effect.duration;});},[]);};var translate=useSharedValue(0);React.useEffect(function(){if(open){clearTimeout(unmountTimerRef==null?void 0:unmountTimerRef.current);setHasOpened(true);setRender(true);}else if(unmountOnClose){unmountTimerRef.current=setTimeout(function(){return setRender(false);},totalDuration);}},[open]);return pipe(useFadeEffect,useSlideEffect,useScaleEffect)([Object.assign({},values,{animatedStyles:[],useRegisterEffect:useRegisterEffect,useAddTransition:function useAddTransition(){},open:open,onClose:onClose,lazy:lazy,unmountOnClose:unmountOnClose,hasOpened:hasOpened,setHasOpened:setHasOpened,render:render,setRender:setRender}),Object.assign({},props,{animatedStyles:[]})]);}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neko-os/ui",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "author": "Christian Storch <ccstorch@gmail.com>",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -1,5 +1,4 @@
1
- import { map, prop } from 'ramda'
2
- import Animated, { useAnimatedStyle } from 'react-native-reanimated'
1
+ import Animated from 'react-native-reanimated'
3
2
 
4
3
  export function AbsAnimatedView({ children, style, animatedStyles = [] }) {
5
4
  return <Animated.View style={[style, ...animatedStyles]}>{children}</Animated.View>
@@ -24,7 +24,6 @@ export function useAnimatedEffects([values, { open, onClose, lazy = false, unmou
24
24
  const useAddTransition = (effect, transition) => {
25
25
  React.useEffect(() => {
26
26
  if (!effect?.duration) return
27
-
28
27
  setTransitions((v) => [...v, transition])
29
28
  }, [])
30
29
  }
@@ -1,3 +1,55 @@
1
- import { useAnimatedEffect as useAnimatedEffectNative } from './animatedEffects.native'
1
+ import { pipe } from 'ramda'
2
+ import { useSharedValue } from 'react-native-reanimated'
3
+ import React from 'react'
2
4
 
3
- export const useAnimatedEffects = useAnimatedEffectNative
5
+ import { useFadeEffect } from './fadeEffect'
6
+ import { useScaleEffect } from './scaleEffect'
7
+ import { useSlideEffect } from './slideEffect'
8
+
9
+ export function useAnimatedEffects([values, { open = true, onClose, lazy = false, unmountOnClose = false, ...props }]) {
10
+ const unmountTimerRef = React.useRef()
11
+ const [totalDuration, setTotalDuration] = React.useState(0)
12
+ const [hasOpened, setHasOpened] = React.useState(open || !lazy)
13
+ const [render, setRender] = React.useState(open || !lazy)
14
+
15
+ const useRegisterEffect = (effect) => {
16
+ React.useEffect(() => {
17
+ if (!effect?.duration) return
18
+ setTotalDuration((v) => (v > effect.duration ? v : effect.duration))
19
+ }, [])
20
+ }
21
+
22
+ const translate = useSharedValue(0)
23
+
24
+ React.useEffect(() => {
25
+ if (open) {
26
+ clearTimeout(unmountTimerRef?.current)
27
+ setHasOpened(true)
28
+ setRender(true)
29
+ } else if (unmountOnClose) {
30
+ unmountTimerRef.current = setTimeout(() => setRender(false), totalDuration)
31
+ }
32
+ }, [open])
33
+
34
+ return pipe(
35
+ useFadeEffect, //
36
+ useSlideEffect,
37
+ useScaleEffect
38
+ )([
39
+ {
40
+ ...values,
41
+ animatedStyles: [],
42
+ useRegisterEffect,
43
+ useAddTransition: () => {},
44
+ open,
45
+ onClose,
46
+ lazy,
47
+ unmountOnClose,
48
+ hasOpened,
49
+ setHasOpened,
50
+ render,
51
+ setRender,
52
+ },
53
+ { ...props, animatedStyles: [] },
54
+ ])
55
+ }