[feat]: Animate Presence component addition

Aperta
#1,955 6 commenti 14 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
20/100
Tipo di issue
Funzionalità
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
react, typescript
Ambito
frontend

Direzione di ricerca

Inizia esaminando l’API useTransition esistente e l’hook useAnimatePresence e l’HOC animatedPresence proposti e descritti nell’issue. Non vengono indicati file, test o entry point, quindi l’API e il comportamento devono essere concordati con i maintainer prima dell’implementazione. Il lavoro sarà completato quando sarà stato implementato e validato un design concordato per le animazioni di mount e unmount.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area: core kind: request
A clear and concise description of what the feature is

A new component / hook that animates elements depending on whether their children are being rendered or not without the need to be passing data (this is similar but separate to useTransition which could be depreciated in favour of this new hook)

Why should this feature be included?

framer-motion has a component called animate presence which is fairly similar to our useTransition except with the latter, you have to pass state to the hook to control the appearance of the animated components.

This isn't the worst thing when you're only controlling one modal for instance, but if you want to control multiple it would be easier to be able to handle the animations depending on whether the dom element was mounted or not (see here for more context).

This feature would hopefully lead into #1628 which is also something I would be very interested in adding to react-spring.

Please provide an example for how this would work

Unlike framer-motion, rs has two parts, the hook that runs outside the react-render world & the animated component that interpolates those SpringValues to be applied to the DOM element.

We could create a new component in a similar API style to AnimatePresence, but it would be more inline with the direction of react-spring if we could make a hook & the an additional HOC built on animated to register these components for the hook to manipulate & track. So an ideal approach can be seen below:

const MyComponent = ({show}) => {
	const springs = useAnimatePresence({
		from: {
			opacity: 0,
		},
		enter: {
			opacity: 1
		},
		leave: {
			opacity: 0
		}
	}) 

	return show ? <animatedPresence.div style={springs}>Hello world</animatedPresence.div> : null
}

Of course, happy to hear other people's API design ideas // thoughts or even concerns about this feature.

Lingua principale
TypeScript
Stelle
29.3k
Fork
1.2k
Merge medio
3g 15h
PR unite (30g)
17

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di pmndrs/react-spring

Tutte le issue di pmndrs/react-spring

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.