File tree 5 files changed +57
-5
lines changed
5 files changed +57
-5
lines changed Original file line number Diff line number Diff line change
1
+ import { AnimatePresence , motion , MotionConfig } from "framer-motion"
2
+ import { useState } from "react"
3
+
4
+ export const App = ( ) => {
5
+ const [ state , setState ] = useState ( false )
6
+
7
+ return (
8
+ < MotionConfig transition = { { duration : 10 , ease : ( p ) => 0.25 } } >
9
+ < div style = { { display : "flex" , gap : 100 } } >
10
+ < motion . div
11
+ layoutId = "box"
12
+ style = { { width : 100 , height : 100 , background : "red" } }
13
+ />
14
+ < AnimatePresence >
15
+ { state && (
16
+ < motion . div
17
+ layoutId = "box"
18
+ layoutCrossfade = { false }
19
+ style = { {
20
+ width : 100 ,
21
+ height : 100 ,
22
+ background : "blue" ,
23
+ } }
24
+ />
25
+ ) }
26
+ </ AnimatePresence >
27
+ </ div >
28
+ < button onClick = { ( ) => setState ( ! state ) } > Toggle</ button >
29
+ </ MotionConfig >
30
+ )
31
+ }
Original file line number Diff line number Diff line change @@ -347,4 +347,16 @@ describe("Layout animation", () => {
347
347
expect ( $count . textContent ) . to . equal ( "1" )
348
348
} )
349
349
} )
350
+
351
+ it ( "Disabling crossfade works as expected" , ( ) => {
352
+ cy . visit ( "?test=layout-crossfade" )
353
+ . wait ( 50 )
354
+ . get ( "button" )
355
+ . trigger ( "click" )
356
+ . wait ( 200 )
357
+ . get ( "#box" )
358
+ . should ( ( [ $box ] : any ) => {
359
+ expect ( $box . style . opacity ) . to . equal ( "1" )
360
+ } )
361
+ } )
350
362
} )
Original file line number Diff line number Diff line change @@ -92,4 +92,12 @@ export interface LayoutProps {
92
92
* perform scale correction on it.
93
93
*/
94
94
"data-framer-portal-id" ?: string
95
+
96
+ /**
97
+ * By default, shared layout elements will crossfade. By setting this
98
+ * to `false`, this element will take its default opacity throughout the animation.
99
+ *
100
+ * @public
101
+ */
102
+ layoutCrossfade ?: boolean
95
103
}
Original file line number Diff line number Diff line change @@ -153,6 +153,7 @@ function createProjectionNode(
153
153
dragConstraints,
154
154
layoutScroll,
155
155
layoutRoot,
156
+ layoutCrossfade,
156
157
} = props
157
158
158
159
visualElement . projection = new ProjectionNodeConstructor (
@@ -177,6 +178,7 @@ function createProjectionNode(
177
178
*/
178
179
animationType : typeof layout === "string" ? layout : "both" ,
179
180
initialPromotionConfig,
181
+ crossfade : layoutCrossfade ,
180
182
layoutScroll,
181
183
layoutRoot,
182
184
} )
Original file line number Diff line number Diff line change @@ -25,19 +25,18 @@ export function mixValues(
25
25
if ( shouldCrossfadeOpacity ) {
26
26
target . opacity = mixNumber (
27
27
0 ,
28
- // TODO Reinstate this if only child
29
- lead . opacity !== undefined ? ( lead . opacity as number ) : 1 ,
28
+ ( lead . opacity as number ) ?? 1 ,
30
29
easeCrossfadeIn ( progress )
31
30
)
32
31
target . opacityExit = mixNumber (
33
- follow . opacity !== undefined ? ( follow . opacity as number ) : 1 ,
32
+ ( follow . opacity as number ) ?? 1 ,
34
33
0 ,
35
34
easeCrossfadeOut ( progress )
36
35
)
37
36
} else if ( isOnlyMember ) {
38
37
target . opacity = mixNumber (
39
- follow . opacity !== undefined ? ( follow . opacity as number ) : 1 ,
40
- lead . opacity !== undefined ? ( lead . opacity as number ) : 1 ,
38
+ ( follow . opacity as number ) ?? 1 ,
39
+ ( lead . opacity as number ) ?? 1 ,
41
40
progress
42
41
)
43
42
}
You can’t perform that action at this time.
0 commit comments