MCPcopy Create free account
hub / github.com/adobe/react-spectrum / startViewTransition

Function startViewTransition

packages/@react-spectrum/s2/src/Toast.tsx:84–101  ·  view source on GitHub ↗
(fn: () => void, type: string)

Source from the content-addressed store, hash-verified

82
83let globalReduceMotion = false;
84function startViewTransition(fn: () => void, type: string) {
85 if ('startViewTransition' in document) {
86 // Safari doesn't support :active-view-transition-type() yet, so we fall back to a class on the html element.
87 document.documentElement.classList.add(toastCss[type]);
88 if (globalReduceMotion) {
89 document.documentElement.classList.add(toastCss.reduceMotion);
90 }
91
92 let viewTransition = document.startViewTransition(() => flushSync(fn));
93
94 viewTransition.ready.catch(() => {});
95 viewTransition.finished.then(() => {
96 document.documentElement.classList.remove(toastCss[type], toastCss.reduceMotion);
97 });
98 } else {
99 fn();
100 }
101}
102
103// There is a single global toast queue instance for the whole app, initialized lazily.
104let globalToastQueue: ToastQueue<SpectrumToastValue> | null = null;

Callers 2

wrapUpdateFunction · 0.85
toggleExpandedFunction · 0.85

Calls 4

fnFunction · 0.85
startViewTransitionMethod · 0.80
addMethod · 0.65
removeMethod · 0.65

Tested by

no test coverage detected