# Deslizar para actualizar

Al tirar de la lista hacia abajo se añade una entrada recién llegada al registro de impresión.

## Cómo probarlo

Desde el inicio de la lista, tira hacia abajo y suelta cuando cambie el indicador. También puedes usar el botón de actualizar.

## Detalles de la interacción

Se necesitan 82 px de arrastre. Si se suelta antes o se cancela, la lista vuelve a su sitio. Ignora nuevas entradas durante la actualización y añade uno de tres registros de muestra por turno. Con movimiento reducido, sustituye el giro por un mensaje de estado.

## Controles por plataforma

- iOS · Tira hacia abajo desde la flecha superior y suelta. También puedes tocar el botón de actualizar.
- Android · Tira hacia abajo desde la flecha y suelta cuando aparezca el aviso para actualizar.
- PC · Arrastra hacia abajo la parte superior de la lista o enfoca el botón de actualizar y pulsa Intro.

## Dónde usarlo

Fuentes de novedades y colas de trabajo que se actualizan a petición del lector.

## Instrucciones de implementación

> Actualiza una sola vez tras un arrastre suficiente y añade la nueva entrada al principio.

## Fuentes y créditos

[Android Developers · Pull to refresh](<https://developer.android.com/develop/ui/compose/components/pull-to-refresh>)

## Ejemplo en HTML

Guarda el siguiente código en un archivo HTML y ábrelo en tu navegador. Puedes usar el ejemplo sin conexión.

```html
<!doctype html>
<html lang="es"><head><script>if(new URLSearchParams(location.search).get('reduce')==='1')document.documentElement.classList.add('motion-reduced');</script><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Deslizar para actualizar · Motion Lab</title>
<style>
*{box-sizing:border-box}html{color-scheme:light}body{margin:0;font:15px/1.5 system-ui,-apple-system,'Malgun Gothic',sans-serif;word-break:keep-all}main{margin:auto}button{font:inherit;color:inherit;cursor:pointer}button:focus-visible,[tabindex]:focus-visible{outline:3px solid #005bc6;outline-offset:2px}button:disabled{cursor:default}h1,h2,p{margin:0}h1{font-size:clamp(26px,5vw,42px);font-weight:750;letter-spacing:-.075em;line-height:1.2}h2{font-size:18px;letter-spacing:-.04em}.mono{font:600 11px/1.4 ui-monospace,Consolas,monospace;letter-spacing:.055em}.sr{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}button{touch-action:manipulation}html.motion-reduced *,html.motion-reduced *::before,html.motion-reduced *::after{animation-duration:.01ms!important;animation-iteration-count:1!important;transition-duration:.01ms!important;scroll-behavior:auto!important}@media(prefers-reduced-motion:reduce){*,*::before,*::after{animation-duration:.01ms!important;animation-iteration-count:1!important;transition-duration:.01ms!important;scroll-behavior:auto!important}}

body{background:#dae4d9;color:#132d25}main{width:min(100%,660px);padding:clamp(15px,4vw,40px)}.ledger{background:#f3f3dd;border-block:2px solid #183e31;padding:clamp(15px,4vw,32px);box-shadow:0 12px 35px #153a2517}.head,.foot,.row{display:flex;align-items:center;justify-content:space-between;gap:12px}.head{align-items:end}.head h1{margin-top:5px}.seal{display:grid;place-items:center;border:2px double #27503b;color:#27503b;border-radius:50%;width:64px;height:64px;text-align:center;line-height:1.08;transform:rotate(-10deg);font:italic 700 18px/1 Georgia,serif}.pull{margin-top:18px;height:50px;touch-action:none;cursor:grab;user-select:none;display:flex;align-items:center;justify-content:center;gap:8px;background:#d7e2c5;border-block:1px dashed #708771;color:#214833}.pull:active{cursor:grabbing}.dial{font-size:24px;line-height:1}.well{overflow:hidden}.rows{list-style:none;padding:0;margin:0;transform:translateY(var(--pull,0px));transition:transform .28s cubic-bezier(.19,.8,.24,1)}.dragging .rows{transition:none}.row{position:relative;min-height:58px;justify-content:flex-start;padding:8px 0;border-bottom:1px solid #abb59e}.row time{margin-left:auto;font-size:12px}.thumb{height:36px;width:34px;flex:none;background:radial-gradient(ellipse at 47% 45%,var(--tone) 0 34%,#f9e2a4 35% 41%,transparent 42%),repeating-linear-gradient(33deg,#244c39 0 2px,#96ab79 2px 5px);border:1px solid #12352e}.row strong{display:block;font-size:15px}.row small{color:#435547;font-size:11px}.foot{margin-top:13px}.foot p{font-size:12px;color:#344e3d}.foot button{border:0;background:#244532;color:white;min-height:44px;padding:6px 16px;font-weight:700}.foot button:disabled{background:#4c5e50}.busy .dial{animation:spin .72s linear infinite}.row.new{animation:arrival .45s ease-out}@keyframes spin{to{transform:rotate(1turn)}}@keyframes arrival{from{opacity:.15;transform:translateY(-18px)}to{opacity:1;transform:none}}@media(max-width:370px){.seal{width:48px;height:48px;font-size:15px}.row{gap:8px}.foot button{padding-inline:10px}}

</style></head><body>

<main><section class="ledger" aria-labelledby="title"><header class="head"><div><span class="mono">Sala de impresión · Registro de entradas</span><h1 id="title">Pruebas de hoy</h1></div><span class="seal" aria-hidden="true">Proof<br>Desk</span></header>
<div class="pull" id="pull"><span class="dial" aria-hidden="true">↓</span><span id="hint">Desliza hacia abajo para ver novedades</span></div>
<div class="well"><ul class="rows" id="rows" aria-label="Entradas recientes"></ul></div><footer class="foot"><p id="status" role="status">3 entradas recientes</p><button id="refresh" type="button">Actualizar</button></footer></section></main>

<script>

const rows=document.getElementById('rows'),pull=document.getElementById('pull'),hint=document.getElementById('hint'),status=document.getElementById('status'),refresh=document.getElementById('refresh'),ledger=document.querySelector('.ledger');
const records=[['Encuadernación de verano','Prueba de portada','09:12','#ab5030'],['Intervalos de ola','Prueba de texto','09:45','#356258'],['Tipografía del parque','Control de tinta directa','10:20','#2c4f48'],['Taller Verde','Cartel en risografía','10:32','#d35c37'],['Muestra de ventana','Prueba de tinta directa','10:47','#45699d'],['Coordenadas de un paseo','Prueba de plegado','11:08','#8f4151']];
let total=3,gesture=null,busy=false;
function display(fresh){rows.replaceChildren(...records.slice(0,total).reverse().slice(0,3).map(([name,detail,time,tone],i)=>{const li=document.createElement('li');li.className='row'+(fresh&&i===0?' new':'');li.innerHTML='<i aria-hidden="true" class="thumb"></i><div><strong></strong><small></small></div><time class="mono"></time>';li.style.setProperty('--tone',tone);li.querySelector('strong').textContent=name;li.querySelector('small').textContent=detail;li.querySelector('time').textContent=time;return li;}));}
function rest(){ledger.classList.remove('dragging');rows.style.removeProperty('--pull');pull.querySelector('.dial').style.removeProperty('transform');hint.textContent='Desliza hacia abajo para ver novedades';}
function load(){if(busy)return;rest();gesture=null;busy=true;ledger.classList.add('busy');refresh.disabled=true;rows.setAttribute('aria-busy','true');pull.querySelector('.dial').textContent='↻';hint.textContent='Consultando el registro';status.textContent='Consultando el registro del taller.';
setTimeout(()=>{const fresh=total<records.length;if(fresh)total++;display(fresh);busy=false;refresh.disabled=false;ledger.classList.remove('busy');rows.setAttribute('aria-busy','false');rest();pull.querySelector('.dial').textContent='↓';status.textContent=fresh?records[total-1][0]+' recibido · Se muestran las tres últimas entradas':'El registro está al día.';},450);}
pull.addEventListener('pointerdown',e=>{if(!e.isPrimary||e.button!==0||busy)return;gesture={id:e.pointerId,start:e.clientY,dy:0};pull.setPointerCapture(e.pointerId);ledger.classList.add('dragging');});
pull.addEventListener('pointermove',e=>{if(!gesture||e.pointerId!==gesture.id)return;gesture.dy=Math.max(0,e.clientY-gesture.start);rows.style.setProperty('--pull',Math.min(44,gesture.dy*.45)+'px');pull.querySelector('.dial').style.transform='rotate('+Math.min(180,gesture.dy*2)+'deg)';hint.textContent=gesture.dy>=82?'Suelta para actualizar':'Arrastra un poco más';});
function finish(e){if(!gesture||e.pointerId!==gesture.id)return;const commit=e.type==='pointerup'&&gesture.dy>=82;gesture=null;rest();if(commit)load();}
['pointerup','pointercancel','lostpointercapture'].forEach(type=>pull.addEventListener(type,finish));
document.addEventListener('keydown',e=>{if(e.key==='Escape'&&gesture){gesture=null;rest();}});refresh.addEventListener('click',load);display(false);

</script></body></html>
```
