MCPcopy Create free account
hub / github.com/dailydotdev/apps / ShellBlock

Function ShellBlock

packages/shared/src/components/shell/ShellBlock.tsx:252–435  ·  view source on GitHub ↗
({
  root,
  row,
}: ShellBlockProps)

Source from the content-addressed store, hash-verified

250// reading down and returns on any scroll up. Content keeps a constant top
251// padding from --shell-top, so hiding never reflows it.
252export function ShellBlock({
253 root,
254 row,
255}: ShellBlockProps): ReactElement | null {
256 const router = useRouter();
257 const config = useShellPageConfig();
258 const dockedRow = useShellDockedRow();
259 const { p } = useShellScroll();
260 const online = useOnline();
261 const ref = useRef<HTMLElement>(null);
262 const hidden = !config?.hidden && p >= 0.99;
263 // iOS 26 Safari paints its status area solid while a fixed element with a
264 // background stands at the top, and looks again only when that element
265 // leaves the layout: slid out of view or made invisible, the block left a
266 // solid band over the page. There, once it has slid away it leaves the
267 // layout ('out'). Coming back it first stands at the hidden position
268 // ('returning'), since a box leaving `display: none` has no start for the
269 // slide to run from.
270 const [gone, setGone] = useState<'out' | 'returning' | false>(false);
271 useEffect(() => {
272 if (!hidden) {
273 setGone((was) => (was === 'out' ? 'returning' : false));
274 return undefined;
275 }
276 if (!isIOS() || isIOSNative()) {
277 return undefined;
278 }
279 const timer = window.setTimeout(() => setGone('out'), motion.snap);
280 return () => window.clearTimeout(timer);
281 }, [hidden]);
282 useClientLayoutEffect(() => {
283 if (gone !== 'returning') {
284 return;
285 }
286 // Reading the box settles the hidden position as the slide's start.
287 ref.current?.getBoundingClientRect();
288 setGone(false);
289 }, [gone]);
290 const offset = gone ? 1 : p;
291
292 // A new page starts with the block in place, so an arrival (a slide, a
293 // cut) is never followed by the block playing its own reveal. The reset
294 // comes at the start of the move: the route's own completion lands a
295 // frame after the new page has painted.
296 const [arriving, setArriving] = useState(false);
297 const events = router?.events;
298 useEffect(() => {
299 if (!events) {
300 return undefined;
301 }
302 const onArrive = () => {
303 revealShell();
304 setArriving(true);
305 };
306 events.on('routeChangeStart', onArrive);
307 events.on('routeChangeComplete', onArrive);
308 return () => {
309 events.off('routeChangeStart', onArrive);

Callers

nothing calls this directly

Calls 10

useShellPageConfigFunction · 0.90
useShellDockedRowFunction · 0.90
useShellScrollFunction · 0.90
useOnlineFunction · 0.90
isIOSFunction · 0.90
isIOSNativeFunction · 0.90
setNativeStatusBarFunction · 0.90
revealShellFunction · 0.90
publishFunction · 0.70
useRouterFunction · 0.50

Tested by

no test coverage detected