react-native-my-survey-sdk 3.0.0 → 3.0.2
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 +249 -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
|
@@ -1,360 +0,0 @@
|
|
|
1
|
-
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
Animated,
|
|
4
|
-
Keyboard,
|
|
5
|
-
View,
|
|
6
|
-
Text,
|
|
7
|
-
TouchableOpacity,
|
|
8
|
-
StyleSheet,
|
|
9
|
-
Dimensions,
|
|
10
|
-
Platform,
|
|
11
|
-
useWindowDimensions,
|
|
12
|
-
} from 'react-native';
|
|
13
|
-
import RNModal from 'react-native-modal';
|
|
14
|
-
import { XeboSurveyManager, XEBO_EVENTS } from '../core/XeboSurveyManager';
|
|
15
|
-
import {
|
|
16
|
-
XeboSurvey,
|
|
17
|
-
XeboAnswer,
|
|
18
|
-
XeboQuestion,
|
|
19
|
-
XeboQuestionType,
|
|
20
|
-
} from '../models/XeboModels';
|
|
21
|
-
import { getTheme } from '../theme/XeboTheme';
|
|
22
|
-
|
|
23
|
-
import { XeboIntroView } from './XeboIntroView';
|
|
24
|
-
import { XeboThankYouView } from './XeboThankYouView';
|
|
25
|
-
import { XeboSingleChoiceView } from './XeboSingleChoiceView';
|
|
26
|
-
import { XeboMultipleChoiceView } from './XeboMultipleChoiceView';
|
|
27
|
-
import { XeboDropdownView } from './XeboDropdownView';
|
|
28
|
-
import { XeboTextBoxView } from './XeboTextBoxView';
|
|
29
|
-
import { XeboNPSView } from './XeboNPSView';
|
|
30
|
-
import { XeboMultiNPSView } from './XeboMultiNPSView';
|
|
31
|
-
import { XeboRatingView } from './XeboRatingView';
|
|
32
|
-
import { XeboMultiRatingView } from './XeboMultiRatingView';
|
|
33
|
-
|
|
34
|
-
function computeSheetHeight(question: XeboQuestion | null, screen: ModalScreen, sh: number): number {
|
|
35
|
-
if (screen === 'thankYou') return sh * 0.30;
|
|
36
|
-
if (screen === 'intro') return sh * 0.38;
|
|
37
|
-
if (!question) return sh * 0.45;
|
|
38
|
-
switch (question.type) {
|
|
39
|
-
case XeboQuestionType.multiNps:
|
|
40
|
-
case XeboQuestionType.multiRating: {
|
|
41
|
-
const rowCount = question.options?.length ?? 3;
|
|
42
|
-
return Math.min(sh * 0.75, sh * (0.25 + rowCount * 0.13));
|
|
43
|
-
}
|
|
44
|
-
case XeboQuestionType.nps:
|
|
45
|
-
return (question.conditionalFollowUps?.length ?? 0) > 0
|
|
46
|
-
? sh * 0.60
|
|
47
|
-
: sh * 0.38;
|
|
48
|
-
case XeboQuestionType.rating:
|
|
49
|
-
return question.followUpQuestion ? sh * 0.55 : sh * 0.38;
|
|
50
|
-
case XeboQuestionType.singleTextBox:
|
|
51
|
-
return sh * 0.38;
|
|
52
|
-
case XeboQuestionType.multipleTextBox: {
|
|
53
|
-
const fieldCount = question.options?.length ?? 1;
|
|
54
|
-
return Math.min(sh * 0.70, sh * (0.28 + fieldCount * 0.10));
|
|
55
|
-
}
|
|
56
|
-
case XeboQuestionType.dropdown:
|
|
57
|
-
return sh * 0.62;
|
|
58
|
-
case XeboQuestionType.singleChoice:
|
|
59
|
-
case XeboQuestionType.multipleChoice: {
|
|
60
|
-
const optCount = question.options?.length ?? 0;
|
|
61
|
-
return Math.min(sh * 0.75, sh * (0.26 + optCount * 0.08));
|
|
62
|
-
}
|
|
63
|
-
default:
|
|
64
|
-
return sh * 0.45;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
type ModalScreen = 'intro' | 'question' | 'thankYou';
|
|
69
|
-
|
|
70
|
-
export const XeboSurveyModal: React.FC = () => {
|
|
71
|
-
const theme = getTheme();
|
|
72
|
-
// Always get the live window dimensions — fixes stale height on Android first open
|
|
73
|
-
const { height: windowHeight } = useWindowDimensions();
|
|
74
|
-
const screenDims = Dimensions.get('screen');
|
|
75
|
-
const androidNavBar = Platform.OS === 'android'
|
|
76
|
-
? Math.max(0, screenDims.height - windowHeight)
|
|
77
|
-
: 0;
|
|
78
|
-
const bottomInset = Platform.OS === 'ios' ? 34 : Math.max(34, androidNavBar);
|
|
79
|
-
|
|
80
|
-
// Slides the sheet above the keyboard when any TextInput is focused.
|
|
81
|
-
const shiftAnim = useRef(new Animated.Value(0)).current;
|
|
82
|
-
const sheetHeightRef = useRef(0);
|
|
83
|
-
|
|
84
|
-
const [visible, setVisible] = useState(false);
|
|
85
|
-
const [survey, setSurvey] = useState<XeboSurvey | null>(null);
|
|
86
|
-
const [screen, setScreen] = useState<ModalScreen>('intro');
|
|
87
|
-
const [questionIndex, setQuestionIndex] = useState(0);
|
|
88
|
-
|
|
89
|
-
const sheetHeight = useMemo(
|
|
90
|
-
() => computeSheetHeight(survey?.questions[questionIndex] ?? null, screen, windowHeight),
|
|
91
|
-
[survey, questionIndex, screen, windowHeight]
|
|
92
|
-
);
|
|
93
|
-
sheetHeightRef.current = sheetHeight;
|
|
94
|
-
|
|
95
|
-
// ─── Keyboard: slide sheet above keyboard when any TextInput focuses ──────
|
|
96
|
-
|
|
97
|
-
useEffect(() => {
|
|
98
|
-
const showEvent = Platform.OS === 'ios' ? 'keyboardWillShow' : 'keyboardDidShow';
|
|
99
|
-
const hideEvent = Platform.OS === 'ios' ? 'keyboardWillHide' : 'keyboardDidHide';
|
|
100
|
-
|
|
101
|
-
const onShow = (e: { endCoordinates: { height: number } }) => {
|
|
102
|
-
const kh = e.endCoordinates.height;
|
|
103
|
-
const maxShift = Math.max(0, windowHeight - sheetHeightRef.current);
|
|
104
|
-
Animated.timing(shiftAnim, {
|
|
105
|
-
toValue: -Math.min(kh, maxShift),
|
|
106
|
-
duration: Platform.OS === 'ios' ? 250 : 0,
|
|
107
|
-
useNativeDriver: true,
|
|
108
|
-
}).start();
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
const onHide = () => {
|
|
112
|
-
Animated.timing(shiftAnim, {
|
|
113
|
-
toValue: 0,
|
|
114
|
-
duration: Platform.OS === 'ios' ? 200 : 0,
|
|
115
|
-
useNativeDriver: true,
|
|
116
|
-
}).start();
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
const showSub = Keyboard.addListener(showEvent, onShow);
|
|
120
|
-
const hideSub = Keyboard.addListener(hideEvent, onHide);
|
|
121
|
-
return () => { showSub.remove(); hideSub.remove(); };
|
|
122
|
-
}, []); // mount-only — sheetHeightRef keeps the height current without re-subscribing
|
|
123
|
-
|
|
124
|
-
// ─── Subscribe to manager events ─────────────────────────────────────────
|
|
125
|
-
|
|
126
|
-
useEffect(() => {
|
|
127
|
-
const onLoaded = (s: XeboSurvey) => {
|
|
128
|
-
setSurvey(s);
|
|
129
|
-
setQuestionIndex(0);
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
const onVisible = (v: boolean) => {
|
|
133
|
-
if (v) {
|
|
134
|
-
// Sync survey into React state before showing so first frame isn't blank
|
|
135
|
-
const s = XeboSurveyManager.survey;
|
|
136
|
-
setSurvey(s);
|
|
137
|
-
if (s?.introPage?.enabled) {
|
|
138
|
-
setScreen('intro');
|
|
139
|
-
} else {
|
|
140
|
-
setScreen('question');
|
|
141
|
-
setQuestionIndex(XeboSurveyManager.currentQuestionIndex);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
setVisible(v);
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
const onQuestionChanged = (idx: number) => {
|
|
148
|
-
setQuestionIndex(idx);
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
XeboSurveyManager.on(XEBO_EVENTS.SURVEY_LOADED, onLoaded);
|
|
152
|
-
XeboSurveyManager.on(XEBO_EVENTS.SURVEY_VISIBLE, onVisible);
|
|
153
|
-
XeboSurveyManager.on(XEBO_EVENTS.QUESTION_CHANGED, onQuestionChanged);
|
|
154
|
-
|
|
155
|
-
return () => {
|
|
156
|
-
XeboSurveyManager.off(XEBO_EVENTS.SURVEY_LOADED, onLoaded);
|
|
157
|
-
XeboSurveyManager.off(XEBO_EVENTS.SURVEY_VISIBLE, onVisible);
|
|
158
|
-
XeboSurveyManager.off(XEBO_EVENTS.QUESTION_CHANGED, onQuestionChanged);
|
|
159
|
-
};
|
|
160
|
-
}, []);
|
|
161
|
-
|
|
162
|
-
// ─── User actions ─────────────────────────────────────────────────────────
|
|
163
|
-
|
|
164
|
-
const handleSkip = () => {
|
|
165
|
-
XeboSurveyManager.dismissSurvey();
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
const handleIntroStart = () => {
|
|
169
|
-
setScreen('question');
|
|
170
|
-
setQuestionIndex(0);
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
const handleAnswer = useCallback((answer: XeboAnswer | XeboAnswer[]) => {
|
|
174
|
-
// NPS Pro sends [npsAnswer, followUpAnswer] — record each separately
|
|
175
|
-
const answers = Array.isArray(answer) ? answer : [answer];
|
|
176
|
-
answers.forEach(a => XeboSurveyManager.recordAnswer(a));
|
|
177
|
-
XeboSurveyManager.nextQuestion();
|
|
178
|
-
const s = XeboSurveyManager.survey;
|
|
179
|
-
const newIdx = XeboSurveyManager.currentQuestionIndex;
|
|
180
|
-
if (s && s.questions[newIdx]?.id === 'thank_you_auto') {
|
|
181
|
-
setScreen('thankYou');
|
|
182
|
-
}
|
|
183
|
-
}, []);
|
|
184
|
-
|
|
185
|
-
// ─── Question renderer ────────────────────────────────────────────────────
|
|
186
|
-
|
|
187
|
-
const renderQuestion = (question: XeboQuestion) => {
|
|
188
|
-
const questions = survey?.questions ?? [];
|
|
189
|
-
const lastRealIndex = questions.findIndex(q => q.id === 'thank_you_auto') - 1;
|
|
190
|
-
const isLast = questionIndex === lastRealIndex;
|
|
191
|
-
|
|
192
|
-
// key must be passed directly (not via spread) — forces unmount/remount on question change,
|
|
193
|
-
// resetting all component state (selected score, text, etc.)
|
|
194
|
-
const commonProps = { question, isLastQuestion: isLast, onAnswer: handleAnswer };
|
|
195
|
-
|
|
196
|
-
switch (question.type) {
|
|
197
|
-
case XeboQuestionType.singleChoice:
|
|
198
|
-
return <XeboSingleChoiceView key={question.id} {...commonProps} />;
|
|
199
|
-
case XeboQuestionType.multipleChoice:
|
|
200
|
-
return <XeboMultipleChoiceView key={question.id} {...commonProps} />;
|
|
201
|
-
case XeboQuestionType.dropdown:
|
|
202
|
-
return <XeboDropdownView key={question.id} {...commonProps} />;
|
|
203
|
-
case XeboQuestionType.singleTextBox:
|
|
204
|
-
case XeboQuestionType.multipleTextBox:
|
|
205
|
-
return <XeboTextBoxView key={question.id} {...commonProps} />;
|
|
206
|
-
case XeboQuestionType.nps:
|
|
207
|
-
return <XeboNPSView key={question.id} {...commonProps} />;
|
|
208
|
-
case XeboQuestionType.multiNps:
|
|
209
|
-
return <XeboMultiNPSView key={question.id} {...commonProps} />;
|
|
210
|
-
case XeboQuestionType.rating:
|
|
211
|
-
return <XeboRatingView key={question.id} {...commonProps} />;
|
|
212
|
-
case XeboQuestionType.multiRating:
|
|
213
|
-
return <XeboMultiRatingView key={question.id} {...commonProps} />;
|
|
214
|
-
default:
|
|
215
|
-
return null;
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
const renderContent = () => {
|
|
220
|
-
if (!survey) return null;
|
|
221
|
-
|
|
222
|
-
if (screen === 'intro' && survey.introPage) {
|
|
223
|
-
return <XeboIntroView introPage={survey.introPage} onStart={handleIntroStart} />;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
if (screen === 'thankYou') {
|
|
227
|
-
const tyQuestion = survey.questions.find(q => q.id === 'thank_you_auto');
|
|
228
|
-
if (tyQuestion) {
|
|
229
|
-
return <XeboThankYouView question={tyQuestion} onDismiss={handleSkip} />;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
if (screen === 'question') {
|
|
234
|
-
const question = survey.questions[questionIndex];
|
|
235
|
-
if (!question) return null;
|
|
236
|
-
return renderQuestion(question);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
return null;
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
// ─── Render ───────────────────────────────────────────────────────────────
|
|
243
|
-
|
|
244
|
-
return (
|
|
245
|
-
<RNModal
|
|
246
|
-
isVisible={visible}
|
|
247
|
-
onBackButtonPress={handleSkip}
|
|
248
|
-
backdropOpacity={0.5}
|
|
249
|
-
backdropColor="#000000"
|
|
250
|
-
style={styles.modal}
|
|
251
|
-
animationIn="slideInUp"
|
|
252
|
-
animationInTiming={350}
|
|
253
|
-
animationOut="slideOutDown"
|
|
254
|
-
animationOutTiming={300}
|
|
255
|
-
useNativeDriver={true}
|
|
256
|
-
useNativeDriverForBackdrop={true}
|
|
257
|
-
hideModalContentWhileAnimating={true}
|
|
258
|
-
coverScreen={true}
|
|
259
|
-
propagateSwipe={false}
|
|
260
|
-
onModalHide={() => {
|
|
261
|
-
setSurvey(null);
|
|
262
|
-
shiftAnim.setValue(0); // reset in case keyboard was open when modal closed
|
|
263
|
-
}}
|
|
264
|
-
>
|
|
265
|
-
{/* Animated.View handles ONLY the keyboard shift (transform).
|
|
266
|
-
The inner View owns height/layout so flex children compute correctly. */}
|
|
267
|
-
<Animated.View style={{ transform: [{ translateY: shiftAnim }] }}>
|
|
268
|
-
<View
|
|
269
|
-
style={[
|
|
270
|
-
styles.sheet,
|
|
271
|
-
{
|
|
272
|
-
backgroundColor: theme.backgroundColor,
|
|
273
|
-
height: sheetHeight,
|
|
274
|
-
},
|
|
275
|
-
]}
|
|
276
|
-
>
|
|
277
|
-
{/* Handle bar */}
|
|
278
|
-
<View style={styles.handleWrap}>
|
|
279
|
-
<View style={styles.handle} />
|
|
280
|
-
</View>
|
|
281
|
-
|
|
282
|
-
{/* Header row: Skip / X close */}
|
|
283
|
-
<View style={styles.headerRow}>
|
|
284
|
-
{screen === 'thankYou' ? (
|
|
285
|
-
<TouchableOpacity onPress={handleSkip} style={styles.closeButton} activeOpacity={0.7}>
|
|
286
|
-
<Text style={[styles.closeText, { color: theme.textColor }]}>✕</Text>
|
|
287
|
-
</TouchableOpacity>
|
|
288
|
-
) : (
|
|
289
|
-
<TouchableOpacity onPress={handleSkip} style={styles.skipButton} activeOpacity={0.7}>
|
|
290
|
-
<Text style={[styles.skipText, { color: theme.textColor }]}>Skip</Text>
|
|
291
|
-
</TouchableOpacity>
|
|
292
|
-
)}
|
|
293
|
-
</View>
|
|
294
|
-
|
|
295
|
-
{/* Main content */}
|
|
296
|
-
<View style={styles.content}>{renderContent()}</View>
|
|
297
|
-
|
|
298
|
-
{/* Safe area bottom padding — home indicator on iOS, gesture nav on Android */}
|
|
299
|
-
<View style={{ height: bottomInset }} />
|
|
300
|
-
</View>
|
|
301
|
-
</Animated.View>
|
|
302
|
-
</RNModal>
|
|
303
|
-
);
|
|
304
|
-
};
|
|
305
|
-
|
|
306
|
-
const styles = StyleSheet.create({
|
|
307
|
-
// react-native-modal wrapper: full screen, sheet aligned to bottom
|
|
308
|
-
modal: {
|
|
309
|
-
justifyContent: 'flex-end',
|
|
310
|
-
margin: 0,
|
|
311
|
-
},
|
|
312
|
-
sheet: {
|
|
313
|
-
borderTopLeftRadius: 16,
|
|
314
|
-
borderTopRightRadius: 16,
|
|
315
|
-
overflow: 'hidden',
|
|
316
|
-
elevation: 9999,
|
|
317
|
-
shadowColor: '#000',
|
|
318
|
-
shadowOffset: { width: 0, height: -4 },
|
|
319
|
-
shadowOpacity: 0.15,
|
|
320
|
-
shadowRadius: 12,
|
|
321
|
-
},
|
|
322
|
-
handleWrap: {
|
|
323
|
-
alignItems: 'center',
|
|
324
|
-
paddingTop: 10,
|
|
325
|
-
paddingBottom: 4,
|
|
326
|
-
},
|
|
327
|
-
handle: {
|
|
328
|
-
width: 36,
|
|
329
|
-
height: 4,
|
|
330
|
-
borderRadius: 2,
|
|
331
|
-
backgroundColor: '#D1D5DB',
|
|
332
|
-
},
|
|
333
|
-
headerRow: {
|
|
334
|
-
flexDirection: 'row',
|
|
335
|
-
justifyContent: 'flex-end',
|
|
336
|
-
paddingHorizontal: 16,
|
|
337
|
-
paddingBottom: 4,
|
|
338
|
-
},
|
|
339
|
-
skipButton: {
|
|
340
|
-
paddingHorizontal: 12,
|
|
341
|
-
paddingVertical: 6,
|
|
342
|
-
},
|
|
343
|
-
skipText: {
|
|
344
|
-
fontSize: 14,
|
|
345
|
-
fontWeight: '500',
|
|
346
|
-
opacity: 0.6,
|
|
347
|
-
},
|
|
348
|
-
closeButton: {
|
|
349
|
-
paddingHorizontal: 12,
|
|
350
|
-
paddingVertical: 6,
|
|
351
|
-
},
|
|
352
|
-
closeText: {
|
|
353
|
-
fontSize: 18,
|
|
354
|
-
fontWeight: '600',
|
|
355
|
-
opacity: 0.7,
|
|
356
|
-
},
|
|
357
|
-
content: {
|
|
358
|
-
flex: 1,
|
|
359
|
-
},
|
|
360
|
-
});
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
import React, { useRef, useState } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
View,
|
|
4
|
-
Text,
|
|
5
|
-
TextInput,
|
|
6
|
-
TouchableOpacity,
|
|
7
|
-
StyleSheet,
|
|
8
|
-
ScrollView,
|
|
9
|
-
Animated,
|
|
10
|
-
Keyboard,
|
|
11
|
-
} from 'react-native';
|
|
12
|
-
import { XeboQuestion, XeboAnswer, XeboQuestionType } from '../models/XeboModels';
|
|
13
|
-
import { getTheme } from '../theme/XeboTheme';
|
|
14
|
-
|
|
15
|
-
interface Props {
|
|
16
|
-
question: XeboQuestion;
|
|
17
|
-
isLastQuestion: boolean;
|
|
18
|
-
onAnswer: (answer: XeboAnswer) => void;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const XeboTextBoxView: React.FC<Props> = ({ question, isLastQuestion, onAnswer }) => {
|
|
22
|
-
const theme = getTheme();
|
|
23
|
-
const isMulti = question.type === XeboQuestionType.multipleTextBox;
|
|
24
|
-
const fields = question.options && question.options.length > 0 ? question.options : [{ id: 'default', text: '', value: '' }];
|
|
25
|
-
|
|
26
|
-
const [values, setValues] = useState<Record<string, string>>({});
|
|
27
|
-
const [error, setError] = useState('');
|
|
28
|
-
const shakeAnim = useRef(new Animated.Value(0)).current;
|
|
29
|
-
const scrollRef = useRef<ScrollView>(null);
|
|
30
|
-
|
|
31
|
-
// Scroll so the focused field is visible above the button when keyboard is up
|
|
32
|
-
const handleFocus = (idx: number) => {
|
|
33
|
-
setTimeout(() => {
|
|
34
|
-
scrollRef.current?.scrollTo({ y: idx * 80, animated: true });
|
|
35
|
-
}, 150);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const shake = () => {
|
|
39
|
-
Animated.sequence([
|
|
40
|
-
Animated.timing(shakeAnim, { toValue: 8, duration: 60, useNativeDriver: true }),
|
|
41
|
-
Animated.timing(shakeAnim, { toValue: -8, duration: 60, useNativeDriver: true }),
|
|
42
|
-
Animated.timing(shakeAnim, { toValue: 6, duration: 60, useNativeDriver: true }),
|
|
43
|
-
Animated.timing(shakeAnim, { toValue: 0, duration: 60, useNativeDriver: true }),
|
|
44
|
-
]).start();
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const handleChange = (fieldId: string, text: string) => {
|
|
48
|
-
setValues(prev => ({ ...prev, [fieldId]: text }));
|
|
49
|
-
setError('');
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const handleSubmit = () => {
|
|
53
|
-
if (question.isRequired) {
|
|
54
|
-
const empty = fields.some(f => !(values[f.id] ?? '').trim());
|
|
55
|
-
if (empty) {
|
|
56
|
-
setError('Please fill in all fields.');
|
|
57
|
-
shake();
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
Keyboard.dismiss();
|
|
63
|
-
onAnswer({
|
|
64
|
-
questionId: question.id,
|
|
65
|
-
value: fields
|
|
66
|
-
.filter(f => (values[f.id] ?? '').trim())
|
|
67
|
-
.map(f => ({ rowId: f.id, text: values[f.id] ?? '' })),
|
|
68
|
-
});
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
return (
|
|
72
|
-
<View style={styles.outer}>
|
|
73
|
-
<ScrollView
|
|
74
|
-
ref={scrollRef}
|
|
75
|
-
style={styles.scroll}
|
|
76
|
-
contentContainerStyle={styles.scrollContent}
|
|
77
|
-
keyboardShouldPersistTaps="handled"
|
|
78
|
-
showsVerticalScrollIndicator={false}
|
|
79
|
-
>
|
|
80
|
-
<Text style={[styles.title, { color: theme.textColor, fontFamily: theme.fontFamily }]}>
|
|
81
|
-
{question.title}
|
|
82
|
-
</Text>
|
|
83
|
-
{!!question.subtitle && (
|
|
84
|
-
<Text style={[styles.subtitle, { color: theme.textColor, fontFamily: theme.fontFamily }]}>
|
|
85
|
-
{question.subtitle}
|
|
86
|
-
</Text>
|
|
87
|
-
)}
|
|
88
|
-
|
|
89
|
-
{fields.map((field, idx) => (
|
|
90
|
-
<View key={field.id} style={styles.fieldWrap}>
|
|
91
|
-
{isMulti && !!field.text && (
|
|
92
|
-
<Text style={[styles.fieldLabel, { color: theme.textColor, fontFamily: theme.fontFamily }]}>
|
|
93
|
-
{field.text}
|
|
94
|
-
</Text>
|
|
95
|
-
)}
|
|
96
|
-
<TextInput
|
|
97
|
-
style={[
|
|
98
|
-
styles.input,
|
|
99
|
-
{
|
|
100
|
-
borderColor: '#E5E7EB',
|
|
101
|
-
color: theme.textColor,
|
|
102
|
-
fontFamily: theme.fontFamily,
|
|
103
|
-
borderRadius: theme.cornerRadius,
|
|
104
|
-
},
|
|
105
|
-
]}
|
|
106
|
-
placeholder={isMulti ? '' : (question.placeholder || 'Type your answer here...')}
|
|
107
|
-
placeholderTextColor="#9CA3AF"
|
|
108
|
-
value={values[field.id] ?? ''}
|
|
109
|
-
onChangeText={text => handleChange(field.id, text)}
|
|
110
|
-
onFocus={() => handleFocus(idx)}
|
|
111
|
-
multiline={!isMulti}
|
|
112
|
-
numberOfLines={isMulti ? 1 : 4}
|
|
113
|
-
textAlignVertical={isMulti ? 'center' : 'top'}
|
|
114
|
-
returnKeyType={idx === fields.length - 1 ? 'done' : 'next'}
|
|
115
|
-
/>
|
|
116
|
-
</View>
|
|
117
|
-
))}
|
|
118
|
-
</ScrollView>
|
|
119
|
-
|
|
120
|
-
{/* Error + button always visible at bottom, outside scroll */}
|
|
121
|
-
{!!error && <Text style={styles.errorText}>{error}</Text>}
|
|
122
|
-
<Animated.View style={{ transform: [{ translateX: shakeAnim }] }}>
|
|
123
|
-
<TouchableOpacity
|
|
124
|
-
style={[styles.button, { backgroundColor: theme.primaryColor, borderRadius: theme.cornerRadius }]}
|
|
125
|
-
onPress={handleSubmit}
|
|
126
|
-
activeOpacity={0.8}
|
|
127
|
-
>
|
|
128
|
-
<Text style={[styles.buttonText, { fontFamily: theme.fontFamily }]}>
|
|
129
|
-
{isLastQuestion ? 'Submit' : 'Next'}
|
|
130
|
-
</Text>
|
|
131
|
-
</TouchableOpacity>
|
|
132
|
-
</Animated.View>
|
|
133
|
-
</View>
|
|
134
|
-
);
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
const styles = StyleSheet.create({
|
|
138
|
-
outer: {
|
|
139
|
-
paddingHorizontal: 20,
|
|
140
|
-
paddingBottom: 24,
|
|
141
|
-
},
|
|
142
|
-
scroll: {
|
|
143
|
-
maxHeight: 340,
|
|
144
|
-
},
|
|
145
|
-
scrollContent: {
|
|
146
|
-
paddingTop: 16,
|
|
147
|
-
paddingBottom: 8,
|
|
148
|
-
},
|
|
149
|
-
title: {
|
|
150
|
-
fontSize: 18,
|
|
151
|
-
fontWeight: '700',
|
|
152
|
-
marginBottom: 16,
|
|
153
|
-
},
|
|
154
|
-
subtitle: {
|
|
155
|
-
fontSize: 14,
|
|
156
|
-
opacity: 0.6,
|
|
157
|
-
marginBottom: 16,
|
|
158
|
-
},
|
|
159
|
-
fieldWrap: {
|
|
160
|
-
marginBottom: 14,
|
|
161
|
-
},
|
|
162
|
-
fieldLabel: {
|
|
163
|
-
fontSize: 14,
|
|
164
|
-
fontWeight: '500',
|
|
165
|
-
marginBottom: 6,
|
|
166
|
-
},
|
|
167
|
-
input: {
|
|
168
|
-
borderWidth: 1.5,
|
|
169
|
-
padding: 12,
|
|
170
|
-
fontSize: 15,
|
|
171
|
-
minHeight: 48,
|
|
172
|
-
},
|
|
173
|
-
errorText: {
|
|
174
|
-
color: '#EF4444',
|
|
175
|
-
fontSize: 13,
|
|
176
|
-
marginBottom: 8,
|
|
177
|
-
},
|
|
178
|
-
button: {
|
|
179
|
-
paddingVertical: 14,
|
|
180
|
-
alignItems: 'center',
|
|
181
|
-
marginTop: 8,
|
|
182
|
-
},
|
|
183
|
-
buttonText: {
|
|
184
|
-
color: '#FFFFFF',
|
|
185
|
-
fontSize: 16,
|
|
186
|
-
fontWeight: '600',
|
|
187
|
-
},
|
|
188
|
-
});
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useRef } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
View,
|
|
4
|
-
Text,
|
|
5
|
-
StyleSheet,
|
|
6
|
-
Animated,
|
|
7
|
-
Linking,
|
|
8
|
-
} from 'react-native';
|
|
9
|
-
import { XeboQuestion } from '../models/XeboModels';
|
|
10
|
-
import { getTheme } from '../theme/XeboTheme';
|
|
11
|
-
|
|
12
|
-
interface Props {
|
|
13
|
-
question: XeboQuestion;
|
|
14
|
-
onDismiss: () => void;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const XeboThankYouView: React.FC<Props> = ({ question, onDismiss }) => {
|
|
18
|
-
const theme = getTheme();
|
|
19
|
-
const fadeAnim = useRef(new Animated.Value(0)).current;
|
|
20
|
-
const scaleAnim = useRef(new Animated.Value(0.8)).current;
|
|
21
|
-
|
|
22
|
-
useEffect(() => {
|
|
23
|
-
Animated.parallel([
|
|
24
|
-
Animated.timing(fadeAnim, { toValue: 1, duration: 400, useNativeDriver: true }),
|
|
25
|
-
Animated.spring(scaleAnim, { toValue: 1, tension: 60, friction: 7, useNativeDriver: true }),
|
|
26
|
-
]).start();
|
|
27
|
-
|
|
28
|
-
if (question.redirectURL) {
|
|
29
|
-
const timer = setTimeout(async () => {
|
|
30
|
-
try {
|
|
31
|
-
await Linking.openURL(question.redirectURL!);
|
|
32
|
-
} catch {
|
|
33
|
-
// ignore
|
|
34
|
-
}
|
|
35
|
-
onDismiss();
|
|
36
|
-
}, 2500);
|
|
37
|
-
return () => clearTimeout(timer);
|
|
38
|
-
}
|
|
39
|
-
}, []);
|
|
40
|
-
|
|
41
|
-
return (
|
|
42
|
-
<Animated.View
|
|
43
|
-
style={[
|
|
44
|
-
styles.container,
|
|
45
|
-
{ opacity: fadeAnim, transform: [{ scale: scaleAnim }] },
|
|
46
|
-
]}
|
|
47
|
-
>
|
|
48
|
-
{/* Green checkmark circle */}
|
|
49
|
-
<View style={styles.iconCircle}>
|
|
50
|
-
<Text style={styles.checkmark}>✓</Text>
|
|
51
|
-
</View>
|
|
52
|
-
|
|
53
|
-
<Text style={[styles.title, { color: theme.textColor, fontFamily: theme.fontFamily }]}>
|
|
54
|
-
{question.title}
|
|
55
|
-
</Text>
|
|
56
|
-
|
|
57
|
-
{!!question.subtitle && (
|
|
58
|
-
<Text style={[styles.subtitle, { color: theme.textColor, fontFamily: theme.fontFamily }]}>
|
|
59
|
-
{question.subtitle}
|
|
60
|
-
</Text>
|
|
61
|
-
)}
|
|
62
|
-
</Animated.View>
|
|
63
|
-
);
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const styles = StyleSheet.create({
|
|
67
|
-
container: {
|
|
68
|
-
flex: 1,
|
|
69
|
-
paddingHorizontal: 20,
|
|
70
|
-
paddingVertical: 40,
|
|
71
|
-
alignItems: 'center',
|
|
72
|
-
justifyContent: 'center',
|
|
73
|
-
},
|
|
74
|
-
iconCircle: {
|
|
75
|
-
width: 80,
|
|
76
|
-
height: 80,
|
|
77
|
-
borderRadius: 40,
|
|
78
|
-
backgroundColor: '#22C55E',
|
|
79
|
-
alignItems: 'center',
|
|
80
|
-
justifyContent: 'center',
|
|
81
|
-
marginBottom: 24,
|
|
82
|
-
},
|
|
83
|
-
checkmark: {
|
|
84
|
-
color: '#FFFFFF',
|
|
85
|
-
fontSize: 40,
|
|
86
|
-
fontWeight: '700',
|
|
87
|
-
},
|
|
88
|
-
title: {
|
|
89
|
-
fontSize: 22,
|
|
90
|
-
fontWeight: '700',
|
|
91
|
-
textAlign: 'center',
|
|
92
|
-
marginBottom: 12,
|
|
93
|
-
},
|
|
94
|
-
subtitle: {
|
|
95
|
-
fontSize: 15,
|
|
96
|
-
textAlign: 'center',
|
|
97
|
-
opacity: 0.7,
|
|
98
|
-
lineHeight: 22,
|
|
99
|
-
},
|
|
100
|
-
});
|