Skip to content

Commit be7d9ae

Browse files
committed
Fixed shared element layout shift bug
1 parent 6ab60e6 commit be7d9ae

File tree

6 files changed

+34
-13
lines changed

6 files changed

+34
-13
lines changed

example/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function App() {
1616
page_load_transition: false,
1717
animation: {
1818
type: "zoom",
19-
duration: 200,
19+
duration: 300,
2020
}
2121
}}>
2222
<Stack.Screen

example/src/Components/Tile.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ export default class Tile extends React.Component<TileProps> {
1010
render() {
1111
return (
1212
<div onClick={this.props.onClick} className="tile">
13-
<SharedElement id={this.props.hero.id}>
13+
<SharedElement id={this.props.hero.id} config={{
14+
duration: 200
15+
}}>
1416
<img src={this.props.hero.photo} alt={this.props.hero.name} />
1517
</SharedElement>
1618
</div>

example/src/Screens/Details.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default function Details(props: DetailsProps) {
2828
easing_function: 'cubic-bezier(0.175, 0.885, 0.32, 1.275)'
2929
},
3030
y: {
31-
duration: 200,
31+
duration: 250,
3232
easing_function: 'ease-out'
3333
}
3434
}} id={props.route.params.profile.id}>

src/GhostLayer.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,14 @@ export default class GhostLayer extends React.Component<GhostLayerProps, GhostLa
4646
const start_instance = current_scene.nodes[id].instance;
4747
start_instance.hidden = true;
4848
end_instance.hidden = true;
49+
50+
4951
const start_node = current_scene.nodes[id].node;
5052
const end_node = next_scene.nodes[id].node;
5153

54+
start_node.style.display = 'unset';
55+
end_node.style.display = 'unset';
56+
5257
const x_duration: number = end_instance.props.config?.x?.duration || end_instance.props.config?.duration || this.props.animation.duration;
5358
const y_duration: number = end_instance.props.config?.y?.duration || end_instance.props.config?.duration || this.props.animation.duration;
5459

src/SharedElement.tsx

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,18 @@ namespace SharedElement {
3939
"ease-out"
4040
}
4141

42+
enum TransitionAnimationEnum {
43+
"move",
44+
"fade-in",
45+
"fade-out",
46+
"cross-fade"
47+
}
48+
49+
type TransitionAnimation = keyof typeof TransitionAnimationEnum;
50+
4251
type EasingFunctionKeyword = keyof typeof EasingFunctionKeywordEnum;
4352

44-
type EasingFunction = EasingFunctionKeyword | `cubic-bezier(${number}, ${number}, ${number}, ${number})`;
53+
type EasingFunction = EasingFunctionKeyword | string;
4554

4655
type TransformOriginGlobal = keyof typeof TransformOriginGlobalEnum;
4756

@@ -58,16 +67,17 @@ namespace SharedElement {
5867

5968
interface SharedElementConfig {
6069
transform_origin?: TransformOrigin;
61-
easing_function?: EasingFunction,
62-
duration?: number,
70+
easing_function?: EasingFunction;
71+
duration?: number;
72+
animation?: TransitionAnimation;
6373
x?: {
6474
duration?: number;
6575
easing_function?: EasingFunction
66-
}
76+
};
6777
y?: {
6878
duration?: number;
6979
easing_function?: EasingFunction
70-
}
80+
};
7181
}
7282

7383

@@ -254,7 +264,15 @@ namespace SharedElement {
254264
{(scene) => {
255265
this._scene = scene;
256266
return (
257-
<div ref={this.set_ref.bind(this)} id={`shared-element-${this._id}`} className={"shared-element"} style={{opacity: this._hidden ? '0': '1'}}>
267+
<div
268+
ref={this.set_ref.bind(this)}
269+
id={`shared-element-${this._id}`}
270+
className={"shared-element"}
271+
style={{
272+
display: this._hidden ? 'block' : 'contents',
273+
opacity: this._hidden ? '0': '1'
274+
}
275+
}>
258276
{this.props.children}
259277
</div>
260278
);

src/css/Transition.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,6 @@ html, body {
109109
.screen-content {
110110
overflow: scroll;
111111
}
112-
.shared-element {
113-
width: 100%;
114-
height: 100%;
115-
}
116112
#ghost-layer {
117113
position: absolute;
118114
z-index: 100000;

0 commit comments

Comments
 (0)