@codeleap/mobile 2.4.5 → 2.4.7

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.
Files changed (48) hide show
  1. package/dist/components/ActionIcon/styles.d.ts +1 -1
  2. package/dist/components/ActivityIndicator/styles.d.ts +1 -1
  3. package/dist/components/AutoComplete/styles.d.ts +1 -1
  4. package/dist/components/Backdrop/styles.d.ts +1 -1
  5. package/dist/components/Button/index.d.ts +5 -5
  6. package/dist/components/Button/styles.d.ts +1 -1
  7. package/dist/components/Checkbox/index.d.ts +1 -1
  8. package/dist/components/Checkbox/styles.d.ts +1 -1
  9. package/dist/components/ContentView/styles.d.ts +1 -1
  10. package/dist/components/Drawer/styles.d.ts +1 -1
  11. package/dist/components/EmptyPlaceholder/styles.d.ts +1 -1
  12. package/dist/components/FileInput/styles.d.ts +1 -1
  13. package/dist/components/Grid/styles.d.ts +1 -1
  14. package/dist/components/Icon/styles.d.ts +1 -1
  15. package/dist/components/Image/styles.d.ts +1 -1
  16. package/dist/components/List/PaginationIndicator.d.ts +1 -1
  17. package/dist/components/List/styles.d.ts +1 -1
  18. package/dist/components/Modal/index.js +13 -8
  19. package/dist/components/Modal/index.js.map +1 -1
  20. package/dist/components/Modal/styles.d.ts +1 -1
  21. package/dist/components/Pager/styles.d.ts +1 -1
  22. package/dist/components/RadioInput/styles.d.ts +1 -1
  23. package/dist/components/Scroll/index.d.ts +1 -1
  24. package/dist/components/Scroll/styles.d.ts +1 -1
  25. package/dist/components/Sections/index.d.ts +1 -1
  26. package/dist/components/SegmentedControl/styles.d.ts +1 -1
  27. package/dist/components/Select/styles.d.ts +1 -1
  28. package/dist/components/Slider/styles.d.ts +1 -1
  29. package/dist/components/Switch/styles.d.ts +1 -1
  30. package/dist/components/Text/styles.d.ts +1 -1
  31. package/dist/components/TextInput/index.d.ts +2 -2
  32. package/dist/components/TextInput/index.js +1 -1
  33. package/dist/components/TextInput/index.js.map +1 -1
  34. package/dist/components/TextInput/styles.d.ts +1 -1
  35. package/dist/components/Touchable/styles.d.ts +1 -1
  36. package/dist/components/View/index.d.ts +2 -0
  37. package/dist/components/View/index.js +6 -1
  38. package/dist/components/View/index.js.map +1 -1
  39. package/dist/components/View/styles.d.ts +1 -1
  40. package/dist/components/defaultStyles.d.ts +27 -27
  41. package/dist/utils/hooks.d.ts +21 -2
  42. package/dist/utils/hooks.js +61 -2
  43. package/dist/utils/hooks.js.map +1 -1
  44. package/package.json +1 -1
  45. package/src/components/Modal/index.tsx +17 -16
  46. package/src/components/TextInput/index.tsx +2 -2
  47. package/src/components/View/index.tsx +3 -1
  48. package/src/utils/hooks.ts +110 -4
@@ -1,12 +1,11 @@
1
1
  import * as React from 'react'
2
- import { View, ViewProps } from '../View'
3
- import { Button, ButtonProps } from '../Button'
2
+ import { AnimatedView, View, ViewProps } from '../View'
3
+ import { ButtonProps } from '../Button'
4
4
  import { Scroll } from '../Scroll'
