Skip to content

Commit

Permalink
CM追加
Browse files Browse the repository at this point in the history
  • Loading branch information
TranLuongTuanAnh committed Mar 12, 2018
1 parent b54cefb commit 455ebb2
Show file tree
Hide file tree
Showing 5 changed files with 475 additions and 7 deletions.
10 changes: 4 additions & 6 deletions App.js
Expand Up @@ -14,6 +14,8 @@ import {
Dimensions,
} from 'react-native';

import CoachMarks from './source/coachmarks'

const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' +
'Cmd+D or shake for dev menu',
Expand Down Expand Up @@ -56,9 +58,6 @@ export default class App extends Component<Props> {
<Image style={styles.bottomChildItem}
source={require('./ic_skip_next.png')}
/>
<Image style={styles.bottomChildItem}
source={require('./ic_smartphone.png')}
/>
</View>
</View>
);
Expand All @@ -69,7 +68,6 @@ const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
backgroundColor: 'rgba(19,166,205,1)',
},
welcome: {
fontSize: 20,
Expand All @@ -84,7 +82,7 @@ const styles = StyleSheet.create({
},
bottomChildView: {
flexDirection: 'row',
top: height / 2,
top: height / 2 - 40,
},
bottomChildItem: {
width: 60,
Expand All @@ -93,7 +91,7 @@ const styles = StyleSheet.create({
},
topChildView: {
flexDirection: 'row',
top: 70,
top: 30,
width: width,
justifyContent: 'flex-end',
},
Expand Down
Binary file added mask.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -7,8 +7,10 @@
"test": "jest"
},
"dependencies": {
"prop-types": "^15.6.1",
"react": "16.2.0",
"react-native": "0.53.3"
"react-native": "0.53.3",
"react-native-i18n": "^2.0.12"
},
"devDependencies": {
"babel-jest": "22.4.0",
Expand Down
219 changes: 219 additions & 0 deletions source/coachmarks.js
@@ -0,0 +1,219 @@
import React, { Component } from 'react';

import {
View,
Modal,
Text,
Image,
StyleSheet,
Dimensions,
TouchableOpacity,
Button,
} from 'react-native';

import PropTypes from 'prop-types';

import I18n from 'react-native-i18n';


import TurtorialStep from './tutorialStep';

const { width, height } = Dimensions.get('window');
const dogImg = require('../ic_public.png');

export default class CoachMarks extends Component {
static propTypes = {
numberOfSteps: PropTypes.number,
coachMarks: PropTypes.array,
visible: PropTypes.bool,
congratsText: PropTypes.string,
onClose: PropTypes.func,
}

state = {
stepStates: [],
isStarting: false,
isEnding: false,
}

componentDidMount() {
this.setDefaultStepStates();
}

render() {
const { theme } = this.props.styles;
const styles = createThemeStyle(theme);

return (
<Modal
animationType="fade"
transparent
visible={this.props.visible && !this.state.isEnding}
onRequestClose={() => {
this.dismiss();
}}
>
{!this.state.isStarting &&
<View style={styles.visibleContainer}>
<TouchableOpacity style={styles.backArea} activeOpacity={1} />
<View style={styles.scene}>
<View style={styles.container}>
<Image
style={{ width: 150, height: 150 }}
source={dogImg}
/>
<Text style={styles.centeringTxt}>{this.props.congratsText}</Text>
<Button title="startTutorial" onPress={() => this.startTutorial()} />
</View>
<View style={styles.skipScene}>
<Button title="skipTutorial" onPress={() => this.dismiss()} />
</View>
</View>
</View>
}
{this.renderCM()}
</Modal>
);
}

dismiss() {
this.setState({ isEnding: true });
this.props.onClose();
}

startTutorial() {
this.setState({ isStarting: true });
this.startCoachMarks();
}

setDefaultStepStates() {
const states = [];
for (let i = 0; i < this.props.numberOfSteps; i++) {
states.push(0);
}
this.setState({ stepStates: states });
}

startCoachMarks() {
const states = this.state.stepStates;
for (let i = 0; i < this.props.numberOfSteps; i++) {
if (i === 0) {
states[i] = 1;
} else {
states[i] = 0;
}
}

this.setState({ stepStates: states });
}

OKBtn(step, onPressOK) {
const states = this.state.stepStates;
if (step === this.props.numberOfSteps - 1) {
this.dismiss();
}
for (let i = 0; i < this.props.numberOfSteps; i++) {
if (i === step + 1) {
states[i] = 1;
} else {
states[i] = 0;
}
}
this.setState({ stepStates: states });

if (onPressOK) {
onPressOK();
}
}

renderCM() {
const {
numberOfSteps, coachMarks,
} = this.props;
const CM = [];
for (let i = 0; i < numberOfSteps; i++) {
const state = this.state.stepStates[i];
CM.push(<TurtorialStep
key={i}
step={i}
tooltip={coachMarks[i].tooltip}
style={coachMarks[i].style}
position={coachMarks[i].position}
tooltipPosition={coachMarks[i].tooltipPosition}
visible={state !== 0}
onPress={step => this.OKBtn(step, coachMarks[i].onPressOK)}
styles={this.props.styles}
okEnable={coachMarks[i].okEnable}
onPressMark={coachMarks[i].onPressMark}
endModal={coachMarks[i].endModal}
isCircleMask={coachMarks[i].isCircleMask}
/>);
}
return (
<View>
{CM}
</View>
);
}
}

const createThemeStyle = theme => StyleSheet.create({
visibleContainer: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
scene: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
backArea: {
width,
height,
position: 'absolute',
top: 0,
right: 0,
backgroundColor: theme.coachmarksOverlay,
},
container: {
width: 300,
height: 320,
backgroundColor: theme.content,
borderColor: theme.coachmarksContainerBorder,
borderRadius: 8,
overflow: 'hidden',
justifyContent: 'center',
alignItems: 'center',
},
centeringTxt: {
color: theme.coachmarksText,
textAlign: 'center',
paddingLeft: 3,
paddingRight: 3,
},
skipScene: {
justifyContent: 'center',
alignItems: 'center',
width: 300,
height: 70,
},
divider: {
backgroundColor: theme.divider,
marginVertical: 16,
width: 268,
},
button: {
backgroundColor: theme.transparent,
},
buttonText: {
color: theme.mainColor,
},
skip: {
backgroundColor: theme.transparent,
},
skipText: {
color: theme.coachmarksSkipText,
fontSize: 13,
},
});

0 comments on commit 455ebb2

Please sign in to comment.