@@ -59,33 +59,6 @@ const EASING_PRESETS: Record<string, CubicBezier> = {
5959 easeInOut : [ 0.42 , 0 , 0.58 , 1 ] ,
6060} ;
6161
62- /** Transition struct field names (matches NativeTransitions keys). */
63- const TRANSITION_KEYS = [
64- 'opacity' ,
65- 'translateX' ,
66- 'translateY' ,
67- 'scaleX' ,
68- 'scaleY' ,
69- 'rotate' ,
70- 'rotateX' ,
71- 'rotateY' ,
72- 'borderRadius' ,
73- 'backgroundColor' ,
74- ] as const ;
75-
76- type TransitionKey = ( typeof TRANSITION_KEYS ) [ number ] ;
77-
78- /** Transform property keys (indices 1-7) get spring defaults; others get timing. */
79- const TRANSFORM_KEYS = new Set < TransitionKey > ( [
80- 'translateX' ,
81- 'translateY' ,
82- 'scaleX' ,
83- 'scaleY' ,
84- 'rotate' ,
85- 'rotateX' ,
86- 'rotateY' ,
87- ] ) ;
88-
8962/** Returns true if the transition is a SingleTransition (has a `type` field). */
9063function isSingleTransition ( t : Transition ) : t is SingleTransition {
9164 return 'type' in t ;
@@ -106,20 +79,14 @@ type NativeTransitionConfig = {
10679/** Full transitions struct passed to native. */
10780type NativeTransitions = {
10881 defaultConfig : NativeTransitionConfig ;
109- opacity : NativeTransitionConfig ;
110- translateX : NativeTransitionConfig ;
111- translateY : NativeTransitionConfig ;
112- scaleX : NativeTransitionConfig ;
113- scaleY : NativeTransitionConfig ;
114- rotate : NativeTransitionConfig ;
115- rotateX : NativeTransitionConfig ;
116- rotateY : NativeTransitionConfig ;
117- borderRadius : NativeTransitionConfig ;
118- backgroundColor : NativeTransitionConfig ;
82+ transform ?: NativeTransitionConfig ;
83+ opacity ?: NativeTransitionConfig ;
84+ borderRadius ?: NativeTransitionConfig ;
85+ backgroundColor ?: NativeTransitionConfig ;
11986} ;
12087
121- /** Library defaults: spring for transforms, timing 300ms easeInOut for others . */
122- const TIMING_DEFAULT_CONFIG : NativeTransitionConfig = {
88+ /** Default config: timing 300ms easeInOut. */
89+ const DEFAULT_CONFIG : NativeTransitionConfig = {
12390 type : 'timing' ,
12491 duration : 300 ,
12592 easingBezier : [ 0.42 , 0 , 0.58 , 1 ] ,
@@ -130,6 +97,7 @@ const TIMING_DEFAULT_CONFIG: NativeTransitionConfig = {
13097 delay : 0 ,
13198} ;
13299
100+ /** Default config for transform properties: spring. */
133101const SPRING_DEFAULT_CONFIG : NativeTransitionConfig = {
134102 type : 'spring' ,
135103 duration : 300 ,
@@ -141,12 +109,6 @@ const SPRING_DEFAULT_CONFIG: NativeTransitionConfig = {
141109 delay : 0 ,
142110} ;
143111
144- function getLibraryDefault ( key : TransitionKey ) : NativeTransitionConfig {
145- return TRANSFORM_KEYS . has ( key )
146- ? SPRING_DEFAULT_CONFIG
147- : TIMING_DEFAULT_CONFIG ;
148- }
149-
150112/** Resolve a SingleTransition into a native config object. */
151113function resolveSingleConfig ( config : SingleTransition ) : NativeTransitionConfig {
152114 const type = config . type as string ;
@@ -198,63 +160,47 @@ function resolveSingleConfig(config: SingleTransition): NativeTransitionConfig {
198160 } ;
199161}
200162
201- /** Resolve the transition prop into a fully-populated NativeTransitions struct. */
163+ /** Category keys that map to optional NativeTransitions fields. */
164+ const CATEGORY_KEYS = [
165+ 'transform' ,
166+ 'opacity' ,
167+ 'borderRadius' ,
168+ 'backgroundColor' ,
169+ ] as const ;
170+
171+ /** Resolve the transition prop into a NativeTransitions struct. */
202172function resolveTransitions ( transition ?: Transition ) : NativeTransitions {
203- // Single transition: apply the same config to all 11 slots
173+ // Single transition: set as defaultConfig, no category overrides needed
204174 if ( transition != null && isSingleTransition ( transition ) ) {
205- const config = resolveSingleConfig ( transition ) ;
206- const result = { defaultConfig : config } as Record <
207- string ,
208- NativeTransitionConfig
209- > ;
210- for ( const key of TRANSITION_KEYS ) {
211- result [ key ] = config ;
212- }
213- return result as unknown as NativeTransitions ;
175+ return { defaultConfig : resolveSingleConfig ( transition ) } ;
214176 }
215177
216- // No transition: use library defaults per category
178+ // No transition: timing default + spring for transforms
217179 if ( transition == null ) {
218- const result = { defaultConfig : TIMING_DEFAULT_CONFIG } as Record <
219- string ,
220- NativeTransitionConfig
221- > ;
222- for ( const key of TRANSITION_KEYS ) {
223- result [ key ] = getLibraryDefault ( key ) ;
224- }
225- return result as unknown as NativeTransitions ;
180+ return { defaultConfig : DEFAULT_CONFIG , transform : SPRING_DEFAULT_CONFIG } ;
226181 }
227182
228- // TransitionMap: resolve per property
229- const transitionMap = transition ;
230- const defaultSingle = transitionMap . default ;
231- const defaultNative = defaultSingle
232- ? resolveSingleConfig ( defaultSingle )
233- : undefined ;
183+ // TransitionMap: resolve defaultConfig + only specified category keys
184+ const defaultConfig = transition . default
185+ ? resolveSingleConfig ( transition . default )
186+ : DEFAULT_CONFIG ;
234187
235- const result = {
236- defaultConfig : defaultNative ?? TIMING_DEFAULT_CONFIG ,
237- } as Record < string , NativeTransitionConfig > ;
188+ const result : NativeTransitions = { defaultConfig } ;
238189
239- for ( const key of TRANSITION_KEYS ) {
240- const specific = transitionMap [ key as keyof typeof transitionMap ] as
241- | SingleTransition
242- | undefined ;
190+ for ( const key of CATEGORY_KEYS ) {
191+ const specific = transition [ key ] ;
243192 if ( specific != null ) {
244- result [ key ] = resolveSingleConfig ( specific ) ;
245- } else if (
246- ( key === 'scaleX' || key === 'scaleY' ) &&
247- transitionMap . scale != null
248- ) {
249- result [ key ] = resolveSingleConfig ( transitionMap . scale ! ) ;
250- } else if ( defaultNative ) {
251- result [ key ] = defaultNative ;
252- } else {
253- result [ key ] = getLibraryDefault ( key ) ;
193+ ( result as Record < string , NativeTransitionConfig > ) [ key ] =
194+ resolveSingleConfig ( specific ) ;
254195 }
255196 }
256197
257- return result as unknown as NativeTransitions ;
198+ // Preserve spring default for transforms when not explicitly set
199+ if ( result . transform == null && transition . default == null ) {
200+ result . transform = SPRING_DEFAULT_CONFIG ;
201+ }
202+
203+ return result ;
258204}
259205
260206export type EaseViewProps = ViewProps & {
0 commit comments