Skip to content

Feat/featur highlight extras #506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 35 additions & 14 deletions demo/src/screens/componentScreens/FeatureHighlightScreen.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import _ from 'lodash';
import React, {Component} from 'react';
import {Constants, View, Text, Button, Image, FeatureHighlight} from 'react-native-ui-lib'; // eslint-disable-line
import {Colors, Typography, View, Text, Button, FeatureHighlight} from 'react-native-ui-lib'; // eslint-disable-line


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

class FeatureHighlightScreen extends Component {
Expand All @@ -30,14 +30,10 @@ class FeatureHighlightScreen extends Component {

this.state = {
showFTE: false,
currentTargetIndex: 0,
currentTargetIndex: 0
};

this.targets = {};

this.closeHighlight = this.closeHighlight.bind(this);
this.showHighlight = this.showHighlight.bind(this);
this.moveNext = this.moveNext.bind(this);
}

componentDidMount() {
Expand All @@ -47,11 +43,11 @@ class FeatureHighlightScreen extends Component {
}, 1000);
}

closeHighlight() {
closeHighlight = () => {
this.setState({showFTE: false});
}

showHighlight() {
showHighlight = () => {
this.setState({showFTE: true});
}

Expand All @@ -61,29 +57,54 @@ class FeatureHighlightScreen extends Component {
}
}

moveNext() {
moveNext = () => {
const {currentTargetIndex} = this.state;
const newTargetIndex = currentTargetIndex + 1;

if (newTargetIndex < _.size(this.targets)) {
this.setState({currentTargetIndex: newTargetIndex});
this.moveToPage(newTargetIndex);
}

moveToPage(index) {
if (index < _.size(this.targets)) {
this.setState({currentTargetIndex: index});
} else {
this.closeHighlight();
}
}

getPageControlProps() {
return {
numOfPages: titles.length,
currentPage: this.state.currentTargetIndex,
onPagePress: this.onPagePress,
color: Colors.dark30,
inactiveColor: Colors.dark80,
size: 8
};
}

onPagePress = (index) => {
this.moveToPage(index);
}

renderHighlighterOverlay() {
const {showFTE, currentTargetIndex} = this.state;
const lastPage = titles.length - 1;

return (
<FeatureHighlight
visible={showFTE}
title={titles[currentTargetIndex]}
message={messages[currentTargetIndex]}
titleStyle={currentTargetIndex === lastPage ? {...Typography.text70} : undefined}
messageStyle={currentTargetIndex === lastPage ? {...Typography.text60, fontWeight: '900', lineHeight: 28} : undefined}
confirmButtonProps={{label: 'Got It', onPress: this.moveNext}}
onBackgroundPress={this.closeHighlight}
getTarget={() => this.targets[currentTargetIndex]}
// highlightFrame={{x: 30, y: 70, width: 150, height: 30}}
// highlightFrame={{x: 160, y: 336, width: 150, height: 56}}
borderRadius={currentTargetIndex === 4 ? 4 : undefined}
pageControlProps={currentTargetIndex < lastPage ? this.getPageControlProps() : undefined}
/>
);
}
Expand Down
54 changes: 48 additions & 6 deletions src/components/featureHighlight/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {BaseComponent} from '../../commons';
import View from '../view';
import Text from '../text';
import Button from '../button';
import PageControl from '../pageControl';
import {HighlighterOverlayView} from '../../nativeComponents';


Expand Down Expand Up @@ -63,6 +64,14 @@ class FeatureHighlight extends BaseComponent {
* Message to be displayed
*/
message: PropTypes.string,
/**
* Title text style
*/
titleStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.number, PropTypes.array]),
/**
* Message text style
*/
messageStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.number, PropTypes.array]),
/**
* Title's max number of lines
*/
Expand Down Expand Up @@ -95,6 +104,10 @@ class FeatureHighlight extends BaseComponent {
* Width of the border around the highlighted element
*/
borderWidth: PropTypes.number,
/**
* Border radius for the border corners around the highlighted element
*/
borderRadius: PropTypes.number,
/**
* The minimum size of the highlighted component (Android API 21+, and only when passing a ref in 'getTarget')
*/
Expand All @@ -105,7 +118,11 @@ class FeatureHighlight extends BaseComponent {
/**
* The padding of the highlight frame around the highlighted element's frame (only when passing ref in 'getTarget')
*/
innerPadding: PropTypes.number
innerPadding: PropTypes.number,
/**
* PageControl component's props
*/
pageControlProps: PropTypes.shape(PageControl.propTypes)
};

constructor(props) {
Expand Down Expand Up @@ -216,7 +233,7 @@ class FeatureHighlight extends BaseComponent {
}

renderHighlightMessage() {
const {title, message, confirmButtonProps, textColor, titleNumberOfLines, messageNumberOfLines}
const {title, message, titleStyle, messageStyle, confirmButtonProps, textColor, titleNumberOfLines, messageNumberOfLines}
= this.getThemeProps();
const color = textColor || defaultTextColor;

Expand All @@ -227,12 +244,31 @@ class FeatureHighlight extends BaseComponent {
pointerEvents="box-none"
>
{title && (
<Text text60 style={[styles.title, {color}]} numberOfLines={titleNumberOfLines} pointerEvents="none">
<Text text60
style={[
styles.title,
{
color,
marginBottom: message ? titleBottomMargin : messageBottomMargin
},
titleStyle
]}
numberOfLines={titleNumberOfLines}
pointerEvents="none"
>
{title}
</Text>
)}
{message && (
<Text text70 style={[styles.message, {color}]} numberOfLines={messageNumberOfLines} pointerEvents="none">
<Text text70
style={[
styles.message,
{color},
messageStyle
]}
numberOfLines={messageNumberOfLines}
pointerEvents="none"
>
{message}
</Text>
)}
Expand All @@ -255,7 +291,7 @@ class FeatureHighlight extends BaseComponent {
if (contentTopPosition === undefined) return null;

const {testID, visible, highlightFrame, overlayColor, borderColor, borderWidth, minimumRectSize, innerPadding,
onBackgroundPress} = this.getThemeProps();
onBackgroundPress, borderRadius, pageControlProps} = this.getThemeProps();

return (
<HighlighterOverlayView
Expand All @@ -268,9 +304,16 @@ class FeatureHighlight extends BaseComponent {
strokeWidth={borderWidth || defaultStrokeWidth}
minimumRectSize={minimumRectSize}
innerPadding={innerPadding}
borderRadius={borderRadius}
>
<TouchableWithoutFeedback style={styles.touchableOverlay} onPress={onBackgroundPress}>
{pageControlProps ?
<View flex bottom>
<PageControl {...pageControlProps} containerStyle={{marginBottom: 24}}/>
</View>
:
<View flex/>
}
</TouchableWithoutFeedback>
{this.renderHighlightMessage()}
</HighlighterOverlayView>
Expand All @@ -286,7 +329,6 @@ const styles = StyleSheet.create({
alignItems: 'flex-start'
},
title: {
marginBottom: titleBottomMargin,
lineHeight: Typography.text60.lineHeight,
fontWeight: '900'
},
Expand Down