Skip to content

Commit 4b39cab

Browse files
Inbal-Tishethanshar
authored andcommitted
Feat/featur highlight extras (#506)
* Adding borderRadius prop * Adding headline prop * Adding pageControlProps prop * adding borderRadius example * removing headline prop and adding titleStyle and messageStyle props
1 parent f5f46b6 commit 4b39cab

File tree

2 files changed

+83
-20
lines changed

2 files changed

+83
-20
lines changed

demo/src/screens/componentScreens/FeatureHighlightScreen.js

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import _ from 'lodash';
22
import React, {Component} from 'react';
3-
import {Constants, View, Text, Button, Image, FeatureHighlight} from 'react-native-ui-lib'; // eslint-disable-line
3+
import {Colors, Typography, View, Text, Button, FeatureHighlight} from 'react-native-ui-lib'; // eslint-disable-line
4+
45

56
const titles = [
67
'Get Notified',
78
'Title two is a long title that will not get cut by default, but can be limited',
89
'Title number three',
910
'Title number four',
1011
'Title number five',
11-
'Title number six',
12+
'Welcome to Uilib demo!'
1213
];
1314
const messages = [
1415
'Important notifications appear right on your clubs and groups. Tap them to get more information about the most' +
@@ -19,8 +20,7 @@ const messages = [
1920
' warning about it',
2021
'Very short message',
2122
'Short message with information about the below highlighted feature',
22-
'Important notifications appear right on your clubs and groups. Tap them to get more information about the most' +
23-
'important things that you should pay attention to.',
23+
'Here is where you can view demos of all Uilib components'
2424
];
2525

2626
class FeatureHighlightScreen extends Component {
@@ -30,14 +30,10 @@ class FeatureHighlightScreen extends Component {
3030

3131
this.state = {
3232
showFTE: false,
33-
currentTargetIndex: 0,
33+
currentTargetIndex: 0
3434
};
3535

3636
this.targets = {};
37-
38-
this.closeHighlight = this.closeHighlight.bind(this);
39-
this.showHighlight = this.showHighlight.bind(this);
40-
this.moveNext = this.moveNext.bind(this);
4137
}
4238

4339
componentDidMount() {
@@ -47,11 +43,11 @@ class FeatureHighlightScreen extends Component {
4743
}, 1000);
4844
}
4945

50-
closeHighlight() {
46+
closeHighlight = () => {
5147
this.setState({showFTE: false});
5248
}
5349

54-
showHighlight() {
50+
showHighlight = () => {
5551
this.setState({showFTE: true});
5652
}
5753

@@ -61,29 +57,54 @@ class FeatureHighlightScreen extends Component {
6157
}
6258
}
6359

64-
moveNext() {
60+
moveNext = () => {
6561
const {currentTargetIndex} = this.state;
6662
const newTargetIndex = currentTargetIndex + 1;
6763

68-
if (newTargetIndex < _.size(this.targets)) {
69-
this.setState({currentTargetIndex: newTargetIndex});
64+
this.moveToPage(newTargetIndex);
65+
}
66+
67+
moveToPage(index) {
68+
if (index < _.size(this.targets)) {
69+
this.setState({currentTargetIndex: index});
7070
} else {
7171
this.closeHighlight();
7272
}
7373
}
7474

75+
getPageControlProps() {
76+
return {
77+
numOfPages: titles.length,
78+
currentPage: this.state.currentTargetIndex,
79+
onPagePress: this.onPagePress,
80+
color: Colors.dark30,
81+
inactiveColor: Colors.dark80,
82+
size: 8
83+
};
84+
}
85+
86+
onPagePress = (index) => {
87+
this.moveToPage(index);
88+
}
89+
7590
renderHighlighterOverlay() {
7691
const {showFTE, currentTargetIndex} = this.state;
92+
const lastPage = titles.length - 1;
93+
7794
return (
7895
<FeatureHighlight
7996
visible={showFTE}
8097
title={titles[currentTargetIndex]}
8198
message={messages[currentTargetIndex]}
99+
titleStyle={currentTargetIndex === lastPage ? {...Typography.text70} : undefined}
100+
messageStyle={currentTargetIndex === lastPage ? {...Typography.text60, fontWeight: '900', lineHeight: 28} : undefined}
82101
confirmButtonProps={{label: 'Got It', onPress: this.moveNext}}
83102
onBackgroundPress={this.closeHighlight}
84103
getTarget={() => this.targets[currentTargetIndex]}
85104
// highlightFrame={{x: 30, y: 70, width: 150, height: 30}}
86105
// highlightFrame={{x: 160, y: 336, width: 150, height: 56}}
106+
borderRadius={currentTargetIndex === 4 ? 4 : undefined}
107+
pageControlProps={currentTargetIndex < lastPage ? this.getPageControlProps() : undefined}
87108
/>
88109
);
89110
}

src/components/featureHighlight/index.js

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {BaseComponent} from '../../commons';
88
import View from '../view';
99
import Text from '../text';
1010
import Button from '../button';
11+
import PageControl from '../pageControl';
1112
import {HighlighterOverlayView} from '../../nativeComponents';
1213

1314

@@ -63,6 +64,14 @@ class FeatureHighlight extends BaseComponent {
6364
* Message to be displayed
6465
*/
6566
message: PropTypes.string,
67+
/**
68+
* Title text style
69+
*/
70+
titleStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.number, PropTypes.array]),
71+
/**
72+
* Message text style
73+
*/
74+
messageStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.number, PropTypes.array]),
6675
/**
6776
* Title's max number of lines
6877
*/
@@ -95,6 +104,10 @@ class FeatureHighlight extends BaseComponent {
95104
* Width of the border around the highlighted element
96105
*/
97106
borderWidth: PropTypes.number,
107+
/**
108+
* Border radius for the border corners around the highlighted element
109+
*/
110+
borderRadius: PropTypes.number,
98111
/**
99112
* The minimum size of the highlighted component (Android API 21+, and only when passing a ref in 'getTarget')
100113
*/
@@ -105,7 +118,11 @@ class FeatureHighlight extends BaseComponent {
105118
/**
106119
* The padding of the highlight frame around the highlighted element's frame (only when passing ref in 'getTarget')
107120
*/
108-
innerPadding: PropTypes.number
121+
innerPadding: PropTypes.number,
122+
/**
123+
* PageControl component's props
124+
*/
125+
pageControlProps: PropTypes.shape(PageControl.propTypes)
109126
};
110127

111128
constructor(props) {
@@ -216,7 +233,7 @@ class FeatureHighlight extends BaseComponent {
216233
}
217234

218235
renderHighlightMessage() {
219-
const {title, message, confirmButtonProps, textColor, titleNumberOfLines, messageNumberOfLines}
236+
const {title, message, titleStyle, messageStyle, confirmButtonProps, textColor, titleNumberOfLines, messageNumberOfLines}
220237
= this.getThemeProps();
221238
const color = textColor || defaultTextColor;
222239

@@ -227,12 +244,31 @@ class FeatureHighlight extends BaseComponent {
227244
pointerEvents="box-none"
228245
>
229246
{title && (
230-
<Text text60 style={[styles.title, {color}]} numberOfLines={titleNumberOfLines} pointerEvents="none">
247+
<Text text60
248+
style={[
249+
styles.title,
250+
{
251+
color,
252+
marginBottom: message ? titleBottomMargin : messageBottomMargin
253+
},
254+
titleStyle
255+
]}
256+
numberOfLines={titleNumberOfLines}
257+
pointerEvents="none"
258+
>
231259
{title}
232260
</Text>
233261
)}
234262
{message && (
235-
<Text text70 style={[styles.message, {color}]} numberOfLines={messageNumberOfLines} pointerEvents="none">
263+
<Text text70
264+
style={[
265+
styles.message,
266+
{color},
267+
messageStyle
268+
]}
269+
numberOfLines={messageNumberOfLines}
270+
pointerEvents="none"
271+
>
236272
{message}
237273
</Text>
238274
)}
@@ -255,7 +291,7 @@ class FeatureHighlight extends BaseComponent {
255291
if (contentTopPosition === undefined) return null;
256292

257293
const {testID, visible, highlightFrame, overlayColor, borderColor, borderWidth, minimumRectSize, innerPadding,
258-
onBackgroundPress} = this.getThemeProps();
294+
onBackgroundPress, borderRadius, pageControlProps} = this.getThemeProps();
259295

260296
return (
261297
<HighlighterOverlayView
@@ -268,9 +304,16 @@ class FeatureHighlight extends BaseComponent {
268304
strokeWidth={borderWidth || defaultStrokeWidth}
269305
minimumRectSize={minimumRectSize}
270306
innerPadding={innerPadding}
307+
borderRadius={borderRadius}
271308
>
272309
<TouchableWithoutFeedback style={styles.touchableOverlay} onPress={onBackgroundPress}>
310+
{pageControlProps ?
311+
<View flex bottom>
312+
<PageControl {...pageControlProps} containerStyle={{marginBottom: 24}}/>
313+
</View>
314+
:
273315
<View flex/>
316+
}
274317
</TouchableWithoutFeedback>
275318
{this.renderHighlightMessage()}
276319
</HighlighterOverlayView>
@@ -286,7 +329,6 @@ const styles = StyleSheet.create({
286329
alignItems: 'flex-start'
287330
},
288331
title: {
289-
marginBottom: titleBottomMargin,
290332
lineHeight: Typography.text60.lineHeight,
291333
fontWeight: '900'
292334
},

0 commit comments

Comments
 (0)