callstack / callstack/react-native-pager-view
Wrapped pager for ease of use with separate components (without mapping function)
- Lingua principale
- TypeScript
- Stelle
- 3.4k
- Fork
- 476
- Merge medio
- 10g 21h
- PR unite (30g)
- 2
Descrizione
## Describe the feature
This wraps the pagerview into a separate component and looks for the children within the pagerview and based on that will memoize the components.
## Motivation
I struggled to find a way of using the usePagerView hook without a mapping function. For example when you want to show multiple components. So I thought of this idea and I just wanted to share this with everyone :)
Let me know what you think about this! Maybe someone else has an even better alternative? Happy coding!
## Related Issues
Issue right now (look at comment):
```typescript
export function PagerHookExample() {
const { AnimatedPagerView, ref, ...rest } = usePagerView({ pagesAmount: 10 });
return (
{useMemo(
() =>
rest.pages.map((_, index) => ( // We're mapping here, but what if we want to show multiple components?
{`page number ${index}`}
)),
[rest.pages]
)}
);
}
```
Step one: Create the component
```typescript
import { forwardRef, Children, useMemo, useEffect } from "react";
import PagerView, { UsePagerViewProps } from "react-native-pager-view";
interface ListProps extends Omit {
children: React.ReactNode;
onListCountChange?: (count: number) => void;
}
const Pager = forwardRef(
({ children, onListCountChange, AnimatedPagerView, scrollEnabled, ...other }, ref) => {
const childCount = Children.count(children);
useEffect(() => {
onListCountChange?.(childCount);
}, [childCount]);
return (
{useMemo(
() =>
Children.map(children, (child, index) => {
return child
}),
[children],
)}
);
},
);
export default Pager;
```
Step two: use the component using the usePagerView hook
```typescript
export default function Screen() {
const { activePage, ref, ...pagerViewProps } = usePagerView();
return (
);
}
```
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia con l’hook usePagerView e l’entry point AnimatedPagerView descritti nell’issue, quindi confronta gli esempi PagerHookExample e Screen. Il lavoro è completato quando un componente pager separato può accettare più componenti figli senza una funzione di mapping, mantenendo le props del pager e il comportamento di navigazione mostrati qui.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- react-native, typescript
- Ambito
- frontend, mobile
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 32/100