Skip to content

Commit f643782

Browse files
Inbal-Tishethanshar
authored andcommitted
Woa 9306 (#111)
* add support for inactiveColor * lint fix * adding support to enlargeActive page indicator in PageControl; adding example for colored placeholder in TextInput * edit for docs * Adding support for custom spacing between the page indicators (circles) * fix for enlargement size
1 parent 9eae8a0 commit f643782

File tree

4 files changed

+64
-35
lines changed

4 files changed

+64
-35
lines changed

demo/src/screens/componentScreens/InputsScreen.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ export default class InputScreen extends Component {
7171
<TextInput
7272
text70
7373
floatingPlaceholder
74+
placeholderTextColor={Colors.cyan30}
75+
floatingPlaceholderColor={Colors.cyan30}
7476
placeholder="underline colors && error"
7577
onChangeText={text => this.setState({error: text ? '' : 'This field is required'})}
7678
error={this.state.error}

demo/src/screens/componentScreens/PageControlScreen.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ export default class PageControlScreen extends Component {
1717
<PageControl containerStyle={containerStyle} numOfPages={10} currentPage={4} color={Colors.purple40}/>
1818
<PageControl containerStyle={containerStyle} numOfPages={10} currentPage={5} color={Colors.violet40} size={20}/>
1919
<PageControl containerStyle={containerStyle} numOfPages={10} currentPage={6} color={Colors.orange40} size={20}/>
20+
<PageControl
21+
containerStyle={containerStyle} numOfPages={10} currentPage={6} inactiveColor={Colors.dark70}
22+
/>
23+
<PageControl
24+
containerStyle={containerStyle} numOfPages={10} currentPage={6} inactiveColor={Colors.dark70}
25+
enlargeActive
26+
/>
27+
<PageControl
28+
containerStyle={containerStyle} numOfPages={10} currentPage={6} inactiveColor={Colors.dark70} enlargeActive
29+
spacing={10}
30+
/>
2031
</ScrollView>
2132
);
2233
}

src/components/pageControl/index.js

Lines changed: 50 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1-
import React from 'react';
1+
import _ from 'lodash';
22
import PropTypes from 'prop-types';
3+
import React from 'react';
34
import {StyleSheet} from 'react-native';
4-
import _ from 'lodash';
5-
import * as Constants from '../../helpers/Constants';
65
import {ThemeManager} from '../../style';
76
import {BaseComponent} from '../../commons';
87
import TouchableOpacity from '../touchableOpacity';
98
import View from '../view';
109

11-
function getColorStyle(color, index, currentPage) {
10+
11+
function getColorStyle(color, inactiveColor, index, currentPage) {
1212
const compColor = color || ThemeManager.primaryColor;
13-
return {borderColor: compColor, backgroundColor: (index === currentPage) ? compColor : 'transparent'};
13+
return {borderColor: (index === currentPage) ? compColor : inactiveColor || compColor,
14+
backgroundColor: (index === currentPage) ? compColor : inactiveColor || 'transparent'};
15+
}
16+
17+
function getSizeStyle(size, enlargeActive, index, currentPage) {
18+
const temp = enlargeActive ? ((index === currentPage) ? size + 2 : size) : size;
19+
return {width: temp, height: temp, borderRadius: temp / 2};
1420
}
1521

1622
/**
@@ -38,56 +44,66 @@ export default class PageControl extends BaseComponent {
3844
*/
3945
onPagePress: PropTypes.func,
4046
/**
41-
* Color of the selected page dot and the border of the not selected pages
47+
* Color of the selected page dot and, if inactiveColor not passed, the border of the not selected pages
4248
*/
4349
color: PropTypes.string,
50+
/**
51+
* Color of the unselected page dots and the border of the not selected pages
52+
*/
53+
inactiveColor: PropTypes.string,
4454
/**
4555
* The size of the page indicator
4656
*/
4757
size: PropTypes.number,
58+
/**
59+
* Whether to enlarge the active page indicator
60+
*/
61+
enlargeActive: PropTypes.bool,
62+
/**
63+
* The space between the siblings page indicators
64+
*/
65+
spacing: PropTypes.number,
4866
};
4967

50-
generateStyles() {
51-
this.styles = createStyles(this.props.size);
52-
}
68+
static defaultProps = {
69+
size: 10,
70+
spacing: 4,
71+
enlargeActive: false,
72+
};
5373

5474
render() {
55-
const {numOfPages, currentPage, color, containerStyle, onPagePress} = this.props;
75+
const {numOfPages, currentPage, color, inactiveColor, containerStyle, onPagePress, size, spacing, enlargeActive}
76+
= this.props;
77+
5678
return (
57-
<View style={[this.styles.container, containerStyle]}>
79+
<View style={[styles.container, containerStyle]}>
5880
{
5981
_.map([...new Array(numOfPages)], (item, index) =>
6082
<TouchableOpacity
6183
disabled={_.isUndefined(onPagePress)}
6284
onPress={() => onPagePress && onPagePress(index)}
6385
key={index}
64-
style={[this.styles.pageIndicator, getColorStyle(color, index, currentPage)]}
86+
style={[
87+
styles.pageIndicator,
88+
{marginRight: spacing / 2, marginLeft: spacing / 2},
89+
getColorStyle(color, inactiveColor, index, currentPage),
90+
getSizeStyle(size, enlargeActive, index, currentPage),
91+
]}
6592
/>)
6693
}
6794
</View>
6895
);
6996
}
7097
}
7198

72-
function createStyles(size = 10) {
73-
return StyleSheet.create({
74-
container: {
75-
flexDirection: 'row',
76-
alignItems: 'center',
77-
justifyContent: 'center',
78-
},
79-
pageView: {
80-
width: Constants.screenWidth,
81-
height: Constants.screenHeight,
82-
},
83-
pageIndicator: {
84-
backgroundColor: 'transparent',
85-
borderWidth: 1,
86-
marginRight: 2,
87-
marginLeft: 2,
88-
width: size,
89-
height: size,
90-
borderRadius: size / 2,
91-
},
92-
});
93-
}
99+
const styles = StyleSheet.create({
100+
container: {
101+
flexDirection: 'row',
102+
alignItems: 'center',
103+
justifyContent: 'center',
104+
},
105+
pageIndicator: {
106+
backgroundColor: 'transparent',
107+
borderWidth: 1,
108+
},
109+
});

src/components/view/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default class View extends BaseComponent {
1717
...ViewPropTypes,
1818
...BaseComponent.propTypes,
1919
/**
20-
* if true, will add SafeAreaView as a wrapper
20+
* if true, will render as SafeAreaView
2121
*/
2222
useSafeArea: PropTypes.bool,
2323
};

0 commit comments

Comments
 (0)