File tree Expand file tree Collapse file tree 2 files changed +20
-5
lines changed
src/incubator/TabController Expand file tree Collapse file tree 2 files changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -13,13 +13,25 @@ class PageCarousel extends Component {
13
13
useNativeDriver : true
14
14
} ) ;
15
15
16
+ componentDidMount ( ) {
17
+ if ( Constants . isAndroid ) {
18
+ setTimeout ( ( ) => {
19
+ this . scrollToPage ( this . context . selectedIndex , false ) ;
20
+ } , 0 ) ;
21
+ }
22
+ }
23
+
16
24
onTabChange = ( [ index ] ) => {
17
- const node = this . carousel . current . getNode ( ) ;
18
- node . scrollTo ( { x : index * Constants . screenWidth , animated : true } ) ;
25
+ this . scrollToPage ( index , true ) ;
19
26
} ;
20
27
28
+ scrollToPage = ( pageIndex , animated ) => {
29
+ const node = this . carousel . current . getNode ( ) ;
30
+ node . scrollTo ( { x : pageIndex * Constants . screenWidth , animated} ) ;
31
+ }
32
+
21
33
render ( ) {
22
- const { currentPage} = this . context ;
34
+ const { selectedIndex , currentPage} = this . context ;
23
35
return (
24
36
< >
25
37
< Animated . ScrollView
@@ -30,11 +42,14 @@ class PageCarousel extends Component {
30
42
showsHorizontalScrollIndicator = { false }
31
43
onScroll = { this . onScroll }
32
44
scrollEventThrottle = { 200 }
45
+ contentOffset = { { x : selectedIndex * Constants . screenWidth } } // iOS only
33
46
/>
34
47
35
48
< Code >
36
49
{ ( ) => {
37
- return block ( [ call ( [ currentPage ] , this . onTabChange ) ] ) ;
50
+ return block ( [
51
+ Animated . onChange ( currentPage , call ( [ currentPage ] , this . onTabChange ) )
52
+ ] ) ;
38
53
} }
39
54
</ Code >
40
55
</ >
Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ class TabController extends Component {
57
57
58
58
_targetPage = new Value ( - 1 ) ;
59
59
_currentPage = new Value ( this . props . selectedIndex ) ;
60
- _carouselOffset = new Value ( 0 ) ;
60
+ _carouselOffset = new Value ( this . props . selectedIndex * Math . round ( Constants . screenWidth ) ) ;
61
61
62
62
getProviderContextValue = ( ) => {
63
63
const { itemStates} = this . state ;
You can’t perform that action at this time.
0 commit comments