Skip to content

Commit 48bf50f

Browse files
committed
ntp: adding support for view transitions
1 parent abb8c48 commit 48bf50f

File tree

7 files changed

+17
-30
lines changed

7 files changed

+17
-30
lines changed

special-pages/pages/new-tab/app/favorites/components/FavoritesCustomized.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,18 @@ export function FavoritesConsumer() {
1919
if (state.status === 'ready') {
2020
telemetry.measureFromPageLoad('favorites-will-render', 'time to favorites');
2121
return (
22-
<PragmaticDND items={state.data.favorites} itemsDidReOrder={favoritesDidReOrder}>
22+
<PragmaticDND
23+
items={state.data.favorites}
24+
itemsDidReOrder={(params) => {
25+
if (state.config.animation?.kind === 'view-transitions') {
26+
document.startViewTransition(() => {
27+
favoritesDidReOrder(params);
28+
});
29+
} else {
30+
favoritesDidReOrder(params);
31+
}
32+
}}
33+
>
2334
<FavoritesMemo
2435
favorites={state.data.favorites}
2536
expansion={state.config.expansion}

special-pages/pages/new-tab/app/favorites/components/FavoritesProvider.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ import { reducer, useConfigSubscription, useDataSubscription, useInitialDataAndC
1212
* @typedef {import('../../../types/new-tab.ts').FavoritesOpenAction['target']} OpenTarget
1313
* @typedef {import('../../service.hooks.js').State<FavoritesData, FavoritesConfig>} State
1414
* @typedef {import('../../service.hooks.js').Events<FavoritesData, FavoritesConfig>} Events
15-
* @typedef {{id: string; url: string}} BaseFavoriteType
1615
*/
1716

1817
/**
19-
* @template {BaseFavoriteType} ItemType - allow any type that extends BaseFavoriteType
18+
* @template ItemType
2019
* @typedef {(params: { list: ItemType[], id: string, fromIndex: number, targetIndex: number }) => void} ReorderFn
2120
*/
2221

special-pages/pages/new-tab/app/favorites/components/PragmaticDND.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const InstanceIdContext = createContext(getInstanceId());
2525
* @param {object} props
2626
* @param {import("preact").ComponentChild} props.children
2727
* @param {T[]} props.items
28-
* @param {import('./FavoritesProvider.js').ReorderFn<{id: string; url: string}>} props.itemsDidReOrder
28+
* @param {(params: {list: T[]; id: string; fromIndex: number; targetIndex: number}) => void} props.itemsDidReOrder
2929
*/
3030
export function PragmaticDND({ children, items, itemsDidReOrder }) {
3131
/**
@@ -133,13 +133,6 @@ function useGridState(favorites, itemsDidReOrder, instanceId) {
133133
axis: 'horizontal',
134134
});
135135

136-
// mark an element as dropped globally.
137-
// todo: not happy with this, but it's working for launch.
138-
document.documentElement.dataset.dropped = String(startId);
139-
setTimeout(() => {
140-
document.documentElement.dataset.dropped = '';
141-
}, 0);
142-
143136
itemsDidReOrder({
144137
list: reorderedList,
145138
id: startId,

special-pages/pages/new-tab/app/favorites/components/Tile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export function Tile_({ url, etldPlusOne, faviconSrc, faviconMax, index, title,
4646
data-index={index}
4747
data-dropped={String(dropped)}
4848
data-edge={'closestEdge' in state && state.closestEdge}
49+
style={{ viewTransitionName: `tile-${id}` }}
4950
ref={ref}
5051
>
5152
<div class={cn(styles.icon, styles.draggable)}>

special-pages/pages/new-tab/app/mock-transport.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ export function mockTransport() {
466466
/** @type {FavoritesConfig} */
467467
const defaultConfig = { expansion: 'collapsed', animation: { kind: 'none' } };
468468
const fromStorage = read('favorites_config') || defaultConfig;
469-
if (url.searchParams.get('animation') === 'view-transitions') {
469+
if (url.searchParams.get('favorites.animation') === 'view-transitions') {
470470
fromStorage.animation = { kind: 'view-transitions' };
471471
}
472472
return Promise.resolve(fromStorage);

special-pages/pages/new-tab/messages/types/animation.json

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,6 @@
2323
"const": "view-transitions"
2424
}
2525
}
26-
},
27-
{
28-
"title": "Auto",
29-
"description": "Use the auto-animate library to provide default animation styles",
30-
"type": "object",
31-
"required": ["kind"],
32-
"properties": {
33-
"kind": {
34-
"const": "auto-animate"
35-
}
36-
}
3726
}
3827
]
3928
}

special-pages/pages/new-tab/types/new-tab.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export type Expansion = "expanded" | "collapsed";
5353
/**
5454
* Generic Animation configuration
5555
*/
56-
export type Animation = None | ViewTransitions | Auto;
56+
export type Animation = None | ViewTransitions;
5757
/**
5858
* The visibility state of the widget, as configured by the user
5959
*/
@@ -307,12 +307,6 @@ export interface None {
307307
export interface ViewTransitions {
308308
kind: "view-transitions";
309309
}
310-
/**
311-
* Use the auto-animate library to provide default animation styles
312-
*/
313-
export interface Auto {
314-
kind: "auto-animate";
315-
}
316310
/**
317311
* Generated from @see "../messages/freemiumPIRBanner_action.notify.json"
318312
*/

0 commit comments

Comments
 (0)