Skip to content

Commit 818fe14

Browse files
committed
feat(web): added fade support
1 parent bf6e590 commit 818fe14

File tree

1 file changed

+37
-10
lines changed

1 file changed

+37
-10
lines changed

src/web/RNSharedElementTransition.ts

+37-10
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ export class RNSharedElementTransition {
100100
const {
101101
element,
102102
items,
103-
nodePosition /*, animation, resize, align*/
103+
nodePosition,
104+
animation /*, animation, resize, align*/
104105
} = this;
105106
if (!element) return;
106107

@@ -170,14 +171,38 @@ export class RNSharedElementTransition {
170171
// interpolatedClipInsets = endClipInsets;
171172
}
172173

173-
this.updateView(
174-
0,
175-
interpolatedLayout,
176-
interpolatedStyle,
177-
interpolatedContentLayout,
178-
startLayout,
179-
startContent
180-
);
174+
if (
175+
animation === RNSharedElementAnimation.Move ||
176+
animation === RNSharedElementAnimation.Fade ||
177+
animation === RNSharedElementAnimation.FadeOut
178+
) {
179+
const startOpacity =
180+
animation === RNSharedElementAnimation.Move ? 1 : 1 - nodePosition;
181+
this.updateView(
182+
0,
183+
interpolatedLayout,
184+
interpolatedStyle,
185+
interpolatedContentLayout,
186+
startLayout,
187+
startContent,
188+
startOpacity
189+
);
190+
}
191+
if (
192+
animation === RNSharedElementAnimation.Fade ||
193+
animation === RNSharedElementAnimation.FadeIn
194+
) {
195+
const endOpacity = nodePosition;
196+
this.updateView(
197+
1,
198+
interpolatedLayout,
199+
interpolatedStyle,
200+
interpolatedContentLayout,
201+
endLayout,
202+
endContent,
203+
endOpacity
204+
);
205+
}
181206
}
182207

183208
private updateView(
@@ -188,7 +213,8 @@ export class RNSharedElementTransition {
188213
interpolatedContentLayout: Rect,
189214
// @ts-ignore
190215
originalLayout: Rect,
191-
content: RNSharedElementContent | null
216+
content: RNSharedElementContent | null,
217+
opacity: number
192218
) {
193219
// Find / create view
194220
let view = this.views[index];
@@ -208,5 +234,6 @@ export class RNSharedElementTransition {
208234
if (!content || !content.element) return;
209235
view.contentElement = (content.element as any).cloneNode(true);
210236
}
237+
(view.contentElement as any).style.opacity = opacity;
211238
}
212239
}

0 commit comments

Comments
 (0)