Skip to content

Commit

Permalink
ntp: adding support for view transitions
Browse files Browse the repository at this point in the history
  • Loading branch information
shakyShane committed Jan 17, 2025
1 parent 3a26c45 commit 7283d19
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,18 @@ export function FavoritesConsumer() {
if (state.status === 'ready') {
telemetry.measureFromPageLoad('favorites-will-render', 'time to favorites');
return (
<PragmaticDND items={state.data.favorites} itemsDidReOrder={favoritesDidReOrder}>
<PragmaticDND
items={state.data.favorites}
itemsDidReOrder={(params) => {
if (state.config.animation?.kind === 'view-transitions') {
document.startViewTransition(() => {
favoritesDidReOrder(params);
});
} else {
favoritesDidReOrder(params);
}
}}
>
<FavoritesMemo
favorites={state.data.favorites}
expansion={state.config.expansion}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ import { reducer, useConfigSubscription, useDataSubscription, useInitialDataAndC
* @typedef {import('../../../types/new-tab.ts').FavoritesOpenAction['target']} OpenTarget
* @typedef {import('../../service.hooks.js').State<FavoritesData, FavoritesConfig>} State
* @typedef {import('../../service.hooks.js').Events<FavoritesData, FavoritesConfig>} Events
* @typedef {{id: string; url: string}} BaseFavoriteType
*/

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const InstanceIdContext = createContext(getInstanceId());
* @param {object} props
* @param {import("preact").ComponentChild} props.children
* @param {T[]} props.items
* @param {import('./FavoritesProvider.js').ReorderFn<{id: string; url: string}>} props.itemsDidReOrder
* @param {(params: {list: T[]; id: string; fromIndex: number; targetIndex: number}) => void} props.itemsDidReOrder
*/
export function PragmaticDND({ children, items, itemsDidReOrder }) {
/**
Expand Down Expand Up @@ -133,13 +133,6 @@ function useGridState(favorites, itemsDidReOrder, instanceId) {
axis: 'horizontal',
});

// mark an element as dropped globally.
// todo: not happy with this, but it's working for launch.
document.documentElement.dataset.dropped = String(startId);
setTimeout(() => {
document.documentElement.dataset.dropped = '';
}, 0);

itemsDidReOrder({
list: reorderedList,
id: startId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export function Tile_({ url, etldPlusOne, faviconSrc, faviconMax, index, title,
data-index={index}
data-dropped={String(dropped)}
data-edge={'closestEdge' in state && state.closestEdge}
style={{ viewTransitionName: `tile-${id}` }}
ref={ref}
>
<div class={cn(styles.icon, styles.draggable)}>
Expand Down
2 changes: 1 addition & 1 deletion special-pages/pages/new-tab/app/mock-transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ export function mockTransport() {
/** @type {FavoritesConfig} */
const defaultConfig = { expansion: 'collapsed', animation: { kind: 'none' } };
const fromStorage = read('favorites_config') || defaultConfig;
if (url.searchParams.get('animation') === 'view-transitions') {
if (url.searchParams.get('favorites.animation') === 'view-transitions') {
fromStorage.animation = { kind: 'view-transitions' };
}
return Promise.resolve(fromStorage);
Expand Down
11 changes: 0 additions & 11 deletions special-pages/pages/new-tab/messages/types/animation.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,6 @@
"const": "view-transitions"
}
}
},
{
"title": "Auto",
"description": "Use the auto-animate library to provide default animation styles",
"type": "object",
"required": ["kind"],
"properties": {
"kind": {
"const": "auto-animate"
}
}
}
]
}
8 changes: 1 addition & 7 deletions special-pages/pages/new-tab/types/new-tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export type Expansion = "expanded" | "collapsed";
/**
* Generic Animation configuration
*/
export type Animation = None | ViewTransitions | Auto;
export type Animation = None | ViewTransitions;
/**
* The visibility state of the widget, as configured by the user
*/
Expand Down Expand Up @@ -307,12 +307,6 @@ export interface None {
export interface ViewTransitions {
kind: "view-transitions";
}
/**
* Use the auto-animate library to provide default animation styles
*/
export interface Auto {
kind: "auto-animate";
}
/**
* Generated from @see "../messages/freemiumPIRBanner_action.notify.json"
*/
Expand Down

0 comments on commit 7283d19

Please sign in to comment.