Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions apps/mobile/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ const config: ExpoConfig = {
[
'expo-splash-screen',
{
backgroundColor: '#FFFFFF',
image: './assets/images/icon.png',
backgroundColor: '#5521FF',
image: './assets/images/splash-logo.png',
imageWidth: 120,
dark: {
backgroundColor: '#15121D',
image: './assets/images/icon.png',
backgroundColor: '#5521FF',
image: './assets/images/splash-logo.png',
},
},
],
Expand Down
Binary file added apps/mobile/assets/images/splash-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions apps/mobile/src/components/pixel-dismiss.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { rippleDelay } from '@/components/pixel-dismiss';

describe('rippleDelay', () => {
it('starts at the centre and grows with the distance from it', () => {
const delays = Array.from({ length: 4 }, (_, row) =>
Array.from({ length: 4 }, (_, column) => rippleDelay(row, column, 4, 4, 300)),
);
expect(delays).toEqual([
[225, 168, 168, 225],
[168, 75, 75, 168],
[168, 75, 75, 168],
[225, 168, 168, 225],
]);
});
});
71 changes: 71 additions & 0 deletions apps/mobile/src/components/pixel-dismiss.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { useMemo } from 'react';
import { StyleSheet, useWindowDimensions, View } from 'react-native';
import { EaseView } from 'react-native-ease';

const COLUMNS = 10;
/** Neighbouring pixels overlap so no hairline of the content shows between them before they move. */
const OVERLAP = 1;
const PIXEL_MS = 160;
const SPREAD_MS = 300;
const VANISHED = { scale: 0, rotate: 45 };
const COVERING = { scale: 1, rotate: 0 };

/** Longest time from `dismissed` until the last pixel is gone, not counting `delay`. */
export const PIXEL_DISMISS_MS = SPREAD_MS + PIXEL_MS;

/**
* Delay before the pixel at `row`, `column` starts to vanish. It grows with the distance from the centre of the grid
* to the pixel's centre, scaled so the grid's outer corners would be at `spreadMs`.
*/
export function rippleDelay(row: number, column: number, rows: number, columns: number, spreadMs: number) {
const distance = Math.hypot(column + 0.5 - columns / 2, row + 0.5 - rows / 2);
const maxDistance = Math.hypot(columns / 2, rows / 2);
return Math.round((distance / maxDistance) * spreadMs);
}

/**
* Covers the screen with square pixels of `color`. When `dismissed` turns true, the pixels shrink and turn away,
* rippling outward from the centre after `delay` ms. Each pixel is an `EaseView`, so the whole ripple runs on native
* animations from a single render.
*/
export function PixelDismiss({ color, dismissed, delay }: { color: string; dismissed: boolean; delay: number }) {
const { width, height } = useWindowDimensions();
const grid = useMemo(() => pixelGrid(width, height), [width, height]);

return (
<View style={styles.center}>
<View style={{ width, height: grid.height }}>
{grid.pixels.map(({ key, left, top, rippleMs }) => (
<EaseView
key={key}
style={[styles.pixel, { left, top, width: grid.pixelSize, height: grid.pixelSize, backgroundColor: color }]}
animate={dismissed ? VANISHED : COVERING}
transition={{ type: 'timing', duration: PIXEL_MS, delay: delay + rippleMs, easing: 'easeOut' }}
/>
))}
</View>
</View>
);
}

function pixelGrid(width: number, height: number) {
const size = width / COLUMNS;
const rows = 2 * Math.ceil(height / 2 / size);
const pixels = [];
for (let row = 0; row < rows; row++) {
for (let column = 0; column < COLUMNS; column++) {
pixels.push({
key: `${row}:${column}`,
left: column * size,
top: row * size,
rippleMs: rippleDelay(row, column, rows, COLUMNS, SPREAD_MS),
});
}
}
return { pixelSize: size + OVERLAP, height: rows * size, pixels };
}

const styles = StyleSheet.create({
center: { ...StyleSheet.absoluteFill, alignItems: 'center', justifyContent: 'center' },
pixel: { position: 'absolute' },
});
162 changes: 41 additions & 121 deletions apps/mobile/src/components/splash-overlay.tsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,26 @@
import { Image } from 'expo-image';
import * as SplashScreen from 'expo-splash-screen';
import { useEffect, useMemo, useState, type ReactNode } from 'react';
import { Appearance, StyleSheet, useWindowDimensions, View } from 'react-native';
import { useEffect, useState, type ReactNode } from 'react';
import { View } from 'react-native';
import { EaseView } from 'react-native-ease';
import { useReducedMotion } from 'react-native-reanimated';
import { StyleSheet } from 'react-native-unistyles';

import { PIXEL_DISMISS_MS, PixelDismiss } from '@/components/pixel-dismiss';
import { colors } from '@/design/tokens';

const ICON = require('@/assets/images/icon.png');
const LOGO = require('@/assets/images/splash-logo.png');

/** `imageWidth` of the `expo-splash-screen` config in app.config.ts. */
const ICON_SIZE = 120;
/**
* icon.png draws a 96 pt purple square with a 22 pt radius. The flood starts 1 pt inside it so the icon hides it
* completely on the first frame.
*/
const FLOOD_SIZE = 94;
const FLOOD_RADIUS = 21;
/**
* icon.png's white letter circle is 66 pt wide. Android clips without anti-aliasing, so the clip keeps a purple margin
* and its edge falls on purple.
*/
const LETTERS_CLIP = 72;
const COLUMNS = 10;
/** `backgroundColor` and `imageWidth` of the `expo-splash-screen` config in app.config.ts. */
const SPLASH_COLOR = colors.light.brand;
const LOGO_SIZE = 120;

const FLOOD_MS = 350;
/** Core Animation replaces a 0 duration with its 0.25 s default. */
const CUT_MS = 1;
const RIPPLE_DELAY_MS = 100;
const RIPPLE_SPREAD_MS = 300;
const PIXEL_MS = 160;
const RIPPLE_END_MS = FLOOD_MS + RIPPLE_DELAY_MS + RIPPLE_SPREAD_MS + PIXEL_MS;
const POP_MS = 90;
const SHRINK_MS = 130;
const SETTLE_DELAY_MS = FLOOD_MS + 50;
const SETTLE_MS = 600;
const LOGO_POP_SCALE = 1.2;
const LOGO_POP_MS = 90;
const LOGO_SHRINK_MS = 130;
const PIXELS_DELAY_MS = 100;
const APP_START_SCALE = 0.98;
const APP_SETTLE_MS = 600;
const CROSSFADE_MS = 250;
/** The native animations start once this render reaches the UI thread, after the unmount timer starts. */
const UNMOUNT_SLACK_MS = 50;
Expand All @@ -44,17 +30,14 @@ let played = false;

/**
* Wraps the app, draws the native splash over it, and hides the native splash once this frame is on screen. Then it
* plays the dismiss once per app process: the icon's purple square floods the screen, the letters pop and shrink, and
* the purple breaks into pixels that vanish outward from the logo while the app settles into place. Reduce Motion gets
* a crossfade.
* plays the dismiss once per app process: the logo pops and shrinks, and the purple breaks into pixels that vanish
* outward from it while the app settles into place. Reduce Motion gets a crossfade.
*/
export function SplashOverlay({ children }: { children: ReactNode }) {
const [visible, setVisible] = useState(!played);
const [scheme] = useState<'light' | 'dark'>(() => (Appearance.getColorScheme() === 'dark' ? 'dark' : 'light'));
const reduceMotion = useReducedMotion();
const [displayed, setDisplayed] = useState(false);
const [replayed] = useState(played);
const { width, height } = useWindowDimensions();
const reduceMotion = useReducedMotion();

useEffect(() => {
if (!visible) return;
Expand All @@ -66,127 +49,64 @@ export function SplashOverlay({ children }: { children: ReactNode }) {
SplashScreen.hide();
const timeout = setTimeout(
() => setVisible(false),
(reduceMotion ? CROSSFADE_MS : RIPPLE_END_MS) + UNMOUNT_SLACK_MS,
(reduceMotion ? CROSSFADE_MS : PIXELS_DELAY_MS + PIXEL_DISMISS_MS) + UNMOUNT_SLACK_MS,
);
return () => clearTimeout(timeout);
}, [visible, displayed, reduceMotion]);

const started = replayed || displayed;
const grid = useMemo(() => pixelGrid(width, height), [width, height]);
const ripple = started && !reduceMotion;
const floodScale = (Math.max(width, height) + 4 * grid.size) / FLOOD_SIZE;
const dismissed = started && !reduceMotion;

return (
<>
<View style={styles.backdrop}>
<EaseView
style={styles.app}
animate={{ scale: started ? 1 : 0.98 }}
animate={{ scale: started ? 1 : APP_START_SCALE }}
transition={
reduceMotion
? { type: 'none' }
: { type: 'timing', duration: SETTLE_MS, delay: SETTLE_DELAY_MS, easing: 'easeOut' }
: { type: 'timing', duration: APP_SETTLE_MS, delay: PIXELS_DELAY_MS, easing: 'easeOut' }
}
>
{children}
</EaseView>
{visible && (
<EaseView
style={[StyleSheet.absoluteFill, styles.center]}
style={styles.overlay}
animate={{ opacity: started && reduceMotion ? 0 : 1 }}
transition={{ type: 'timing', duration: CROSSFADE_MS, easing: 'easeInOut' }}
useHardwareLayer
pointerEvents="none"
testID="splash-overlay"
>
{!reduceMotion && (
<View style={[styles.grid, { width: grid.width, height: grid.height }]}>
{grid.cells.map((cell) => (
<EaseView
key={cell.key}
style={[
styles.pixel,
{ left: cell.left, top: cell.top, width: grid.size + 1, height: grid.size + 1 },
]}
animate={ripple ? { scale: 0, rotate: 45 } : { scale: 1, rotate: 0 }}
transition={{ type: 'timing', duration: PIXEL_MS, delay: cell.delay, easing: 'easeOut' }}
/>
))}
</View>
{reduceMotion ? (
<View style={styles.fill} />
) : (
<PixelDismiss color={SPLASH_COLOR} dismissed={dismissed} delay={PIXELS_DELAY_MS} />
)}
<EaseView
style={[StyleSheet.absoluteFill, { backgroundColor: colors[scheme].background }]}
animate={{ opacity: ripple ? 0 : 1 }}
transition={{ type: 'timing', duration: CUT_MS, delay: FLOOD_MS - 20 }}
/>
<EaseView
style={styles.flood}
animate={
ripple
? { opacity: 0, scale: floodScale, borderRadius: 2 }
: { opacity: 1, scale: 1, borderRadius: FLOOD_RADIUS }
}
transition={{
default: { type: 'timing', duration: FLOOD_MS, easing: [0.7, 0, 0.3, 1] },
opacity: { type: 'timing', duration: CUT_MS, delay: FLOOD_MS },
}}
/>
<EaseView
style={styles.icon}
animate={{ opacity: ripple ? 0 : 1 }}
transition={{ type: 'timing', duration: CUT_MS, delay: FLOOD_MS - 20 }}
>
<Image source={ICON} style={styles.icon} onDisplay={() => setDisplayed(true)} />
</EaseView>
<EaseView
style={styles.letters}
animate={{ scale: ripple ? 1.2 : 1 }}
transition={{ type: 'timing', duration: POP_MS, delay: FLOOD_MS, easing: 'easeOut' }}
style={styles.logo}
animate={{ scale: dismissed ? LOGO_POP_SCALE : 1 }}
transition={{ type: 'timing', duration: LOGO_POP_MS, easing: 'easeOut' }}
>
<EaseView
style={styles.lettersClip}
animate={{ scale: ripple ? 0 : 1 }}
transition={{ type: 'timing', duration: SHRINK_MS, delay: FLOOD_MS + POP_MS, easing: 'easeIn' }}
style={styles.logo}
animate={{ scale: dismissed ? 0 : 1 }}
transition={{ type: 'timing', duration: LOGO_SHRINK_MS, delay: LOGO_POP_MS, easing: 'easeIn' }}
>
<Image source={ICON} style={styles.lettersIcon} />
<Image source={LOGO} style={styles.logo} onDisplay={() => setDisplayed(true)} />
</EaseView>
</EaseView>
</EaseView>
)}
</>
</View>
);
}

function pixelGrid(width: number, height: number) {
const size = width / COLUMNS;
const rows = (Math.ceil(height / 2 / size) + 1) * 2;
const gridHeight = rows * size;
const maxDistance = Math.hypot(width / 2, gridHeight / 2);
const cells = [];
for (let row = 0; row < rows; row++) {
for (let column = 0; column < COLUMNS; column++) {
const left = column * size;
const top = row * size;
const distance = Math.hypot(left + size / 2 - width / 2, top + size / 2 - gridHeight / 2);
const delay = Math.round(FLOOD_MS + RIPPLE_DELAY_MS + (distance / maxDistance) * RIPPLE_SPREAD_MS);
cells.push({ key: `${row}:${column}`, left, top, delay });
}
}
return { size, width, height: gridHeight, cells };
}

const styles = StyleSheet.create({
const styles = StyleSheet.create((theme) => ({
backdrop: { flex: 1, backgroundColor: theme.colors.background },
app: { flex: 1 },
center: { alignItems: 'center', justifyContent: 'center' },
grid: { position: 'absolute' },
icon: { width: ICON_SIZE, height: ICON_SIZE },
flood: { position: 'absolute', width: FLOOD_SIZE, height: FLOOD_SIZE, backgroundColor: colors.light.brand },
pixel: { position: 'absolute', backgroundColor: colors.light.brand },
letters: { position: 'absolute', width: LETTERS_CLIP, height: LETTERS_CLIP },
lettersClip: { width: LETTERS_CLIP, height: LETTERS_CLIP, borderRadius: LETTERS_CLIP / 2, overflow: 'hidden' },
lettersIcon: {
width: ICON_SIZE,
height: ICON_SIZE,
marginLeft: (LETTERS_CLIP - ICON_SIZE) / 2,
marginTop: (LETTERS_CLIP - ICON_SIZE) / 2,
},
});
overlay: { ...StyleSheet.absoluteFill, alignItems: 'center', justifyContent: 'center' },
fill: { ...StyleSheet.absoluteFill, backgroundColor: SPLASH_COLOR },
logo: { width: LOGO_SIZE, height: LOGO_SIZE },
}));
Loading