This repository was archived by the owner on Jul 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathTextStep.js
More file actions
151 lines (136 loc) · 3.67 KB
/
TextStep.js
File metadata and controls
151 lines (136 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import Bubble from './Bubble';
import Img from './Image';
import ImageContainer from './ImageContainer';
import Loading from '../common/Loading';
import TextStepContainer from './TextStepContainer';
import TextMessage from './TextMessage';
class TextStep extends Component {
/* istanbul ignore next */
constructor(props) {
super(props);
this.state = {
loading: true,
};
this.renderMessage = this.renderMessage.bind(this);
}
componentDidMount() {
const { step } = this.props;
const { component, delay, waitAction } = step;
const isComponentWatingUser = component && waitAction;
setTimeout(() => {
// this.props.triggerNextStep();
this.setState({ loading: false });
if (!isComponentWatingUser) {
this.props.triggerNextStep();
}
}, delay);
}
renderMessage() {
const { previousValue, step } = this.props;
const { component } = step;
let { message } = step;
if (component) {
const { steps, previousStep, triggerNextStep } = this.props;
return React.cloneElement(component, {
step,
steps,
previousStep,
triggerNextStep,
});
}
message = message.replace(/{previousValue}/g, previousValue);
if(step.inputAttributes && step.inputAttributes.secureTextEntry){
return '*'.repeat(message.length)
}
return message;
}
render() {
const {
step,
isFirst,
isLast,
avatarStyle,
avatarWrapperStyle,
bubbleStyle,
userBubbleStyle,
hideBotAvatar,
hideUserAvatar,
} = this.props;
const {
avatar,
bubbleColor,
fontColor,
user,
} = step;
const showAvatar = user ? !hideUserAvatar : !hideBotAvatar;
return (
<TextStepContainer
className="rsc-ts"
user={user}
>
{
isFirst && showAvatar &&
<ImageContainer
className="rsc-ts-image-container"
borderColor={bubbleColor}
style={avatarWrapperStyle}
user={user}
>
<Img
className="rsc-ts-image"
style={avatarStyle}
showAvatar={showAvatar}
user={user}
source={{ uri: avatar }}
alt="avatar"
/>
</ImageContainer>
}
<Bubble
className="rsc-ts-bubble"
style={user ? userBubbleStyle || bubbleStyle : bubbleStyle}
user={user}
bubbleColor={bubbleColor}
showAvatar={showAvatar}
isFirst={isFirst}
isLast={isLast}
>
{ this.state.loading && <Loading color={fontColor} /> }
{
!this.state.loading &&
<TextMessage
className="rsc-ts-text"
fontColor={fontColor}
>
{this.renderMessage()}
</TextMessage>
}
</Bubble>
</TextStepContainer>
);
}
}
TextStep.propTypes = {
isFirst: PropTypes.bool.isRequired,
isLast: PropTypes.bool.isRequired,
step: PropTypes.object.isRequired,
triggerNextStep: PropTypes.func.isRequired,
avatarStyle: PropTypes.object.isRequired,
avatarWrapperStyle: PropTypes.object,
bubbleStyle: PropTypes.object.isRequired,
userBubbleStyle: PropTypes.object.isRequired,
hideBotAvatar: PropTypes.bool.isRequired,
hideUserAvatar: PropTypes.bool.isRequired,
previousStep: PropTypes.object,
previousValue: PropTypes.any,
steps: PropTypes.object,
};
TextStep.defaultProps = {
previousStep: {},
steps: {},
previousValue: '',
avatarWrapperStyle: {}
};
export default TextStep;