@codeleap/mobile 2.4.6 → 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.
- package/dist/components/ActionIcon/styles.d.ts +1 -1
- package/dist/components/ActivityIndicator/styles.d.ts +1 -1
- package/dist/components/AutoComplete/styles.d.ts +1 -1
- package/dist/components/Backdrop/styles.d.ts +1 -1
- package/dist/components/Button/index.d.ts +5 -5
- package/dist/components/Button/styles.d.ts +1 -1
- package/dist/components/Checkbox/index.d.ts +1 -1
- package/dist/components/Checkbox/styles.d.ts +1 -1
- package/dist/components/ContentView/styles.d.ts +1 -1
- package/dist/components/Drawer/styles.d.ts +1 -1
- package/dist/components/EmptyPlaceholder/styles.d.ts +1 -1
- package/dist/components/FileInput/styles.d.ts +1 -1
- package/dist/components/Grid/styles.d.ts +1 -1
- package/dist/components/Icon/styles.d.ts +1 -1
- package/dist/components/Image/styles.d.ts +1 -1
- package/dist/components/List/PaginationIndicator.d.ts +1 -1
- package/dist/components/List/styles.d.ts +1 -1
- package/dist/components/Modal/index.js +13 -8
- package/dist/components/Modal/index.js.map +1 -1
- package/dist/components/Modal/styles.d.ts +1 -1
- package/dist/components/Pager/styles.d.ts +1 -1
- package/dist/components/RadioInput/styles.d.ts +1 -1
- package/dist/components/Scroll/index.d.ts +1 -1
- package/dist/components/Scroll/styles.d.ts +1 -1
- package/dist/components/Sections/index.d.ts +1 -1
- package/dist/components/SegmentedControl/styles.d.ts +1 -1
- package/dist/components/Select/styles.d.ts +1 -1
- package/dist/components/Slider/styles.d.ts +1 -1
- package/dist/components/Switch/styles.d.ts +1 -1
- package/dist/components/Text/styles.d.ts +1 -1
- package/dist/components/TextInput/index.d.ts +2 -2
- package/dist/components/TextInput/styles.d.ts +1 -1
- package/dist/components/Touchable/styles.d.ts +1 -1
- package/dist/components/View/index.d.ts +2 -0
- package/dist/components/View/index.js +6 -1
- package/dist/components/View/index.js.map +1 -1
- package/dist/components/View/styles.d.ts +1 -1
- package/dist/components/defaultStyles.d.ts +27 -27
- package/dist/utils/hooks.d.ts +21 -2
- package/dist/utils/hooks.js +61 -2
- package/dist/utils/hooks.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Modal/index.tsx +17 -16
- package/src/components/View/index.tsx +3 -1
- package/src/utils/hooks.ts +110 -4
package/dist/utils/hooks.js
CHANGED
|
@@ -14,11 +14,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.useAsyncStorageState = exports.useBackButton = exports.usePressableFeedback = exports.useStaticAnimationStyles = exports.useAppState = exports.useAnimateColor = void 0;
|
|
17
|
+
exports.useAsyncStorageState = exports.useBackButton = exports.usePressableFeedback = exports.useAnimatedVariantStyles = exports.useStaticAnimationStyles = exports.useAppState = exports.useAnimateColor = void 0;
|
|
18
18
|
var common_1 = require("@codeleap/common");
|
|
19
19
|
var react_native_1 = require("react-native");
|
|
20
|
-
// @ts-ignore
|
|
21
20
|
var async_storage_1 = __importDefault(require("@react-native-community/async-storage"));
|
|
21
|
+
var react_native_reanimated_1 = require("react-native-reanimated");
|
|
22
22
|
function useAnimateColor(value, opts) {
|
|
23
23
|
var iters = (0, common_1.useRef)(0);
|
|
24
24
|
var anim = (0, common_1.useState)(new react_native_1.Animated.Value(iters.current))[0];
|
|
@@ -64,6 +64,65 @@ function useStaticAnimationStyles(obj, keys) {
|
|
|
64
64
|
return styles.current;
|
|
65
65
|
}
|
|
66
66
|
exports.useStaticAnimationStyles = useStaticAnimationStyles;
|
|
67
|
+
var buildAnimatedStyle = function (property, value, currentStyle, applyFN) {
|
|
68
|
+
'worklet';
|
|
69
|
+
var _a;
|
|
70
|
+
if (applyFN === void 0) { applyFN = function (v) { return v; }; }
|
|
71
|
+
var newStyle = __assign({}, currentStyle);
|
|
72
|
+
switch (property) {
|
|
73
|
+
case 'opacity':
|
|
74
|
+
newStyle.opacity = applyFN(value);
|
|
75
|
+
break;
|
|
76
|
+
default:
|
|
77
|
+
if (!newStyle.transform) {
|
|
78
|
+
newStyle.transform = [];
|
|
79
|
+
}
|
|
80
|
+
newStyle.transform.push((_a = {},
|
|
81
|
+
_a[property] = applyFN(value),
|
|
82
|
+
_a));
|
|
83
|
+
}
|
|
84
|
+
return newStyle;
|
|
85
|
+
};
|
|
86
|
+
var transformProperties = function (properties, transition) {
|
|
87
|
+
'worklet';
|
|
88
|
+
var styles = {};
|
|
89
|
+
var _loop_1 = function (prop, value) {
|
|
90
|
+
var transitionConfig = transition[prop] || transition;
|
|
91
|
+
var _transitionConfig = __assign({ type: 'timing', duration: 100, easing: react_native_reanimated_1.Easing.linear }, transitionConfig);
|
|
92
|
+
var type = _transitionConfig.type, duration = _transitionConfig.duration, easing = _transitionConfig.easing;
|
|
93
|
+
var fn = void 0;
|
|
94
|
+
switch (type) {
|
|
95
|
+
case 'timing':
|
|
96
|
+
fn = function (v) { return (0, react_native_reanimated_1.withTiming)(v, {
|
|
97
|
+
duration: duration,
|
|
98
|
+
easing: easing
|
|
99
|
+
}); };
|
|
100
|
+
default:
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
styles = buildAnimatedStyle(prop, value, styles, fn);
|
|
104
|
+
};
|
|
105
|
+
for (var _i = 0, _a = Object.entries(properties); _i < _a.length; _i++) {
|
|
106
|
+
var _b = _a[_i], prop = _b[0], value = _b[1];
|
|
107
|
+
_loop_1(prop, value);
|
|
108
|
+
}
|
|
109
|
+
return styles;
|
|
110
|
+
};
|
|
111
|
+
function useAnimatedVariantStyles(config) {
|
|
112
|
+
var animatedProperties = config.animatedProperties, updater = config.updater, variantStyles = config.variantStyles, transition = config.transition, _a = config.dependencies, dependencies = _a === void 0 ? [] : _a;
|
|
113
|
+
var _transition = (0, common_1.useRef)(null);
|
|
114
|
+
if (!_transition.current) {
|
|
115
|
+
_transition.current = JSON.parse(JSON.stringify(transition));
|
|
116
|
+
}
|
|
117
|
+
var staticStyles = useStaticAnimationStyles(variantStyles, animatedProperties);
|
|
118
|
+
var animated = (0, react_native_reanimated_1.useAnimatedStyle)(function () {
|
|
119
|
+
var nextState = updater(staticStyles);
|
|
120
|
+
var formatted = transformProperties(nextState, _transition.current);
|
|
121
|
+
return formatted;
|
|
122
|
+
}, [dependencies]);
|
|
123
|
+
return animated;
|
|
124
|
+
}
|
|
125
|
+
exports.useAnimatedVariantStyles = useAnimatedVariantStyles;
|
|
67
126
|
function usePressableFeedback(styles, config) {
|
|
68
127
|
var disabled = config.disabled, feedbackConfig = config.feedbackConfig, _a = config.hightlightPropertyIn, hightlightPropertyIn = _a === void 0 ? 'backgroundColor' : _a, _b = config.hightlightPropertyOut, hightlightPropertyOut = _b === void 0 ? 'backgroundColor' : _b;
|
|
69
128
|
var _feedbackConfig = __assign({}, feedbackConfig);
|
package/dist/utils/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../src/utils/hooks.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,2CAA2G;AAC3G,
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../src/utils/hooks.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,2CAA2G;AAC3G,6CAAoK;AAEpK,wFAAgE;AAChE,mEAA2G;AAE3G,SAAgB,eAAe,CAAC,KAAa,EAAE,IAA8C;IAC3F,IAAM,KAAK,GAAG,IAAA,eAAM,EAAC,CAAC,CAAC,CAAA;IAChB,IAAA,IAAI,GAAI,IAAA,iBAAQ,EAAC,IAAI,uBAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,GAA/C,CAA+C;IAC1D,IAAM,KAAK,GAAG,IAAA,oBAAW,EAAC,KAAK,CAAC,CAAA;IAChC,IAAM,IAAI,GAAG,KAAK,IAAI,KAAK,CAAA;IAE3B,I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CAAA;wBAChC,QAAQ,GAAG,EAAE,CAAC,KAAK,CAAC,CAAA;qBACrB;oBAED,IAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAA;oBAExC,uBAAY,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;oBAC9D,OAAO,EAAE,CAAA;oBACT,OAAO,QAAQ,CAAA;iBAChB;gBAAC,OAAO,CAAC,EAAE;oBACV,MAAM,CAAC,CAAC,CAAC,CAAA;oBACT,OAAO,QAAQ,CAAA;iBAChB;YAEH,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IAEJ,CAAC,CAAA;IAED,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAyB,CAAA;AAClD,CAAC;AA5CD,oDA4CC"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
|
-
import { View, ViewProps } from '../View'
|
|
3
|
-
import {
|
|
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
|
|
128
|
-
|
|
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
|
-
<
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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
|
-
</
|
|
216
|
+
</AnimatedView>
|
|
216
217
|
|
|
217
218
|
</ScrollComponent>
|
|
218
219
|
</View>
|
|
@@ -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
|
package/src/utils/hooks.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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}
|