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