/
HintsScreen.tsx
224 lines (204 loc) · 7.03 KB
/
HintsScreen.tsx
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
import _ from 'lodash';
import React, {Component} from 'react';
import {Alert, ViewStyle} from 'react-native';
import {Colors, View, Text, Hint, Button, Assets, Incubator} from 'react-native-ui-lib';
import {renderMultipleSegmentOptions, renderBooleanOption} from '../ExampleScreenPresenter';
const settingsIcon = require('../../assets/icons/settings.png');
const reactions = ['❤️', '😮', '😔', '😂', '😡'];
type HintScreenProps = {};
export default class HintsScreen extends Component<HintScreenProps> {
state = {
showHint: true,
useShortMessage: false,
showBottomHint: false,
showIcon: false,
targetPosition: 'flex-start' as ViewStyle['alignSelf'],
useBackdrop: true,
useTargetFrame: false,
useSideTip: false,
showCustomContent: false,
showReactionStrip: false,
enableShadow: false
};
toggleHint = () => {
this.setState({showHint: !this.state.showHint});
};
toggleHintPosition = () => {
this.setState({
showBottomHint: !this.state.showBottomHint
});
};
onHintPressed = () => {
Alert.alert('Hint Pressed');
};
onReactionPress = () => {
Alert.alert('Reaction button pressed');
};
renderCustomContent() {
return (
<Text text70 $textDefaultLight>
Click
<Text onPress={() => Alert.alert('custom content :)')} text70BO red40>
{' here '}
</Text>
for more information
</Text>
);
}
renderReactionStrip() {
return (
<View row padding-8>
{_.map(reactions, (item, index) => (
<Button round link key={index} label={item} onPress={this.onReactionPress}/>
))}
</View>
);
}
renderOptionsFAB() {
return (
<View absR absB padding-page style={{zIndex: 10}}>
<Incubator.ExpandableOverlay
useDialog
expandableContent={this.renderScreenOptions()}
dialogProps={{bottom: true, useSafeArea: true}}
>
<Button round iconSource={Assets.icons.demo.settings} $backgroundDefault/>
</Incubator.ExpandableOverlay>
</View>
);
}
renderScreenOptions() {
return (
<View bg-$backgroundDefault br20 padding-20 collapsable={false}>
<Text h2 marginB-s4>
Hint Options
</Text>
{renderMultipleSegmentOptions.call(this, 'Button Position', 'targetPosition', [
{label: 'Left', value: 'flex-start'},
{label: 'Center', value: 'center'},
{label: 'Right', value: 'flex-end'}
])}
{renderMultipleSegmentOptions.call(this, 'Tip Position', 'useSideTip', [
{label: 'Side Tip', value: true},
{label: 'Middle Top', value: false}
])}
{renderMultipleSegmentOptions.call(this, 'Hint Position', 'showBottomHint', [
{label: 'Above', value: false},
{label: 'Under', value: true}
])}
{renderMultipleSegmentOptions.call(this, 'Message Length', 'useShortMessage', [
{label: 'Short', value: true},
{label: 'Long', value: false}
])}
{renderBooleanOption.call(this, 'With backdrop', 'useBackdrop')}
{renderBooleanOption.call(this, 'With icon', 'showIcon')}
{renderBooleanOption.call(this, 'With shadow', 'enableShadow')}
{renderBooleanOption.call(this, 'Use random position', 'useTargetFrame')}
{renderBooleanOption.call(this, 'Show custom content', 'showCustomContent')}
{renderBooleanOption.call(this, 'Show reaction strip', 'showReactionStrip')}
</View>
);
}
render() {
const {
showHint,
showBottomHint,
showIcon,
targetPosition,
useBackdrop,
useShortMessage,
useSideTip,
useTargetFrame,
showCustomContent,
showReactionStrip,
enableShadow
} = this.state;
const targetFrame = {x: 140, y: 100, width: 10, height: 10};
const message = useShortMessage
? 'Add other cool and useful stuff.'
: 'Add other cool and useful stuff through adding apps to your visitors to enjoy.';
const color = !showCustomContent && showReactionStrip ? {color: Colors.$backgroundDefault} : undefined;
return (
<View flex>
<View
flex
padding-20
paddingT-100
bg-$backgroundNeutralLight
style={{zIndex: 10}}
key={useTargetFrame ? 'withTargetFrame' : 'withElement'}
>
{/* <Button bg-purple30 label="Background" style={{position: 'absolute', right: 50, bottom: 100}}/> */}
<Hint
visible={showHint}
// color={Colors.$backgroundMajorHeavy}
message={message}
// message={
// <Text>
// {message}{' '}
// <Text style={{textDecorationLine: 'underline'}} onPress={() => {}}>
// click here
// </Text>
// </Text>
// }
// messageStyle={{color: 'red'}}
icon={showIcon ? settingsIcon : undefined}
// iconStyle={{tintColor: 'red'}}
// offset={35}
position={showBottomHint ? Hint.positions.BOTTOM : Hint.positions.TOP}
useSideTip={useSideTip}
key={targetPosition}
onPress={this.onHintPressed}
targetFrame={useTargetFrame ? targetFrame : undefined}
// borderRadius={BorderRadiuses.br40}
// edgeMargins={30}
onBackgroundPress={useBackdrop && !useTargetFrame ? this.toggleHint : undefined}
backdropColor={Colors.rgba(Colors.$backgroundInverted, 0.3)}
customContent={
showCustomContent
? this.renderCustomContent()
: showReactionStrip
? this.renderReactionStrip()
: undefined
}
{...color}
removePaddings={!showCustomContent && showReactionStrip}
enableShadow={enableShadow}
testID={'Hint'}
>
{!useTargetFrame && (
<Button
label={showHint ? 'Hide' : 'Show'}
onPress={this.toggleHint}
style={{alignSelf: targetPosition}}
testID={'Hint.button'}
/* Change layout and position to test various cases */
// marginT-150
// style={{alignSelf: targetPosition, marginLeft: 30}}
// style={{alignSelf: targetPosition, position: 'absolute', top: 160, left: 100}}
/>
)}
</Hint>
{useTargetFrame && (
<>
<View
bg-red50
style={{
position: 'absolute',
top: targetFrame.y,
left: targetFrame.x,
width: targetFrame.width,
height: targetFrame.height
}}
/>
<View absL absB margin-page>
<Button label="Show Hint" onPress={this.toggleHint}/>
</View>
</>
)}
</View>
{this.renderOptionsFAB()}
</View>
);
}
}