react-native-my-survey-sdk 2.2.38 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/XeboDropdownView.d.ts +10 -0
- package/dist/components/XeboDropdownView.d.ts.map +1 -0
- package/dist/components/XeboDropdownView.js +190 -0
- package/dist/components/XeboIntroView.d.ts +9 -0
- package/dist/components/XeboIntroView.d.ts.map +1 -0
- package/dist/components/XeboIntroView.js +54 -0
- package/dist/components/XeboMultiNPSView.d.ts +10 -0
- package/dist/components/XeboMultiNPSView.d.ts.map +1 -0
- package/dist/components/XeboMultiNPSView.js +170 -0
- package/dist/components/XeboMultiRatingView.d.ts +10 -0
- package/dist/components/XeboMultiRatingView.d.ts.map +1 -0
- package/dist/components/XeboMultiRatingView.js +154 -0
- package/dist/components/XeboMultipleChoiceView.d.ts +10 -0
- package/dist/components/XeboMultipleChoiceView.d.ts.map +1 -0
- package/dist/components/XeboMultipleChoiceView.js +188 -0
- package/dist/components/XeboNPSView.d.ts +10 -0
- package/dist/components/XeboNPSView.d.ts.map +1 -0
- package/dist/components/XeboNPSView.js +269 -0
- package/dist/components/XeboRatingView.d.ts +10 -0
- package/dist/components/XeboRatingView.d.ts.map +1 -0
- package/dist/components/XeboRatingView.js +248 -0
- package/dist/components/XeboSingleChoiceView.d.ts +10 -0
- package/dist/components/XeboSingleChoiceView.d.ts.map +1 -0
- package/dist/components/XeboSingleChoiceView.js +172 -0
- package/dist/components/XeboSurveyModal.d.ts +3 -0
- package/dist/components/XeboSurveyModal.d.ts.map +1 -0
- package/dist/components/XeboSurveyModal.js +345 -0
- package/dist/components/XeboTextBoxView.d.ts +10 -0
- package/dist/components/XeboTextBoxView.d.ts.map +1 -0
- package/dist/components/XeboTextBoxView.js +176 -0
- package/dist/components/XeboThankYouView.d.ts +9 -0
- package/dist/components/XeboThankYouView.d.ts.map +1 -0
- package/dist/components/XeboThankYouView.js +115 -0
- package/dist/core/XeboNetworkService.d.ts +34 -0
- package/dist/core/XeboNetworkService.d.ts.map +1 -0
- package/dist/core/XeboNetworkService.js +367 -0
- package/dist/core/XeboOfflineQueue.d.ts +8 -0
- package/dist/core/XeboOfflineQueue.d.ts.map +1 -0
- package/dist/core/XeboOfflineQueue.js +35 -0
- package/dist/core/XeboSurveyManager.d.ts +59 -0
- package/dist/core/XeboSurveyManager.d.ts.map +1 -0
- package/dist/core/XeboSurveyManager.js +351 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/models/XeboAPIModels.d.ts +82 -0
- package/dist/models/XeboAPIModels.d.ts.map +1 -0
- package/dist/models/XeboAPIModels.js +4 -0
- package/dist/models/XeboModels.d.ts +141 -0
- package/dist/models/XeboModels.d.ts.map +1 -0
- package/dist/models/XeboModels.js +17 -0
- package/dist/theme/XeboTheme.d.ts +11 -0
- package/dist/theme/XeboTheme.d.ts.map +1 -0
- package/dist/theme/XeboTheme.js +25 -0
- package/package.json +10 -3
- package/babel.config.js +0 -4
- package/src/components/XeboDropdownView.tsx +0 -197
- package/src/components/XeboIntroView.tsx +0 -68
- package/src/components/XeboMultiNPSView.tsx +0 -166
- package/src/components/XeboMultiRatingView.tsx +0 -165
- package/src/components/XeboMultipleChoiceView.tsx +0 -183
- package/src/components/XeboNPSView.tsx +0 -315
- package/src/components/XeboRatingView.tsx +0 -267
- package/src/components/XeboSingleChoiceView.tsx +0 -168
- package/src/components/XeboSurveyModal.tsx +0 -360
- package/src/components/XeboTextBoxView.tsx +0 -188
- package/src/components/XeboThankYouView.tsx +0 -100
- package/src/core/XeboNetworkService.ts +0 -476
- package/src/core/XeboOfflineQueue.ts +0 -33
- package/src/core/XeboSurveyManager.ts +0 -422
- package/src/index.ts +0 -23
- package/src/models/XeboAPIModels.ts +0 -80
- package/src/models/XeboModels.ts +0 -169
- package/src/theme/XeboTheme.ts +0 -33
- package/tsconfig.json +0 -17
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.configureTheme = configureTheme;
|
|
4
|
+
exports.getTheme = getTheme;
|
|
5
|
+
const defaultTheme = {
|
|
6
|
+
primaryColor: '#4F46E5',
|
|
7
|
+
backgroundColor: '#FFFFFF',
|
|
8
|
+
textColor: '#1F2937',
|
|
9
|
+
cornerRadius: 12,
|
|
10
|
+
fontFamily: undefined,
|
|
11
|
+
};
|
|
12
|
+
let currentTheme = Object.assign({}, defaultTheme);
|
|
13
|
+
function configureTheme(config) {
|
|
14
|
+
var _a, _b, _c, _d, _e;
|
|
15
|
+
currentTheme = {
|
|
16
|
+
primaryColor: (_a = config.primaryColor) !== null && _a !== void 0 ? _a : defaultTheme.primaryColor,
|
|
17
|
+
backgroundColor: (_b = config.backgroundColor) !== null && _b !== void 0 ? _b : defaultTheme.backgroundColor,
|
|
18
|
+
textColor: (_c = config.textColor) !== null && _c !== void 0 ? _c : defaultTheme.textColor,
|
|
19
|
+
cornerRadius: (_d = config.cornerRadius) !== null && _d !== void 0 ? _d : defaultTheme.cornerRadius,
|
|
20
|
+
fontFamily: (_e = config.fontFamily) !== null && _e !== void 0 ? _e : defaultTheme.fontFamily,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function getTheme() {
|
|
24
|
+
return currentTheme;
|
|
25
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-my-survey-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "Xebo survey collection SDK for React Native",
|
|
5
|
-
"main": "
|
|
6
|
-
"types": "
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
7
10
|
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"prepublishOnly": "npm run build",
|
|
8
13
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
14
|
},
|
|
10
15
|
"author": "Xebo",
|
|
@@ -21,11 +26,13 @@
|
|
|
21
26
|
},
|
|
22
27
|
"devDependencies": {
|
|
23
28
|
"@babel/runtime": "^7.29.2",
|
|
29
|
+
"@react-native-async-storage/async-storage": "^2.0.0",
|
|
24
30
|
"@react-native-community/netinfo": "^11.4.1",
|
|
25
31
|
"@types/react": "^18.2.0",
|
|
26
32
|
"@types/react-native": "^0.73.0",
|
|
27
33
|
"react-native": "^0.73.0",
|
|
28
34
|
"react-native-device-info": "^10.13.2",
|
|
35
|
+
"react-native-modal": "^13.0.0",
|
|
29
36
|
"typescript": "^5.3.0"
|
|
30
37
|
}
|
|
31
38
|
}
|
package/babel.config.js
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import React, { useRef, useState } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
View,
|
|
4
|
-
Text,
|
|
5
|
-
TouchableOpacity,
|
|
6
|
-
StyleSheet,
|
|
7
|
-
ScrollView,
|
|
8
|
-
Animated,
|
|
9
|
-
} from 'react-native';
|
|
10
|
-
import { XeboQuestion, XeboAnswer, XeboChoice } from '../models/XeboModels';
|
|
11
|
-
import { getTheme } from '../theme/XeboTheme';
|
|
12
|
-
|
|
13
|
-
interface Props {
|
|
14
|
-
question: XeboQuestion;
|
|
15
|
-
isLastQuestion: boolean;
|
|
16
|
-
onAnswer: (answer: XeboAnswer) => void;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const XeboDropdownView: React.FC<Props> = ({ question, isLastQuestion, onAnswer }) => {
|
|
20
|
-
const theme = getTheme();
|
|
21
|
-
const [selectedChoice, setSelectedChoice] = useState<XeboChoice | null>(null);
|
|
22
|
-
const [isOpen, setIsOpen] = useState(false);
|
|
23
|
-
const [error, setError] = useState('');
|
|
24
|
-
const shakeAnim = useRef(new Animated.Value(0)).current;
|
|
25
|
-
|
|
26
|
-
const shake = () => {
|
|
27
|
-
Animated.sequence([
|
|
28
|
-
Animated.timing(shakeAnim, { toValue: 8, duration: 60, useNativeDriver: true }),
|
|
29
|
-
Animated.timing(shakeAnim, { toValue: -8, duration: 60, useNativeDriver: true }),
|
|
30
|
-
Animated.timing(shakeAnim, { toValue: 6, duration: 60, useNativeDriver: true }),
|
|
31
|
-
Animated.timing(shakeAnim, { toValue: 0, duration: 60, useNativeDriver: true }),
|
|
32
|
-
]).start();
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const handleSelect = (choice: XeboChoice) => {
|
|
36
|
-
setSelectedChoice(choice);
|
|
37
|
-
setIsOpen(false);
|
|
38
|
-
setError('');
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const handleNext = () => {
|
|
42
|
-
if (question.isRequired && !selectedChoice) {
|
|
43
|
-
setError('Please select an option.');
|
|
44
|
-
shake();
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
onAnswer({
|
|
48
|
-
questionId: question.id,
|
|
49
|
-
value: selectedChoice ? [{ rowId: selectedChoice.id, text: selectedChoice.text }] : [],
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
return (
|
|
54
|
-
<View style={styles.container}>
|
|
55
|
-
<Text style={[styles.title, { color: theme.textColor, fontFamily: theme.fontFamily }]}>
|
|
56
|
-
{question.title}
|
|
57
|
-
</Text>
|
|
58
|
-
{!!question.subtitle && (
|
|
59
|
-
<Text style={[styles.subtitle, { color: theme.textColor, fontFamily: theme.fontFamily }]}>
|
|
60
|
-
{question.subtitle}
|
|
61
|
-
</Text>
|
|
62
|
-
)}
|
|
63
|
-
|
|
64
|
-
<Animated.View style={{ transform: [{ translateX: shakeAnim }] }}>
|
|
65
|
-
<TouchableOpacity
|
|
66
|
-
style={[styles.trigger, { borderColor: isOpen ? theme.primaryColor : '#E5E7EB', borderRadius: theme.cornerRadius }]}
|
|
67
|
-
onPress={() => setIsOpen(prev => !prev)}
|
|
68
|
-
activeOpacity={0.8}
|
|
69
|
-
>
|
|
70
|
-
<Text
|
|
71
|
-
style={[
|
|
72
|
-
styles.triggerText,
|
|
73
|
-
{ color: selectedChoice ? theme.textColor : '#9CA3AF', fontFamily: theme.fontFamily },
|
|
74
|
-
]}
|
|
75
|
-
>
|
|
76
|
-
{selectedChoice ? selectedChoice.text : (question.placeholder || 'Select an option')}
|
|
77
|
-
</Text>
|
|
78
|
-
<Text style={[styles.chevron, { color: theme.textColor }]}>{isOpen ? '▲' : '▼'}</Text>
|
|
79
|
-
</TouchableOpacity>
|
|
80
|
-
</Animated.View>
|
|
81
|
-
|
|
82
|
-
{isOpen && (
|
|
83
|
-
<View style={[styles.optionsList, { borderColor: theme.primaryColor, borderRadius: theme.cornerRadius }]}>
|
|
84
|
-
<ScrollView nestedScrollEnabled style={styles.optionsScroll} showsVerticalScrollIndicator={false}>
|
|
85
|
-
{(question.options ?? []).map((choice: XeboChoice) => (
|
|
86
|
-
<TouchableOpacity
|
|
87
|
-
key={choice.id}
|
|
88
|
-
style={[
|
|
89
|
-
styles.optionRow,
|
|
90
|
-
selectedChoice?.id === choice.id && { backgroundColor: `${theme.primaryColor}15` },
|
|
91
|
-
]}
|
|
92
|
-
onPress={() => handleSelect(choice)}
|
|
93
|
-
activeOpacity={0.7}
|
|
94
|
-
>
|
|
95
|
-
<Text
|
|
96
|
-
style={[
|
|
97
|
-
styles.optionText,
|
|
98
|
-
{
|
|
99
|
-
color: selectedChoice?.id === choice.id ? theme.primaryColor : theme.textColor,
|
|
100
|
-
fontFamily: theme.fontFamily,
|
|
101
|
-
fontWeight: selectedChoice?.id === choice.id ? '600' : '400',
|
|
102
|
-
},
|
|
103
|
-
]}
|
|
104
|
-
>
|
|
105
|
-
{choice.text}
|
|
106
|
-
</Text>
|
|
107
|
-
</TouchableOpacity>
|
|
108
|
-
))}
|
|
109
|
-
</ScrollView>
|
|
110
|
-
</View>
|
|
111
|
-
)}
|
|
112
|
-
|
|
113
|
-
{!!error && <Text style={styles.errorText}>{error}</Text>}
|
|
114
|
-
|
|
115
|
-
<TouchableOpacity
|
|
116
|
-
style={[
|
|
117
|
-
styles.button,
|
|
118
|
-
{ backgroundColor: theme.primaryColor, borderRadius: theme.cornerRadius },
|
|
119
|
-
(question.isRequired && !selectedChoice) && styles.buttonDisabled,
|
|
120
|
-
]}
|
|
121
|
-
onPress={handleNext}
|
|
122
|
-
activeOpacity={0.8}
|
|
123
|
-
>
|
|
124
|
-
<Text style={[styles.buttonText, { fontFamily: theme.fontFamily }]}>
|
|
125
|
-
{isLastQuestion ? 'Submit' : 'Next'}
|
|
126
|
-
</Text>
|
|
127
|
-
</TouchableOpacity>
|
|
128
|
-
</View>
|
|
129
|
-
);
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
const styles = StyleSheet.create({
|
|
133
|
-
container: {
|
|
134
|
-
paddingHorizontal: 20,
|
|
135
|
-
paddingTop: 16,
|
|
136
|
-
paddingBottom: 24,
|
|
137
|
-
},
|
|
138
|
-
title: {
|
|
139
|
-
fontSize: 18,
|
|
140
|
-
fontWeight: '700',
|
|
141
|
-
marginBottom: 16,
|
|
142
|
-
},
|
|
143
|
-
subtitle: {
|
|
144
|
-
fontSize: 14,
|
|
145
|
-
opacity: 0.6,
|
|
146
|
-
marginBottom: 16,
|
|
147
|
-
},
|
|
148
|
-
trigger: {
|
|
149
|
-
flexDirection: 'row',
|
|
150
|
-
alignItems: 'center',
|
|
151
|
-
borderWidth: 1.5,
|
|
152
|
-
padding: 14,
|
|
153
|
-
},
|
|
154
|
-
triggerText: {
|
|
155
|
-
fontSize: 15,
|
|
156
|
-
flex: 1,
|
|
157
|
-
},
|
|
158
|
-
chevron: {
|
|
159
|
-
fontSize: 12,
|
|
160
|
-
},
|
|
161
|
-
optionsList: {
|
|
162
|
-
borderWidth: 1.5,
|
|
163
|
-
maxHeight: 200,
|
|
164
|
-
marginTop: 6,
|
|
165
|
-
marginBottom: 12,
|
|
166
|
-
},
|
|
167
|
-
optionsScroll: {
|
|
168
|
-
flexGrow: 0,
|
|
169
|
-
},
|
|
170
|
-
optionRow: {
|
|
171
|
-
padding: 14,
|
|
172
|
-
borderBottomWidth: 1,
|
|
173
|
-
borderBottomColor: '#F3F4F6',
|
|
174
|
-
},
|
|
175
|
-
optionText: {
|
|
176
|
-
fontSize: 15,
|
|
177
|
-
},
|
|
178
|
-
errorText: {
|
|
179
|
-
color: '#EF4444',
|
|
180
|
-
fontSize: 13,
|
|
181
|
-
marginTop: 6,
|
|
182
|
-
marginBottom: 4,
|
|
183
|
-
},
|
|
184
|
-
button: {
|
|
185
|
-
paddingVertical: 14,
|
|
186
|
-
alignItems: 'center',
|
|
187
|
-
marginTop: 16,
|
|
188
|
-
},
|
|
189
|
-
buttonDisabled: {
|
|
190
|
-
opacity: 0.4,
|
|
191
|
-
},
|
|
192
|
-
buttonText: {
|
|
193
|
-
color: '#FFFFFF',
|
|
194
|
-
fontSize: 16,
|
|
195
|
-
fontWeight: '600',
|
|
196
|
-
},
|
|
197
|
-
});
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { View, Text, TouchableOpacity, StyleSheet, ScrollView } from 'react-native';
|
|
3
|
-
import { XeboSurveyPage } from '../models/XeboModels';
|
|
4
|
-
import { getTheme } from '../theme/XeboTheme';
|
|
5
|
-
|
|
6
|
-
interface Props {
|
|
7
|
-
introPage: XeboSurveyPage;
|
|
8
|
-
onStart: () => void;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const XeboIntroView: React.FC<Props> = ({ introPage, onStart }) => {
|
|
12
|
-
const theme = getTheme();
|
|
13
|
-
|
|
14
|
-
return (
|
|
15
|
-
<View style={styles.outer}>
|
|
16
|
-
{!!introPage.content && (
|
|
17
|
-
<ScrollView
|
|
18
|
-
style={styles.scroll}
|
|
19
|
-
showsVerticalScrollIndicator={false}
|
|
20
|
-
contentContainerStyle={styles.scrollContent}
|
|
21
|
-
>
|
|
22
|
-
<Text style={[styles.content, { color: theme.textColor, fontFamily: theme.fontFamily }]}>
|
|
23
|
-
{introPage.content}
|
|
24
|
-
</Text>
|
|
25
|
-
</ScrollView>
|
|
26
|
-
)}
|
|
27
|
-
|
|
28
|
-
<TouchableOpacity
|
|
29
|
-
style={[styles.button, { backgroundColor: theme.primaryColor, borderRadius: theme.cornerRadius }]}
|
|
30
|
-
onPress={onStart}
|
|
31
|
-
activeOpacity={0.8}
|
|
32
|
-
>
|
|
33
|
-
<Text style={[styles.buttonText, { fontFamily: theme.fontFamily }]}>
|
|
34
|
-
{introPage.buttonText || "Let's get started"}
|
|
35
|
-
</Text>
|
|
36
|
-
</TouchableOpacity>
|
|
37
|
-
</View>
|
|
38
|
-
);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const styles = StyleSheet.create({
|
|
42
|
-
outer: {
|
|
43
|
-
paddingHorizontal: 20,
|
|
44
|
-
paddingTop: 8,
|
|
45
|
-
paddingBottom: 24,
|
|
46
|
-
},
|
|
47
|
-
scroll: {
|
|
48
|
-
maxHeight: 220,
|
|
49
|
-
marginBottom: 4,
|
|
50
|
-
},
|
|
51
|
-
scrollContent: {
|
|
52
|
-
paddingBottom: 8,
|
|
53
|
-
},
|
|
54
|
-
content: {
|
|
55
|
-
fontSize: 16,
|
|
56
|
-
lineHeight: 26,
|
|
57
|
-
},
|
|
58
|
-
button: {
|
|
59
|
-
paddingVertical: 14,
|
|
60
|
-
alignItems: 'center',
|
|
61
|
-
marginTop: 16,
|
|
62
|
-
},
|
|
63
|
-
buttonText: {
|
|
64
|
-
color: '#FFFFFF',
|
|
65
|
-
fontSize: 16,
|
|
66
|
-
fontWeight: '600',
|
|
67
|
-
},
|
|
68
|
-
});
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import React, { useRef, useState } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
View,
|
|
4
|
-
Text,
|
|
5
|
-
TouchableOpacity,
|
|
6
|
-
StyleSheet,
|
|
7
|
-
ScrollView,
|
|
8
|
-
Animated,
|
|
9
|
-
} from 'react-native';
|
|
10
|
-
import { XeboQuestion, XeboAnswer } from '../models/XeboModels';
|
|
11
|
-
import { getTheme } from '../theme/XeboTheme';
|
|
12
|
-
|
|
13
|
-
interface Props {
|
|
14
|
-
question: XeboQuestion;
|
|
15
|
-
isLastQuestion: boolean;
|
|
16
|
-
onAnswer: (answer: XeboAnswer) => void;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const DETRACTOR_COLOR = '#F24236';
|
|
20
|
-
const PASSIVE_COLOR = '#FFC208';
|
|
21
|
-
const PROMOTER_COLOR = '#2ECC70';
|
|
22
|
-
|
|
23
|
-
function npsColor(score: number, npsLabels?: XeboQuestion['npsLabels']): string {
|
|
24
|
-
if (score <= 6) return npsLabels?.detractorColor ?? DETRACTOR_COLOR;
|
|
25
|
-
if (score <= 8) return npsLabels?.passiveColor ?? PASSIVE_COLOR;
|
|
26
|
-
return npsLabels?.promoterColor ?? PROMOTER_COLOR;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function isColorDark(hex: string): boolean {
|
|
30
|
-
const m = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
31
|
-
if (!m) return false;
|
|
32
|
-
const r = parseInt(m[1], 16) / 255;
|
|
33
|
-
const g = parseInt(m[2], 16) / 255;
|
|
34
|
-
const b = parseInt(m[3], 16) / 255;
|
|
35
|
-
return 0.299 * r + 0.587 * g + 0.114 * b < 0.5;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export const XeboMultiNPSView: React.FC<Props> = ({ question, isLastQuestion, onAnswer }) => {
|
|
39
|
-
const theme = getTheme();
|
|
40
|
-
const rows = question.options ?? [];
|
|
41
|
-
const [scores, setScores] = useState<Record<string, number>>({});
|
|
42
|
-
const [error, setError] = useState('');
|
|
43
|
-
const shakeAnim = useRef(new Animated.Value(0)).current;
|
|
44
|
-
|
|
45
|
-
const shake = () => {
|
|
46
|
-
Animated.sequence([
|
|
47
|
-
Animated.timing(shakeAnim, { toValue: 8, duration: 60, useNativeDriver: true }),
|
|
48
|
-
Animated.timing(shakeAnim, { toValue: -8, duration: 60, useNativeDriver: true }),
|
|
49
|
-
Animated.timing(shakeAnim, { toValue: 6, duration: 60, useNativeDriver: true }),
|
|
50
|
-
Animated.timing(shakeAnim, { toValue: 0, duration: 60, useNativeDriver: true }),
|
|
51
|
-
]).start();
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const setScore = (rowId: string, score: number) => {
|
|
55
|
-
setScores(prev => ({ ...prev, [rowId]: score }));
|
|
56
|
-
setError('');
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
const handleNext = () => {
|
|
60
|
-
if (question.isRequired && rows.some(r => scores[r.id] === undefined)) {
|
|
61
|
-
setError('Please rate all items.');
|
|
62
|
-
shake();
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
onAnswer({
|
|
67
|
-
questionId: question.id,
|
|
68
|
-
value: rows
|
|
69
|
-
.filter(r => scores[r.id] !== undefined)
|
|
70
|
-
.map(r => ({
|
|
71
|
-
rowId: r.id,
|
|
72
|
-
colId: (question.columns?.[scores[r.id]]?.id ?? scores[r.id].toString()),
|
|
73
|
-
})),
|
|
74
|
-
});
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
return (
|
|
78
|
-
<View style={styles.container}>
|
|
79
|
-
<Text style={[styles.title, { color: theme.textColor, fontFamily: theme.fontFamily }]}>
|
|
80
|
-
{question.title}
|
|
81
|
-
</Text>
|
|
82
|
-
{!!question.subtitle && (
|
|
83
|
-
<Text style={[styles.subtitle, { color: theme.textColor, fontFamily: theme.fontFamily }]}>
|
|
84
|
-
{question.subtitle}
|
|
85
|
-
</Text>
|
|
86
|
-
)}
|
|
87
|
-
|
|
88
|
-
<ScrollView style={styles.scroll} showsVerticalScrollIndicator={false}>
|
|
89
|
-
{rows.map(row => (
|
|
90
|
-
<View key={row.id} style={styles.rowWrap}>
|
|
91
|
-
<Text style={[styles.rowLabel, { color: theme.textColor, fontFamily: theme.fontFamily }]}>
|
|
92
|
-
{row.text}
|
|
93
|
-
</Text>
|
|
94
|
-
{/* Single-row NPS scale with always-visible category colors */}
|
|
95
|
-
<View style={styles.scaleRow}>
|
|
96
|
-
{Array.from({ length: 11 }, (_, i) => {
|
|
97
|
-
const selected = scores[row.id] === i;
|
|
98
|
-
const color = npsColor(i, question.npsLabels);
|
|
99
|
-
return (
|
|
100
|
-
<TouchableOpacity
|
|
101
|
-
key={i}
|
|
102
|
-
style={[
|
|
103
|
-
styles.scoreButton,
|
|
104
|
-
{
|
|
105
|
-
backgroundColor: color,
|
|
106
|
-
borderColor: selected ? '#000000' : color,
|
|
107
|
-
borderWidth: selected ? 2.5 : 1.5,
|
|
108
|
-
},
|
|
109
|
-
]}
|
|
110
|
-
onPress={() => setScore(row.id, i)}
|
|
111
|
-
activeOpacity={0.8}
|
|
112
|
-
>
|
|
113
|
-
<Text style={[
|
|
114
|
-
styles.scoreText,
|
|
115
|
-
{ color: isColorDark(color) ? '#FFFFFF' : selected ? '#111111' : '#444444' },
|
|
116
|
-
]}>
|
|
117
|
-
{i}
|
|
118
|
-
</Text>
|
|
119
|
-
</TouchableOpacity>
|
|
120
|
-
);
|
|
121
|
-
})}
|
|
122
|
-
</View>
|
|
123
|
-
</View>
|
|
124
|
-
))}
|
|
125
|
-
</ScrollView>
|
|
126
|
-
|
|
127
|
-
{!!error && <Text style={styles.errorText}>{error}</Text>}
|
|
128
|
-
|
|
129
|
-
<Animated.View style={{ transform: [{ translateX: shakeAnim }] }}>
|
|
130
|
-
<TouchableOpacity
|
|
131
|
-
style={[styles.button, { backgroundColor: theme.primaryColor, borderRadius: theme.cornerRadius }]}
|
|
132
|
-
onPress={handleNext}
|
|
133
|
-
activeOpacity={0.8}
|
|
134
|
-
>
|
|
135
|
-
<Text style={[styles.buttonText, { fontFamily: theme.fontFamily }]}>
|
|
136
|
-
{isLastQuestion ? 'Submit' : 'Next'}
|
|
137
|
-
</Text>
|
|
138
|
-
</TouchableOpacity>
|
|
139
|
-
</Animated.View>
|
|
140
|
-
</View>
|
|
141
|
-
);
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
const styles = StyleSheet.create({
|
|
145
|
-
container: { flex: 1, paddingHorizontal: 20, paddingTop: 16, paddingBottom: 24 },
|
|
146
|
-
title: { fontSize: 18, fontWeight: '700', marginBottom: 6 },
|
|
147
|
-
subtitle: { fontSize: 14, opacity: 0.6, marginBottom: 16 },
|
|
148
|
-
scroll: { flex: 1, minHeight: 0, marginBottom: 12 },
|
|
149
|
-
rowWrap: { marginBottom: 20 },
|
|
150
|
-
rowLabel: { fontSize: 15, fontWeight: '500', marginBottom: 8 },
|
|
151
|
-
scaleRow: {
|
|
152
|
-
flexDirection: 'row',
|
|
153
|
-
gap: 3,
|
|
154
|
-
},
|
|
155
|
-
scoreButton: {
|
|
156
|
-
flex: 1,
|
|
157
|
-
height: 40,
|
|
158
|
-
borderRadius: 5,
|
|
159
|
-
alignItems: 'center',
|
|
160
|
-
justifyContent: 'center',
|
|
161
|
-
},
|
|
162
|
-
scoreText: { fontSize: 12, fontWeight: '700' },
|
|
163
|
-
errorText: { color: '#EF4444', fontSize: 13, marginBottom: 8 },
|
|
164
|
-
button: { paddingVertical: 14, alignItems: 'center', marginTop: 4 },
|
|
165
|
-
buttonText: { color: '#FFFFFF', fontSize: 16, fontWeight: '600' },
|
|
166
|
-
});
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import React, { useRef, useState } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
View,
|
|
4
|
-
Text,
|
|
5
|
-
TouchableOpacity,
|
|
6
|
-
StyleSheet,
|
|
7
|
-
ScrollView,
|
|
8
|
-
Animated,
|
|
9
|
-
} from 'react-native';
|
|
10
|
-
import { XeboQuestion, XeboAnswer } from '../models/XeboModels';
|
|
11
|
-
import { getTheme } from '../theme/XeboTheme';
|
|
12
|
-
|
|
13
|
-
interface Props {
|
|
14
|
-
question: XeboQuestion;
|
|
15
|
-
isLastQuestion: boolean;
|
|
16
|
-
onAnswer: (answer: XeboAnswer) => void;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const XeboMultiRatingView: React.FC<Props> = ({ question, isLastQuestion, onAnswer }) => {
|
|
20
|
-
const theme = getTheme();
|
|
21
|
-
const rows = question.options ?? [];
|
|
22
|
-
const totalSteps = question.columns?.length ?? 5;
|
|
23
|
-
const ratingColor = question.ratingColor ?? theme.primaryColor;
|
|
24
|
-
const ratingStyle = question.ratingStyle ?? 'star';
|
|
25
|
-
|
|
26
|
-
const [ratings, setRatings] = useState<Record<string, number>>({});
|
|
27
|
-
const [error, setError] = useState('');
|
|
28
|
-
const shakeAnim = useRef(new Animated.Value(0)).current;
|
|
29
|
-
|
|
30
|
-
const shake = () => {
|
|
31
|
-
Animated.sequence([
|
|
32
|
-
Animated.timing(shakeAnim, { toValue: 8, duration: 60, useNativeDriver: true }),
|
|
33
|
-
Animated.timing(shakeAnim, { toValue: -8, duration: 60, useNativeDriver: true }),
|
|
34
|
-
Animated.timing(shakeAnim, { toValue: 6, duration: 60, useNativeDriver: true }),
|
|
35
|
-
Animated.timing(shakeAnim, { toValue: 0, duration: 60, useNativeDriver: true }),
|
|
36
|
-
]).start();
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const setRating = (rowId: string, index: number) => {
|
|
40
|
-
setRatings(prev => ({ ...prev, [rowId]: index }));
|
|
41
|
-
setError('');
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const isCumulative = ratingStyle === 'star' || ratingStyle === 'heart';
|
|
45
|
-
|
|
46
|
-
const handleNext = () => {
|
|
47
|
-
if (question.isRequired && rows.some(r => ratings[r.id] === undefined)) {
|
|
48
|
-
setError('Please rate all items.');
|
|
49
|
-
shake();
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
onAnswer({
|
|
54
|
-
questionId: question.id,
|
|
55
|
-
value: rows
|
|
56
|
-
.filter(r => ratings[r.id] !== undefined)
|
|
57
|
-
.map(r => ({
|
|
58
|
-
rowId: r.id,
|
|
59
|
-
colId: question.columns?.[ratings[r.id]]?.id ?? ratings[r.id].toString(),
|
|
60
|
-
})),
|
|
61
|
-
});
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const starIcon = (filled: boolean) =>
|
|
65
|
-
ratingStyle === 'heart' ? (filled ? '♥' : '♡') : filled ? '★' : '☆';
|
|
66
|
-
|
|
67
|
-
return (
|
|
68
|
-
<View style={styles.container}>
|
|
69
|
-
<Text style={[styles.title, { color: theme.textColor, fontFamily: theme.fontFamily }]}>
|
|
70
|
-
{question.title}
|
|
71
|
-
</Text>
|
|
72
|
-
{!!question.subtitle && (
|
|
73
|
-
<Text style={[styles.subtitle, { color: theme.textColor, fontFamily: theme.fontFamily }]}>
|
|
74
|
-
{question.subtitle}
|
|
75
|
-
</Text>
|
|
76
|
-
)}
|
|
77
|
-
|
|
78
|
-
<ScrollView style={styles.scroll} showsVerticalScrollIndicator={false}>
|
|
79
|
-
{rows.map(row => (
|
|
80
|
-
<View key={row.id} style={styles.rowWrap}>
|
|
81
|
-
<Text style={[styles.rowLabel, { color: theme.textColor, fontFamily: theme.fontFamily }]}>
|
|
82
|
-
{row.text}
|
|
83
|
-
</Text>
|
|
84
|
-
<View style={styles.iconsRow}>
|
|
85
|
-
{Array.from({ length: totalSteps }, (_, i) => {
|
|
86
|
-
const isFilled = isCumulative
|
|
87
|
-
? ratings[row.id] !== undefined && i <= ratings[row.id]
|
|
88
|
-
: i === ratings[row.id];
|
|
89
|
-
return (
|
|
90
|
-
<TouchableOpacity
|
|
91
|
-
key={i}
|
|
92
|
-
onPress={() => setRating(row.id, i)}
|
|
93
|
-
activeOpacity={0.7}
|
|
94
|
-
style={styles.iconButton}
|
|
95
|
-
>
|
|
96
|
-
{ratingStyle === 'circle' ? (
|
|
97
|
-
<View
|
|
98
|
-
style={[
|
|
99
|
-
styles.circle,
|
|
100
|
-
{ backgroundColor: isFilled ? ratingColor : '#E5E7EB' },
|
|
101
|
-
]}
|
|
102
|
-
/>
|
|
103
|
-
) : ratingStyle === 'tile' ? (
|
|
104
|
-
<View
|
|
105
|
-
style={[
|
|
106
|
-
styles.tile,
|
|
107
|
-
{ backgroundColor: isFilled ? ratingColor : '#E5E7EB' },
|
|
108
|
-
]}
|
|
109
|
-
>
|
|
110
|
-
<Text style={[styles.tileText, { color: isFilled ? '#FFF' : '#6B7280' }]}>
|
|
111
|
-
{i + 1}
|
|
112
|
-
</Text>
|
|
113
|
-
</View>
|
|
114
|
-
) : (
|
|
115
|
-
<Text style={{ fontSize: 30, color: isFilled ? ratingColor : '#E5E7EB' }}>
|
|
116
|
-
{starIcon(isFilled)}
|
|
117
|
-
</Text>
|
|
118
|
-
)}
|
|
119
|
-
</TouchableOpacity>
|
|
120
|
-
);
|
|
121
|
-
})}
|
|
122
|
-
</View>
|
|
123
|
-
</View>
|
|
124
|
-
))}
|
|
125
|
-
</ScrollView>
|
|
126
|
-
|
|
127
|
-
{!!error && <Text style={styles.errorText}>{error}</Text>}
|
|
128
|
-
|
|
129
|
-
<Animated.View style={{ transform: [{ translateX: shakeAnim }] }}>
|
|
130
|
-
<TouchableOpacity
|
|
131
|
-
style={[styles.button, { backgroundColor: theme.primaryColor, borderRadius: theme.cornerRadius }]}
|
|
132
|
-
onPress={handleNext}
|
|
133
|
-
activeOpacity={0.8}
|
|
134
|
-
>
|
|
135
|
-
<Text style={[styles.buttonText, { fontFamily: theme.fontFamily }]}>
|
|
136
|
-
{isLastQuestion ? 'Submit' : 'Next'}
|
|
137
|
-
</Text>
|
|
138
|
-
</TouchableOpacity>
|
|
139
|
-
</Animated.View>
|
|
140
|
-
</View>
|
|
141
|
-
);
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
const styles = StyleSheet.create({
|
|
145
|
-
container: { paddingHorizontal: 20, paddingTop: 16, paddingBottom: 24 },
|
|
146
|
-
title: { fontSize: 18, fontWeight: '700', marginBottom: 16 },
|
|
147
|
-
subtitle: { fontSize: 14, opacity: 0.6, marginBottom: 16 },
|
|
148
|
-
scroll: { maxHeight: 280, marginBottom: 12 },
|
|
149
|
-
rowWrap: { marginBottom: 24 },
|
|
150
|
-
rowLabel: { fontSize: 15, fontWeight: '500', marginBottom: 8 },
|
|
151
|
-
iconsRow: { flexDirection: 'row', flexWrap: 'nowrap', justifyContent: 'space-between' },
|
|
152
|
-
iconButton: { alignItems: 'center', justifyContent: 'center' },
|
|
153
|
-
circle: { width: 36, height: 36, borderRadius: 18 },
|
|
154
|
-
tile: {
|
|
155
|
-
width: 40,
|
|
156
|
-
height: 40,
|
|
157
|
-
borderRadius: 6,
|
|
158
|
-
alignItems: 'center',
|
|
159
|
-
justifyContent: 'center',
|
|
160
|
-
},
|
|
161
|
-
tileText: { fontSize: 13, fontWeight: '700' },
|
|
162
|
-
errorText: { color: '#EF4444', fontSize: 13, marginBottom: 8 },
|
|
163
|
-
button: { paddingVertical: 14, alignItems: 'center', marginTop: 4 },
|
|
164
|
-
buttonText: { color: '#FFFFFF', fontSize: 16, fontWeight: '600' },
|
|
165
|
-
});
|