File tree Expand file tree Collapse file tree 2 files changed +11
-7
lines changed Expand file tree Collapse file tree 2 files changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -89,13 +89,13 @@ export class ViewPager extends React.Component<Props> {
89
89
} ;
90
90
91
91
private renderComponentChild = ( element : ChildElement , index : number ) : ChildElement => {
92
- const { shouldLoadComponent } = this . props ;
92
+ const { shouldLoadComponent, contentContainerStyle } = this . props ;
93
93
94
94
const contentView : ChildElement | null = shouldLoadComponent ( index ) ? element : null ;
95
95
96
96
return React . createElement ( View , {
97
97
key : index ,
98
- style : styles . contentViewContainer ,
98
+ style : [ styles . contentViewContainer , contentContainerStyle ] ,
99
99
} , contentView ) ;
100
100
} ;
101
101
@@ -107,10 +107,12 @@ export class ViewPager extends React.Component<Props> {
107
107
const { contentContainerStyle, children, ...derivedProps } = this . props ;
108
108
const componentChildren : ChildElement [ ] = this . renderComponentChildren ( children ) ;
109
109
110
+ const widthPercent : number = 100 * componentChildren . length ;
111
+
110
112
return (
111
113
< ScrollView
112
114
bounces = { false }
113
- contentContainerStyle = { [ styles . contentContainer , contentContainerStyle ] }
115
+ contentContainerStyle = { { width : ` ${ widthPercent } %` } }
114
116
showsHorizontalScrollIndicator = { false }
115
117
{ ...derivedProps }
116
118
ref = { this . scrollViewRef }
@@ -127,10 +129,8 @@ export class ViewPager extends React.Component<Props> {
127
129
}
128
130
129
131
const styles = StyleSheet . create ( {
130
- contentContainer : {
131
- flex : 1 ,
132
- } ,
133
132
contentViewContainer : {
133
+ flex : 1 ,
134
134
width : '100%' ,
135
135
} ,
136
136
} ) ;
Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ import React from 'react';
2
2
import {
3
3
View ,
4
4
Text ,
5
- Dimensions ,
6
5
} from 'react-native' ;
7
6
import { NavigationScreenProps } from 'react-navigation' ;
8
7
import {
@@ -36,6 +35,7 @@ class ViewPagerScreen extends React.Component<Props, State> {
36
35
return (
37
36
< ViewPager
38
37
selectedIndex = { this . state . selectedIndex }
38
+ contentContainerStyle = { this . props . themedStyle . container }
39
39
onSelect = { this . onIndexChange } >
40
40
< View style = { this . props . themedStyle . tabContainer } >
41
41
< Text > Tab 1</ Text >
@@ -52,10 +52,14 @@ class ViewPagerScreen extends React.Component<Props, State> {
52
52
}
53
53
54
54
export default withStyles ( ViewPagerScreen , ( theme : ThemeType ) => ( {
55
+ container : {
56
+ padding : 16 ,
57
+ } ,
55
58
tabContainer : {
56
59
flex : 1 ,
57
60
justifyContent : 'center' ,
58
61
alignItems : 'center' ,
62
+ backgroundColor : 'yellow' ,
59
63
} ,
60
64
} ) ) ;
61
65
You can’t perform that action at this time.
0 commit comments