Skip to content

Commit 2925e70

Browse files
32penkinartyorsh
authored andcommitted
fix(ui): view-pager swipe
1 parent 87b89c1 commit 2925e70

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/framework/ui/viewPager/viewPager.component.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ export class ViewPager extends React.Component<Props> {
8989
};
9090

9191
private renderComponentChild = (element: ChildElement, index: number): ChildElement => {
92-
const { shouldLoadComponent } = this.props;
92+
const { shouldLoadComponent, contentContainerStyle } = this.props;
9393

9494
const contentView: ChildElement | null = shouldLoadComponent(index) ? element : null;
9595

9696
return React.createElement(View, {
9797
key: index,
98-
style: styles.contentViewContainer,
98+
style: [styles.contentViewContainer, contentContainerStyle],
9999
}, contentView);
100100
};
101101

@@ -107,10 +107,12 @@ export class ViewPager extends React.Component<Props> {
107107
const { contentContainerStyle, children, ...derivedProps } = this.props;
108108
const componentChildren: ChildElement[] = this.renderComponentChildren(children);
109109

110+
const widthPercent: number = 100 * componentChildren.length;
111+
110112
return (
111113
<ScrollView
112114
bounces={false}
113-
contentContainerStyle={[styles.contentContainer, contentContainerStyle]}
115+
contentContainerStyle={{ width: `${widthPercent}%` }}
114116
showsHorizontalScrollIndicator={false}
115117
{...derivedProps}
116118
ref={this.scrollViewRef}
@@ -127,10 +129,8 @@ export class ViewPager extends React.Component<Props> {
127129
}
128130

129131
const styles = StyleSheet.create({
130-
contentContainer: {
131-
flex: 1,
132-
},
133132
contentViewContainer: {
133+
flex: 1,
134134
width: '100%',
135135
},
136136
});

src/playground/src/ui/screen/viewPager.component.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React from 'react';
22
import {
33
View,
44
Text,
5-
Dimensions,
65
} from 'react-native';
76
import { NavigationScreenProps } from 'react-navigation';
87
import {
@@ -36,6 +35,7 @@ class ViewPagerScreen extends React.Component<Props, State> {
3635
return (
3736
<ViewPager
3837
selectedIndex={this.state.selectedIndex}
38+
contentContainerStyle={this.props.themedStyle.container}
3939
onSelect={this.onIndexChange}>
4040
<View style={this.props.themedStyle.tabContainer}>
4141
<Text>Tab 1</Text>
@@ -52,10 +52,14 @@ class ViewPagerScreen extends React.Component<Props, State> {
5252
}
5353

5454
export default withStyles(ViewPagerScreen, (theme: ThemeType) => ({
55+
container: {
56+
padding: 16,
57+
},
5558
tabContainer: {
5659
flex: 1,
5760
justifyContent: 'center',
5861
alignItems: 'center',
62+
backgroundColor: 'yellow',
5963
},
6064
}));
6165

0 commit comments

Comments
 (0)