diff --git a/.gitignore b/.gitignore index e505689..442e7a9 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ node_modules .rts2_cache_esm .rts2_cache_umd dist -todo.txt \ No newline at end of file +todo.txt +coverage \ No newline at end of file diff --git a/example/App.tsx b/example/App.tsx index 58f937d..db427c3 100644 --- a/example/App.tsx +++ b/example/App.tsx @@ -35,7 +35,7 @@ const App = () => { - + diff --git a/src/pager.tsx b/src/pager.tsx index 32dabd1..758d745 100644 --- a/src/pager.tsx +++ b/src/pager.tsx @@ -273,8 +273,8 @@ function Pager({ // set the initial position - priority to direct prop over context, and context over uncontrolled const _position = memoize(new Value(activeIndex)); - const position = isControlled - ? animatedValue || _position + const position = animatedValue + ? animatedValue : context ? context[2] : _position; @@ -456,8 +456,7 @@ function Pager({ ); - })}{' '} - } + })} diff --git a/test/pager.test.tsx b/test/pager.test.tsx index b1f4b9a..1a81983 100644 --- a/test/pager.test.tsx +++ b/test/pager.test.tsx @@ -1,15 +1,124 @@ import React from 'react'; -import { render } from './test-utils'; -import { Pager } from '../src'; -import { Text } from 'react-native'; +import { render, fireEvent } from './test-utils'; +import { Pager, iPager, PagerProvider, usePager } from '../src'; +import { Text, Button } from 'react-native'; -test('render()', () => { - const { debug } = render( - +function TestPager(props: iPager) { + // style prop will render children without waiting for layout events + return ; +} + +test('render() works', () => { + render( + 1 2 - + ); +}); + +test('activeIndex and onChange props update pager', () => { + function Container({ spy }) { + const [activeIndex, onChange] = React.useState(0); + + function handleChange(nextIndex: number) { + spy(nextIndex); + onChange(nextIndex); + } + + return ( + + Active Index: {activeIndex} +