$ git show theme-reveal
Theme circle reveal
Switching to dark mode spreads out as a circle from the toggle, using a snapshot of the old screen.
Inspired by TelegramFrom William Candillon’s “Can it be done in React Native?” series. The code here is a simplified rewrite for Reanimated 4 and 3.
import { scheduleOnRN } from 'react-native-worklets';
import { Canvas, Mask, Group, Rect, Circle, Image, makeImageFromView } from '@shopify/react-native-skia';
const r = useSharedValue(0);
const [overlay, setOverlay] = useState(null);
const toggle = async (x, y) => { // x, y = toggle button center
const img = await makeImageFromView(rootRef); // snapshot of the old theme
setOverlay({ img, x, y });
setDark(d => !d); // new theme renders underneath
r.value = 0;
r.value = withTiming(Math.hypot(width, height), { duration: 600 }, () => scheduleOnRN(setOverlay, null));
};
{overlay && (
<Canvas style={StyleSheet.absoluteFill} pointerEvents="none">
<Mask mode="luminance" mask={
<Group>
<Rect x={0} y={0} width={width} height={height} color="white" />
<Circle cx={overlay.x} cy={overlay.y} r={r} color="black" />
</Group>}>
<Image image={overlay.img} x={0} y={0} width={width} height={height} />
</Mask>
</Canvas>
)}