Skip to content

Commit de490ab

Browse files
Inbal-Tishethanshar
authored andcommitted
Feature highlight (#125)
* add unique targets only by using testID prop * moving setTargetPosition to componentDidMount() to allow rendering with visible=true for immediate visibility * Opening support for tour and adjusting example screen * Adding onBackgroundPress prop to pass a separate callback; Improving example with changing titles and messages for the Tour
1 parent 91c6ef3 commit de490ab

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

demo/src/screens/componentScreens/FeatureHighlightScreen.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@ import _ from 'lodash';
22
import React, {Component} from 'react';
33
import {Constants, View, Text, Button, Image, FeatureHighlight} from 'react-native-ui-lib'; // eslint-disable-line
44

5+
const titles = ['Get Notified', 'Title two is a long title that will get cut', 'Title number three',
6+
'Title number four', 'Title number five', 'Title number six'];
7+
const messages = [
8+
'Important notifications appear right on your clubs and groups. Tap them to get more information about the most' +
9+
'important things that you should pay attention to.',
10+
'Short message with information about the above highlighted feature',
11+
'A long message, that will get cut, with information about the highlighted feature, like: Important notifications' +
12+
' appear right on your clubs and groups. Tap them to get the important things that you should pay attention to.',
13+
'Very short message',
14+
'Short message with information about the below highlighted feature',
15+
'Important notifications appear right on your clubs and groups. Tap them to get more information about the most' +
16+
'important things that you should pay attention to.',
17+
];
18+
519
class FeatureHighlightScreen extends Component {
620

721
constructor(props) {
@@ -51,15 +65,15 @@ class FeatureHighlightScreen extends Component {
5165
}
5266

5367
renderHighlighterOverlay() {
54-
const {showFTE} = this.state;
68+
const {showFTE, currentTargetIndex} = this.state;
5569
return (
5670
<FeatureHighlight
5771
visible={showFTE}
58-
title="Get Notified"
59-
message="Important notifications appear right on your clubs and groups.
60-
Tap them to get more information about the most important things that you should pay attention to."
72+
title={titles[currentTargetIndex]}
73+
message={messages[currentTargetIndex]}
6174
confirmButtonProps={{label: 'Got It', onPress: this.moveNext}}
62-
getTarget={() => this.targets[this.state.currentTargetIndex]}
75+
onBackgroundPress={this.closeHighlight}
76+
getTarget={() => this.targets[currentTargetIndex]}
6377
// highlightFrame={{x: 30, y: 70, width: 150, height: 30}}
6478
// highlightFrame={{x: 175, y: 334, width: 150, height: 56}}
6579
/>
@@ -85,7 +99,8 @@ class FeatureHighlightScreen extends Component {
8599
marginT-40 marginR-60 bg-cyan30
86100
style={{width: 50, height: 70}}
87101
testID={'2'}
88-
ref={r => (this.addTarget(r))}/>
102+
ref={r => (this.addTarget(r))}
103+
/>
89104
<View marginT-40 bg-violet30 style={{width: 70, height: 50}} testID={'3'} ref={r => (this.addTarget(r))}/>
90105
</View>
91106
<View

src/components/featureHighlight/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ class FeatureHighlight extends BaseComponent {
7272
* Props that will be passed to the dismiss button
7373
*/
7474
confirmButtonProps: PropTypes.object,
75+
/**
76+
* Callback for the background press
77+
*/
78+
onBackgroundPress: PropTypes.func,
7579
/**
7680
* Color of the content's background (usually includes alpha for transparency)
7781
*/
@@ -217,9 +221,8 @@ class FeatureHighlight extends BaseComponent {
217221

218222
render() {
219223
const {testID, visible, highlightFrame, overlayColor, borderColor, borderWidth, minimumRectSize, innerPadding,
220-
confirmButtonProps} = this.getThemeProps();
224+
onBackgroundPress} = this.getThemeProps();
221225
const {node, targetPosition} = this.state;
222-
const {onPress} = confirmButtonProps;
223226

224227
return (
225228
<HighlighterOverlayView
@@ -233,7 +236,7 @@ class FeatureHighlight extends BaseComponent {
233236
minimumRectSize={minimumRectSize}
234237
innerPadding={innerPadding}
235238
>
236-
<TouchableWithoutFeedback style={styles.touchableOverlay} onPress={onPress}>
239+
<TouchableWithoutFeedback style={styles.touchableOverlay} onPress={onBackgroundPress}>
237240
<View flex/>
238241
</TouchableWithoutFeedback>
239242
{targetPosition && this.renderHighlightMessage()}

0 commit comments

Comments
 (0)