Skip to content

Commit 0e92e1a

Browse files
Inbal-Tishethanshar
authored andcommitted
Feature highlight (#124)
* 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
1 parent 8da3895 commit 0e92e1a

File tree

2 files changed

+67
-31
lines changed

2 files changed

+67
-31
lines changed

demo/src/screens/componentScreens/FeatureHighlightScreen.js

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
1+
import _ from 'lodash';
12
import React, {Component} from 'react';
23
import {Constants, View, Text, Button, Image, FeatureHighlight} from 'react-native-ui-lib'; // eslint-disable-line
34

45
class FeatureHighlightScreen extends Component {
56

67
constructor(props) {
78
super(props);
8-
this.closeHighlight = this.closeHighlight.bind(this);
9-
this.showHighlight = this.showHighlight.bind(this);
109

1110
this.state = {
12-
showFTE: false,
11+
showFTE: true,
12+
currentTargetIndex: 0,
1313
};
14+
1415
this.targets = [];
16+
17+
this.closeHighlight = this.closeHighlight.bind(this);
18+
this.showHighlight = this.showHighlight.bind(this);
19+
this.moveNext = this.moveNext.bind(this);
1520
}
1621

1722
componentDidMount() {
18-
this.showHighlight();
23+
// this.showHighlight();
1924
}
2025

2126
closeHighlight() {
@@ -26,6 +31,25 @@ class FeatureHighlightScreen extends Component {
2631
this.setState({showFTE: true});
2732
}
2833

34+
addTarget(ref) {
35+
if (ref != null) {
36+
if (!_.find(this.targets, {props: {testID: ref.props.testID}})) {
37+
this.targets.push(ref);
38+
}
39+
}
40+
}
41+
42+
moveNext() {
43+
const {currentTargetIndex} = this.state;
44+
const newTargetIndex = currentTargetIndex + 1;
45+
46+
if (newTargetIndex < this.targets.length) {
47+
this.setState({currentTargetIndex: newTargetIndex});
48+
} else {
49+
this.closeHighlight();
50+
}
51+
}
52+
2953
renderHighlighterOverlay() {
3054
const {showFTE} = this.state;
3155
return (
@@ -34,8 +58,8 @@ class FeatureHighlightScreen extends Component {
3458
title="Get Notified"
3559
message="Important notifications appear right on your clubs and groups.
3660
Tap them to get more information about the most important things that you should pay attention to."
37-
confirmButtonProps={{label: 'Got It', onPress: this.closeHighlight}}
38-
getTarget={() => this.targets[Math.floor(Math.random() * this.targets.length)]}
61+
confirmButtonProps={{label: 'Got It', onPress: this.moveNext}}
62+
getTarget={() => this.targets[this.state.currentTargetIndex]}
3963
// highlightFrame={{x: 30, y: 70, width: 150, height: 30}}
4064
// highlightFrame={{x: 175, y: 334, width: 150, height: 56}}
4165
/>
@@ -47,19 +71,29 @@ class FeatureHighlightScreen extends Component {
4771
<View flex>
4872
<View row flex>
4973
<View left>
50-
<View marginT-40 br100 bg-yellow10 style={{width: 32, height: 32}} ref={r => (this.targets.push(r))}/>
51-
<View marginT-40 bg-red10 style={{width: 12, height: 12}} ref={r => (this.targets.push(r))}/>
74+
<View
75+
marginT-40 br100 bg-yellow10
76+
style={{width: 32, height: 32}}
77+
testID={'0'}
78+
ref={r => (this.addTarget(r))}
79+
/>
80+
<View marginT-40 bg-red10 style={{width: 12, height: 12}} testID={'1'} ref={r => (this.addTarget(r))}/>
5281
</View>
5382
<View right flex>
5483
<View row flex>
55-
<View marginT-40 marginR-60 bg-cyan30 style={{width: 50, height: 70}} ref={r => (this.targets.push(r))}/>
56-
<View marginT-40 bg-violet30 style={{width: 70, height: 50}} ref={r => (this.targets.push(r))}/>
84+
<View
85+
marginT-40 marginR-60 bg-cyan30
86+
style={{width: 50, height: 70}}
87+
testID={'2'}
88+
ref={r => (this.addTarget(r))}/>
89+
<View marginT-40 bg-violet30 style={{width: 70, height: 50}} testID={'3'} ref={r => (this.addTarget(r))}/>
5790
</View>
5891
<View
5992
marginT-40 marginR-50
6093
bg-purple40
6194
style={{width: 150, height: 56}}
62-
ref={r => (this.targets.push(r))}
95+
testID={'4'}
96+
ref={r => (this.addTarget(r))}
6397
/>
6498
</View>
6599
</View>
@@ -72,7 +106,7 @@ class FeatureHighlightScreen extends Component {
72106
into electronic typesetting, <Text>remaining</Text> essentially unchanged.
73107
</Text>
74108
</View>
75-
<View marginT-20 ref={r => (this.targets.push(r))}>
109+
<View marginT-20 testID={'5'} ref={r => (this.addTarget(r))}>
76110
<Button label="Show Overlay" onPress={this.showHighlight}/>
77111
</View>
78112
</View>

src/components/featureHighlight/index.js

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ class FeatureHighlight extends BaseComponent {
118118
innerPadding: 10,
119119
};
120120

121+
componentDidMount() {
122+
this.setTargetPosition();
123+
}
124+
121125
componentWillReceiveProps(nextProps) {
122126
this.setTargetPosition(nextProps);
123127
}
@@ -127,29 +131,27 @@ class FeatureHighlight extends BaseComponent {
127131
}
128132

129133
setTargetPosition(props = this.props) {
130-
if (!this.state.node) {
131-
if (props.getTarget !== undefined) {
132-
const target = props.getTarget();
134+
if (props.getTarget !== undefined) {
135+
const target = props.getTarget();
133136

134-
const node = this.findTargetNode(target);
135-
this.setState({node});
137+
const node = this.findTargetNode(target);
138+
this.setState({node});
136139

137-
if (target) {
138-
setTimeout(() => {
139-
target.measureInWindow((x, y, width, height) => {
140-
this.setState({
141-
targetPosition: {left: x, top: y, width, height},
142-
});
140+
if (target) {
141+
setTimeout(() => {
142+
target.measureInWindow((x, y, width, height) => {
143+
this.setState({
144+
targetPosition: {left: x, top: y, width, height},
143145
});
144-
}, 0);
145-
}
146-
} else {
147-
const frame = props.highlightFrame;
148-
if (frame) {
149-
this.setState({
150-
targetPosition: {left: frame.x, top: frame.y, width: frame.width, height: frame.height},
151146
});
152-
}
147+
}, 0);
148+
}
149+
} else {
150+
const frame = props.highlightFrame;
151+
if (frame) {
152+
this.setState({
153+
targetPosition: {left: frame.x, top: frame.y, width: frame.width, height: frame.height},
154+
});
153155
}
154156
}
155157
}

0 commit comments

Comments
 (0)