callstack / callstack/react-native-pager-view
Wrapped pager for ease of use with separate components (without mapping function)
- Lenguaje dominante
- TypeScript
- Estrellas
- 3.4k
- Forks
- 476
- Merge medio
- 10 d 21 h
- PR fusionados (30 d)
- 2
Descripción
## 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 (
);
}
```
Guía de contribución
Línea de trabajo
Comienza con el hook usePagerView y el punto de entrada AnimatedPagerView descritos en el issue, y después compara los ejemplos PagerHookExample y Screen. El trabajo estará terminado cuando un componente pager independiente pueda aceptar varios componentes hijos sin una función de mapeo, conservando las props del pager y el comportamiento de navegación mostrados aquí.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- react-native, typescript
- Área
- frontend, mobile
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 32/100