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

Function ShellBlock

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

Source from the content-addressed store, hash-verified

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