5
5
  import {
6
6
  ComponentVariants,
7
7
  getNestedStylesByKey,
8
8
  IconPlaceholder,
9
- onUpdate,
10
9
  PropsOf,
11
10
  TypeGuards,
12
11
  useDefaultComponentStyle,
@@ -19,9 +18,8 @@ import {
19
18
  import { StyleSheet } from 'react-native'
20
19
  import { StylesOf } from '../../types/utility'
21
20
 
22
- import { useDynamicAnimation } from 'moti'
23
21
  import { Backdrop } from '../Backdrop'
24
- import { useBackButton, useStaticAnimationStyles } from '../../utils/hooks'
22
+ import { useAnimatedVariantStyles, useBackButton, useStaticAnimationStyles } from '../../utils/hooks'
25
23
  import { Text, TextProps } from '../Text'
26
24
  import { Touchable } from '../Touchable'
27
25
  import { GetKeyboardAwarePropsOptions } from '../../utils'
@@ -124,13 +122,17 @@ export const Modal: React.FC<ModalProps> = (modalProps) => {
124
122
 
125
123
  const boxAnimationStates = useStaticAnimationStyles(variantStyles, ['box:hidden', 'box:visible'])
126
124
 
127
- const boxAnimation = useDynamicAnimation(() => {
128
- return visible ? boxAnimationStates['box:visible'] : boxAnimationStates['box:hidden']
125
+ const boxAnimationStyles = useAnimatedVariantStyles({
126
+ updater: (states ) => {
127
+ 'worklet';
128
+ return visible ? states['box:visible'] : states['box:hidden']
129
+ },
130
+ animatedProperties: ['box:hidden', 'box:visible'],
131
+ variantStyles,
132
+ transition:variantStyles['box:transition'],
133
+ dependencies: [visible]
129
134
  })
130
135
 
131
- onUpdate(() => {
132
- boxAnimation.animateTo(visible ? boxAnimationStates['box:visible'] : boxAnimationStates['box:hidden'])
133
- }, [visible])
134
136
  const wrapperStyle = getStyles('wrapper')
135
137
 
136
138
  const ScrollComponent = scroll ? Scroll : View
@@ -195,11 +197,10 @@ export const Modal: React.FC<ModalProps> = (modalProps) => {
195
197
  noFeedback
196
198
  />}
197
199
 
198
- <View
199
- animated
200
- state={boxAnimation}
201
- style={getStyles('box')}
202
- transition={{ ...variantStyles['box:transition'] }}
200
+ <AnimatedView
201
+
202
+ style={[getStyles('box'),boxAnimationStyles]}
203
+ // transition={{ ...variantStyles['box:transition'] }}
203
204
 
204
205
  {...props}
205
206
  >
@@ -212,7 +213,7 @@ export const Modal: React.FC<ModalProps> = (modalProps) => {
212
213
  {typeof footer === 'string' ? <Text text={footer} /> : footer}
213
214
  </View>
214
215
  )}
215
- </View>
216
+ </AnimatedView>
216
217
 
217
218
  </ScrollComponent>
218
219
  </View>
@@ -191,9 +191,9 @@ export const TextInput = forwardRef<NativeTextInput, TextInputProps>((rawprops,
191
191
  style={getStyles('wrapper')}
192
192
  debugName={debugName}
193
193
  onPress={handlePress}
194
- {...wrapperProps}
195
- android_ripple={null}
196
194
  noFeedback
195
+ android_ripple={null}
196
+ {...wrapperProps}
197
197
  >
198
198
  <InputLabel
199
199
  label={label}
@@ -13,7 +13,7 @@ import { View as NativeView } from 'react-native'
13
13
  import { MotiView, MotiProps } from 'moti'
14
14
  import { GetKeyboardAwarePropsOptions, useKeyboardAwareView } from '../../utils'
15
15
  import {TransitionConfig} from '../../types'
16
-
16
+ import Animated from 'react-native-reanimated'
17
17
  export * from './styles'
18
18
 
19
19
  type MotiViewProps = Omit< Partial<MotiProps>, 'transition'|'children'>
@@ -68,6 +68,8 @@ export const View: React.FC<ViewProps> = forwardRef<NativeView,ViewProps>((viewP
68
68
  )
69
69
  })
70
70
 
71
+ export const AnimatedView = Animated.createAnimatedComponent(View)
72
+
71
73
 
72
74
  type GapProps = ViewProps & {
73
75
  value: number
@@ -1,7 +1,8 @@
1
1
  import { onMount, onUpdate, shadeColor, TypeGuards, usePrevious, useRef, useState } from '@codeleap/common'
2
- import { Animated, AppState, AppStateStatus, Platform, PressableAndroidRippleConfig, BackHandler } from 'react-native'
3
- // @ts-ignore
2
+ import { Animated, AppState, AppStateStatus, Platform, PressableAndroidRippleConfig, BackHandler, ViewStyle, ImageStyle, TextStyle, StyleSheet } from 'react-native'
3
+
4
4
  import AsyncStorage from '@react-native-community/async-storage'
5
+ import { AnimatedStyleProp, Easing, EasingFn, useAnimatedStyle, withTiming } from 'react-native-reanimated'
5
6
 
6
7
  export function useAnimateColor(value: string, opts?: Partial<Animated.TimingAnimationConfig>) {
7
8
  const iters = useRef(0)
@@ -52,6 +53,10 @@ export function useAppState(filter?: AppStateStatus[]) {
52
53
  }
53
54
  }
54
55
 
56
+ type SelectProperties<T extends Record<string|number|symbol, any>, K extends keyof T> = {
57
+ [P in K] : T[K]
58
+ }
59
+
55
60
  export function useStaticAnimationStyles<T extends Record<string|number|symbol, any>, K extends keyof T >(obj: T, keys: K[]) {
56
61
  const styles = useRef({})
57
62
 
@@ -61,11 +66,112 @@ export function useStaticAnimationStyles<T extends Record<string|number|symbol,
61
66
  styles.current = Object.fromEntries(mappedStyles)
62
67
  }
63
68
 
64
- return styles.current as {
65
- [P in K] : T[K]
69
+ return styles.current as SelectProperties<T, K>
70
+ }
71
+
72
+ type AnimatableProperties = 'scale' | 'scaleX' | 'scaleY' | 'translateX' | 'translateY' | 'opacity'
73
+
74
+ type VariantTransitionConfig = {
75
+ type: 'timing'
76
+ duration?: number
77
+ easing?: EasingFn
78
+ }
79
+
80
+ type TransitionConfig = Partial<Record<AnimatableProperties, VariantTransitionConfig>> | VariantTransitionConfig
81
+
82
+
83
+ type UseAnimatedVariantStylesConfig<T extends Record<string|number|symbol, any>, K extends keyof T > = {
84
+ variantStyles: T
85
+ animatedProperties: K[]
86
+ updater: (states: SelectProperties<T, K>) => AnimatedStyleProp<ViewStyle | ImageStyle | TextStyle>
87
+ transition: TransitionConfig
88
+ dependencies?: any[]
89
+ }
90
+
91
+ const buildAnimatedStyle = (property: AnimatableProperties, value, currentStyle, applyFN = (v) => v) => {
92
+ 'worklet';
93
+ const newStyle = {...currentStyle}
94
+
95
+ switch(property){
96
+ case 'opacity':
97
+ newStyle.opacity = applyFN(value)
98
+ break
99
+ default:
100
+ if(!newStyle.transform){
101
+ newStyle.transform = []
102
+ }
103
+ newStyle.transform.push({
104
+ [property]: applyFN(value)
105
+ })
106
+ }
107
+
108
+ return newStyle
109
+
110
+ }
111
+
112
+ const transformProperties = (properties, transition) => {
113
+ 'worklet';
114
+ let styles = {}
115
+
116
+ for(const [prop, value] of Object.entries(properties)){
117
+ let transitionConfig = transition[prop] || transition
118
+
119
+ const _transitionConfig = {
120
+ type:'timing',
121
+ duration: 100,
122
+ easing: Easing.linear,
123
+ ...transitionConfig
124
+ }
125
+
126
+ const { type, duration, easing } = _transitionConfig
127
+
128
+ let fn
129
+
130
+ switch(type){
131
+ case 'timing':
132
+ fn = (v) => withTiming(v, {
133
+ duration,
134
+ easing
135
+ })
136
+ default:
137
+ break
138
+ }
139
+
140
+ styles = buildAnimatedStyle(
141
+ prop as AnimatableProperties,
142
+ value,
143
+ styles,
144
+ fn
145
+ )
146
+ }
147
+
148
+ return styles
149
+ }
150
+
151
+
152
+ export function useAnimatedVariantStyles<T extends Record<string|number|symbol, any>, K extends keyof T >(config: UseAnimatedVariantStylesConfig<T, K>){
153
+ const { animatedProperties, updater, variantStyles, transition, dependencies = []} = config
154
+
155
+ const _transition = useRef(null)
156
+
157
+ if(!_transition.current){
158
+ _transition.current = JSON.parse(JSON.stringify(transition))
66
159
  }
160
+
161
+ const staticStyles = useStaticAnimationStyles(variantStyles, animatedProperties)
162
+
163
+ const animated = useAnimatedStyle(() => {
164
+ const nextState = updater(staticStyles)
165
+
166
+ const formatted = transformProperties(nextState, _transition.current)
167
+
168
+ return formatted
169
+ }, [dependencies])
170
+
171
+ return animated
67
172
  }
68
173
 
174
+
69
175
  export type FeedbackConfig =
70
176
  | { type: 'opacity'; value?: number }
71
177
  | {type: 'highlight'; color?: string; brightness?: number; shiftOpacity?: number}