@microsurveysai/react-native 0.1.6 → 0.1.8
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/README.md +1 -1
- package/dist/index.cjs +234 -73
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +33 -8
- package/dist/index.d.ts +33 -8
- package/dist/index.js +235 -74
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -180,6 +180,7 @@ function normalizeSurvey(raw) {
|
|
|
180
180
|
dismissible: typeof raw.dismissible === "boolean" ? raw.dismissible : null,
|
|
181
181
|
presentation: strOrUndef(raw.presentation) ?? null,
|
|
182
182
|
successMessage: strOrUndef(raw.successMessage) ?? null,
|
|
183
|
+
successPace: raw.successPace === "slow" || raw.successPace === "fast" ? raw.successPace : null,
|
|
183
184
|
platforms: Array.isArray(raw.platforms) ? raw.platforms.filter((p) => typeof p === "string") : null
|
|
184
185
|
};
|
|
185
186
|
}
|
|
@@ -209,12 +210,24 @@ function parseConfig(rawText) {
|
|
|
209
210
|
// src/core/apiClient.ts
|
|
210
211
|
var API_VERSION = "2026-06-30";
|
|
211
212
|
var PENDING_PAGE_SIZE = 50;
|
|
213
|
+
var RETRY_BASE_MS = 2e3;
|
|
214
|
+
var RETRY_MAX_MS = 3e4;
|
|
215
|
+
var INGEST_TIMEOUT_MS = 15e3;
|
|
212
216
|
var ApiClient = class {
|
|
213
217
|
constructor(apiKey, baseURL, storage) {
|
|
214
218
|
__publicField(this, "apiKey");
|
|
215
219
|
__publicField(this, "baseURL");
|
|
216
220
|
__publicField(this, "outbox");
|
|
217
221
|
__publicField(this, "isFlushing", false);
|
|
222
|
+
/** The flush in progress, returned to callers that ask for another meanwhile. */
|
|
223
|
+
__publicField(this, "flushPromise", Promise.resolve());
|
|
224
|
+
/** Set when flush() is called during a flush: run another pass before finishing. */
|
|
225
|
+
__publicField(this, "flushAgain", false);
|
|
226
|
+
__publicField(this, "retryTimer", null);
|
|
227
|
+
/** Failed flushes in a row, for the retry backoff. */
|
|
228
|
+
__publicField(this, "failures", 0);
|
|
229
|
+
/** After `cancelRetry()`: no new retry timers until the next `resumeRetry()`. */
|
|
230
|
+
__publicField(this, "retryStopped", false);
|
|
218
231
|
this.apiKey = apiKey;
|
|
219
232
|
this.outbox = new Outbox(storage);
|
|
220
233
|
this.baseURL = baseURL.replace(/\/+$/, "");
|
|
@@ -266,9 +279,11 @@ var ApiClient = class {
|
|
|
266
279
|
}
|
|
267
280
|
// ── Impressions / responses ─────────────────────────────────────────────────
|
|
268
281
|
/** Queues the impression and returns its `clientId`, so the response from the
|
|
269
|
-
* same showing can point back to it.
|
|
282
|
+
* same showing can point back to it. Pass the `clientId` to send the same
|
|
283
|
+
* impression again (e.g. with `dismissed: true` once the user dismissed it):
|
|
284
|
+
* the server updates the one it has. */
|
|
270
285
|
recordImpression(input) {
|
|
271
|
-
const clientId = uuid();
|
|
286
|
+
const clientId = input.clientId ?? uuid();
|
|
272
287
|
const payload = {
|
|
273
288
|
clientId,
|
|
274
289
|
surveyId: input.surveyId,
|
|
@@ -314,46 +329,94 @@ var ApiClient = class {
|
|
|
314
329
|
}
|
|
315
330
|
// ── Flush ────────────────────────────────────────────────────────────────────
|
|
316
331
|
/** POSTs queued entries in order. Stops at the first retryable failure (likely
|
|
317
|
-
* offline) and
|
|
318
|
-
* running are sent by the same flush, so nothing waits
|
|
319
|
-
* Idempotency keys make re-sends safe.
|
|
320
|
-
|
|
321
|
-
|
|
332
|
+
* offline) and schedules a retry (2 s, doubling, capped at 30 s). Entries
|
|
333
|
+
* queued while a flush is running are sent by the same flush, so nothing waits
|
|
334
|
+
* for the next event. Idempotency keys make re-sends safe. Resolves when the
|
|
335
|
+
* flush in progress is done; never throws. */
|
|
336
|
+
flush() {
|
|
337
|
+
if (this.isFlushing) {
|
|
338
|
+
this.flushAgain = true;
|
|
339
|
+
return this.flushPromise;
|
|
340
|
+
}
|
|
322
341
|
this.isFlushing = true;
|
|
342
|
+
this.clearRetryTimer();
|
|
343
|
+
this.flushPromise = this.runFlush();
|
|
344
|
+
return this.flushPromise;
|
|
345
|
+
}
|
|
346
|
+
/** Stops retrying (the client is stopping). Queued entries stay for later. */
|
|
347
|
+
cancelRetry() {
|
|
348
|
+
this.retryStopped = true;
|
|
349
|
+
this.clearRetryTimer();
|
|
350
|
+
}
|
|
351
|
+
/** Allows retries again after `cancelRetry()`. */
|
|
352
|
+
resumeRetry() {
|
|
353
|
+
this.retryStopped = false;
|
|
354
|
+
}
|
|
355
|
+
async runFlush() {
|
|
356
|
+
let failed = false;
|
|
357
|
+
const sent = /* @__PURE__ */ new Set();
|
|
323
358
|
try {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
359
|
+
do {
|
|
360
|
+
this.flushAgain = false;
|
|
361
|
+
for (; ; ) {
|
|
362
|
+
const pending = this.outbox.snapshot().filter((e) => !sent.has(e.id));
|
|
363
|
+
if (pending.length === 0) break;
|
|
364
|
+
for (const entry of pending) {
|
|
365
|
+
try {
|
|
366
|
+
await this.post(entry.path, entry.body);
|
|
367
|
+
this.outbox.remove(entry.id);
|
|
368
|
+
sent.add(entry.id);
|
|
369
|
+
} catch {
|
|
370
|
+
failed = true;
|
|
371
|
+
break;
|
|
372
|
+
}
|
|
337
373
|
}
|
|
374
|
+
if (failed) break;
|
|
338
375
|
}
|
|
339
|
-
|
|
340
|
-
}
|
|
376
|
+
} while (!failed && this.flushAgain);
|
|
341
377
|
} finally {
|
|
378
|
+
this.flushAgain = false;
|
|
342
379
|
this.isFlushing = false;
|
|
343
380
|
}
|
|
381
|
+
if (failed) {
|
|
382
|
+
this.failures += 1;
|
|
383
|
+
this.scheduleRetry();
|
|
384
|
+
} else {
|
|
385
|
+
this.failures = 0;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
/** One pending retry at most. */
|
|
389
|
+
scheduleRetry() {
|
|
390
|
+
if (this.retryStopped || this.retryTimer) return;
|
|
391
|
+
const delay = Math.min(RETRY_BASE_MS * 2 ** Math.max(0, this.failures - 1), RETRY_MAX_MS);
|
|
392
|
+
this.retryTimer = setTimeout(() => {
|
|
393
|
+
this.retryTimer = null;
|
|
394
|
+
void this.flush();
|
|
395
|
+
}, delay);
|
|
396
|
+
}
|
|
397
|
+
clearRetryTimer() {
|
|
398
|
+
if (this.retryTimer) clearTimeout(this.retryTimer);
|
|
399
|
+
this.retryTimer = null;
|
|
344
400
|
}
|
|
345
401
|
async post(path, body) {
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
"
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
402
|
+
const controller = typeof AbortController !== "undefined" ? new AbortController() : null;
|
|
403
|
+
const timeout = controller ? setTimeout(() => controller.abort(), INGEST_TIMEOUT_MS) : null;
|
|
404
|
+
try {
|
|
405
|
+
const res = await fetch(this.endpoint(path), {
|
|
406
|
+
method: "POST",
|
|
407
|
+
headers: {
|
|
408
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
409
|
+
"MS-Api-Version": API_VERSION,
|
|
410
|
+
"Content-Type": "application/json; charset=utf-8"
|
|
411
|
+
},
|
|
412
|
+
body,
|
|
413
|
+
signal: controller?.signal
|
|
414
|
+
});
|
|
415
|
+
if (res.status === 429 || res.status >= 500 && res.status < 600) {
|
|
416
|
+
throw new Error(`retryable ${res.status}`);
|
|
417
|
+
}
|
|
418
|
+
} finally {
|
|
419
|
+
if (timeout) clearTimeout(timeout);
|
|
357
420
|
}
|
|
358
421
|
}
|
|
359
422
|
endpoint(path) {
|
|
@@ -856,7 +919,7 @@ function debugProperties(properties) {
|
|
|
856
919
|
}
|
|
857
920
|
|
|
858
921
|
// src/core/version.ts
|
|
859
|
-
var SDK_VERSION = "0.1.
|
|
922
|
+
var SDK_VERSION = "0.1.8";
|
|
860
923
|
|
|
861
924
|
// src/core/client.ts
|
|
862
925
|
var DEFAULT_BASE_URL = "https://console.microsurveys.ai";
|
|
@@ -921,15 +984,14 @@ var MicroSurveysClient = class {
|
|
|
921
984
|
start() {
|
|
922
985
|
if (this.started) return;
|
|
923
986
|
this.started = true;
|
|
987
|
+
this.api.resumeRetry();
|
|
924
988
|
void this.api.flush();
|
|
925
989
|
void this.refreshConfig().then(() => {
|
|
926
990
|
if (this.started) this.startPendingChecks();
|
|
927
991
|
});
|
|
928
992
|
this.unsubscribeForeground = this.subscribeForeground(() => {
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
this.refreshConfigIfStale();
|
|
932
|
-
}
|
|
993
|
+
void this.api.flush();
|
|
994
|
+
if (this.refreshOnForeground) this.refreshConfigIfStale();
|
|
933
995
|
this.startPendingChecks();
|
|
934
996
|
});
|
|
935
997
|
this.unsubscribeBackground = this.subscribeBackground?.(() => {
|
|
@@ -949,6 +1011,7 @@ var MicroSurveysClient = class {
|
|
|
949
1011
|
this.unsubscribeBackground = null;
|
|
950
1012
|
this.unsubscribeForeground?.();
|
|
951
1013
|
this.unsubscribeForeground = null;
|
|
1014
|
+
this.api.cancelRetry();
|
|
952
1015
|
this.started = false;
|
|
953
1016
|
}
|
|
954
1017
|
/** Force an ETag-aware config refresh; keeps the cache on failure. */
|
|
@@ -1126,49 +1189,81 @@ var MicroSurveysClient = class {
|
|
|
1126
1189
|
return;
|
|
1127
1190
|
}
|
|
1128
1191
|
this.handleDecision({ surveyId: survey.id, triggerId: trigger.id, reason: "shown" });
|
|
1129
|
-
const p =
|
|
1192
|
+
const p = this.newPresentation(survey, trigger, identity);
|
|
1130
1193
|
this.active = p;
|
|
1131
1194
|
const active = this.toActiveSurvey(p);
|
|
1132
1195
|
this.presentListeners.forEach((l) => l(active));
|
|
1133
1196
|
}
|
|
1197
|
+
newPresentation(survey, trigger, identity) {
|
|
1198
|
+
return { survey, trigger, identity, impressionId: uuid(), presentedAt: /* @__PURE__ */ new Date(), impression: null, closed: false };
|
|
1199
|
+
}
|
|
1134
1200
|
toActiveSurvey(p) {
|
|
1135
1201
|
return {
|
|
1136
1202
|
survey: p.survey,
|
|
1137
1203
|
trigger: p.trigger,
|
|
1204
|
+
shown: () => this.markShown(p),
|
|
1138
1205
|
close: (result) => {
|
|
1139
1206
|
if (p.closed) return;
|
|
1140
1207
|
p.closed = true;
|
|
1141
|
-
this.recordOutcome(p.survey.id, p.trigger?.id ?? null, p.identity, p.shownAt, result);
|
|
1142
1208
|
if (this.active === p) this.active = null;
|
|
1209
|
+
if (result) this.recordOutcome(p, result);
|
|
1143
1210
|
}
|
|
1144
1211
|
};
|
|
1145
1212
|
}
|
|
1146
|
-
/**
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1213
|
+
/** Queues the impression the moment the survey is on screen, so it counts even
|
|
1214
|
+
* if the app is killed before the survey closes. */
|
|
1215
|
+
markShown(p) {
|
|
1216
|
+
if (p.impression || p.closed) return;
|
|
1217
|
+
p.impression = {
|
|
1218
|
+
clientId: p.impressionId,
|
|
1219
|
+
surveyId: p.survey.id,
|
|
1220
|
+
triggerId: p.trigger?.id ?? null,
|
|
1221
|
+
endUserId: endUserIdOf(p.identity),
|
|
1222
|
+
shownAt: /* @__PURE__ */ new Date(),
|
|
1223
|
+
dismissed: false,
|
|
1224
|
+
context: this.deviceContext()
|
|
1225
|
+
};
|
|
1226
|
+
this.api.recordImpression(p.impression);
|
|
1150
1227
|
}
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1228
|
+
/** An **inline** `<MicroSurvey>` (no trigger, no gate, not "the" active survey).
|
|
1229
|
+
* Call `shown` when it renders and `close` with its outcome. */
|
|
1230
|
+
presentInline(survey) {
|
|
1231
|
+
return this.toActiveSurvey(this.newPresentation(survey, null, this.identityStore.snapshot()));
|
|
1232
|
+
}
|
|
1233
|
+
/** Records the outcome of an inline survey in one go, at close. Prefer
|
|
1234
|
+
* `presentInline`, which sends the impression when the survey appears. */
|
|
1235
|
+
recordInline(survey, result, shownAt) {
|
|
1236
|
+
const p = this.newPresentation(survey, null, this.identityStore.snapshot());
|
|
1237
|
+
p.presentedAt = shownAt;
|
|
1238
|
+
p.closed = true;
|
|
1239
|
+
this.recordOutcome(p, result);
|
|
1240
|
+
}
|
|
1241
|
+
recordOutcome(p, result) {
|
|
1242
|
+
let impression = p.impression;
|
|
1243
|
+
if (!impression) {
|
|
1244
|
+
impression = {
|
|
1245
|
+
clientId: p.impressionId,
|
|
1246
|
+
surveyId: p.survey.id,
|
|
1247
|
+
triggerId: p.trigger?.id ?? null,
|
|
1248
|
+
endUserId: endUserIdOf(p.identity),
|
|
1249
|
+
shownAt: p.presentedAt,
|
|
1250
|
+
dismissed: result.dismissed,
|
|
1251
|
+
context: this.deviceContext()
|
|
1252
|
+
};
|
|
1253
|
+
this.api.recordImpression(impression);
|
|
1254
|
+
} else if (result.dismissed) {
|
|
1255
|
+
this.api.recordImpression({ ...impression, dismissed: true });
|
|
1256
|
+
}
|
|
1162
1257
|
if (result.completed || result.answers.length > 0) {
|
|
1163
1258
|
this.api.recordResponse({
|
|
1164
|
-
surveyId,
|
|
1165
|
-
endUserId,
|
|
1259
|
+
surveyId: p.survey.id,
|
|
1260
|
+
endUserId: impression.endUserId,
|
|
1166
1261
|
completed: result.completed,
|
|
1167
1262
|
submittedAt: /* @__PURE__ */ new Date(),
|
|
1168
|
-
userProps: identity.userProperties,
|
|
1169
|
-
impressionId,
|
|
1170
|
-
triggerId,
|
|
1171
|
-
context,
|
|
1263
|
+
userProps: p.identity.userProperties,
|
|
1264
|
+
impressionId: p.impressionId,
|
|
1265
|
+
triggerId: p.trigger?.id ?? null,
|
|
1266
|
+
context: impression.context,
|
|
1172
1267
|
answers: result.answers
|
|
1173
1268
|
});
|
|
1174
1269
|
}
|
|
@@ -1188,6 +1283,19 @@ function createClient(opts) {
|
|
|
1188
1283
|
return new MicroSurveysClient(opts);
|
|
1189
1284
|
}
|
|
1190
1285
|
|
|
1286
|
+
// src/core/thanks.ts
|
|
1287
|
+
var DEFAULT_SUCCESS_MESSAGE = "Thanks!";
|
|
1288
|
+
function thanksMessage(message) {
|
|
1289
|
+
const trimmed = message?.trim();
|
|
1290
|
+
return trimmed ? trimmed : DEFAULT_SUCCESS_MESSAGE;
|
|
1291
|
+
}
|
|
1292
|
+
function thanksDurationMs(message, pace) {
|
|
1293
|
+
const chars = [...thanksMessage(message)].length;
|
|
1294
|
+
const base = Math.min(Math.max(1e3 + 50 * chars, 1300), 7e3);
|
|
1295
|
+
const percent = pace === "slow" ? 150 : pace === "fast" ? 70 : 100;
|
|
1296
|
+
return Math.round(base * percent / 100);
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1191
1299
|
// src/amplitude.ts
|
|
1192
1300
|
function createAmplitudePlugin(forwarder) {
|
|
1193
1301
|
return {
|
|
@@ -1378,7 +1486,23 @@ var MicroSurveys = class {
|
|
|
1378
1486
|
unsubscribe?.();
|
|
1379
1487
|
};
|
|
1380
1488
|
}
|
|
1381
|
-
/**
|
|
1489
|
+
/** Starts one showing of an inline `<MicroSurvey>`: call `shown` once it
|
|
1490
|
+
* renders (sends the impression) and `close` with its outcome. */
|
|
1491
|
+
presentInline(survey) {
|
|
1492
|
+
let inner = null;
|
|
1493
|
+
const withShowing = (fn) => this.withClient((c) => {
|
|
1494
|
+
inner ?? (inner = c.presentInline(survey));
|
|
1495
|
+
fn(inner);
|
|
1496
|
+
});
|
|
1497
|
+
return {
|
|
1498
|
+
survey,
|
|
1499
|
+
trigger: null,
|
|
1500
|
+
shown: () => withShowing((s) => s.shown()),
|
|
1501
|
+
close: (result) => withShowing((s) => s.close(result))
|
|
1502
|
+
};
|
|
1503
|
+
}
|
|
1504
|
+
/** Records the outcome of an inline survey in one go, at close. Prefer
|
|
1505
|
+
* `presentInline`, which sends the impression when the survey appears. */
|
|
1382
1506
|
recordInline(survey, result, shownAt) {
|
|
1383
1507
|
this.withClient((c) => c.recordInline(survey, result, shownAt));
|
|
1384
1508
|
}
|
|
@@ -1407,7 +1531,7 @@ import { SafeAreaProvider, initialWindowMetrics, useSafeAreaInsets } from "react
|
|
|
1407
1531
|
|
|
1408
1532
|
// src/ui/SurveyCard.tsx
|
|
1409
1533
|
import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState as useState2 } from "react";
|
|
1410
|
-
import { Animated, Platform as Platform4, Pressable as Pressable3, ScrollView, StyleSheet as StyleSheet3, Text as Text2, View as View3 } from "react-native";
|
|
1534
|
+
import { AccessibilityInfo, Animated, Platform as Platform4, Pressable as Pressable3, ScrollView, StyleSheet as StyleSheet3, Text as Text2, View as View3 } from "react-native";
|
|
1411
1535
|
|
|
1412
1536
|
// src/ui/CloseButton.tsx
|
|
1413
1537
|
import { Platform as Platform3, Pressable, StyleSheet, View } from "react-native";
|
|
@@ -1838,7 +1962,6 @@ var styles2 = StyleSheet2.create({
|
|
|
1838
1962
|
// src/ui/SurveyCard.tsx
|
|
1839
1963
|
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
1840
1964
|
var CLIP_ROOM = 4;
|
|
1841
|
-
var THANKS_MS = 1300;
|
|
1842
1965
|
var SurveyCard = forwardRef(function SurveyCard2({ survey, theme, variant, bottomInset, onResult, onClose }, ref) {
|
|
1843
1966
|
const questions = useMemo(() => [...survey.questions].sort((a, b) => a.order - b.order), [survey]);
|
|
1844
1967
|
const dismissible = survey.dismissible !== false;
|
|
@@ -1849,9 +1972,27 @@ var SurveyCard = forwardRef(function SurveyCard2({ survey, theme, variant, botto
|
|
|
1849
1972
|
const [height, setHeight] = useState2(0);
|
|
1850
1973
|
const reported = useRef(false);
|
|
1851
1974
|
const closeTimer = useRef(null);
|
|
1975
|
+
const closed = useRef(false);
|
|
1976
|
+
const unmounted = useRef(false);
|
|
1852
1977
|
useEffect(() => () => {
|
|
1978
|
+
unmounted.current = true;
|
|
1853
1979
|
if (closeTimer.current) clearTimeout(closeTimer.current);
|
|
1854
1980
|
}, []);
|
|
1981
|
+
function closeThanks() {
|
|
1982
|
+
if (closed.current) return;
|
|
1983
|
+
closed.current = true;
|
|
1984
|
+
if (closeTimer.current) clearTimeout(closeTimer.current);
|
|
1985
|
+
closeTimer.current = null;
|
|
1986
|
+
onClose();
|
|
1987
|
+
}
|
|
1988
|
+
function startThanksTimer() {
|
|
1989
|
+
const ms = thanksDurationMs(survey.successMessage, survey.successPace);
|
|
1990
|
+
const schedule = (screenReader) => {
|
|
1991
|
+
if (closed.current || unmounted.current || closeTimer.current) return;
|
|
1992
|
+
closeTimer.current = setTimeout(closeThanks, screenReader ? ms * 2 : ms);
|
|
1993
|
+
};
|
|
1994
|
+
AccessibilityInfo.isScreenReaderEnabled().then(schedule, () => schedule(false));
|
|
1995
|
+
}
|
|
1855
1996
|
const question = questions[index];
|
|
1856
1997
|
const isLast = index >= questions.length - 1;
|
|
1857
1998
|
const valid = question ? isAnswerValid(question, current) : false;
|
|
@@ -1881,7 +2022,7 @@ var SurveyCard = forwardRef(function SurveyCard2({ survey, theme, variant, botto
|
|
|
1881
2022
|
}
|
|
1882
2023
|
if (report(true)) {
|
|
1883
2024
|
setDone(true);
|
|
1884
|
-
|
|
2025
|
+
startThanksTimer();
|
|
1885
2026
|
}
|
|
1886
2027
|
}
|
|
1887
2028
|
const pad = theme.spacing + 4;
|
|
@@ -1889,13 +2030,22 @@ var SurveyCard = forwardRef(function SurveyCard2({ survey, theme, variant, botto
|
|
|
1889
2030
|
const hasProgress = questions.length > 1;
|
|
1890
2031
|
if (!question) return null;
|
|
1891
2032
|
if (done) {
|
|
1892
|
-
const custom = survey.successMessage?.trim();
|
|
1893
2033
|
return (
|
|
1894
2034
|
// Keep the card's height so the sheet doesn't jump when the content swaps.
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
2035
|
+
// Tapping the thanks closes it at once.
|
|
2036
|
+
/* @__PURE__ */ jsx3(
|
|
2037
|
+
Pressable3,
|
|
2038
|
+
{
|
|
2039
|
+
onPress: closeThanks,
|
|
2040
|
+
accessibilityLiveRegion: "polite",
|
|
2041
|
+
accessibilityHint: "Closes the survey",
|
|
2042
|
+
style: [styles3.thanks, { minHeight: height, padding: pad }],
|
|
2043
|
+
children: /* @__PURE__ */ jsx3(FadeIn, { children: /* @__PURE__ */ jsxs2(View3, { style: styles3.thanksStack, children: [
|
|
2044
|
+
/* @__PURE__ */ jsx3(View3, { style: [styles3.check, { backgroundColor: theme.accent }], children: /* @__PURE__ */ jsx3(Text2, { allowFontScaling: false, style: [styles3.checkGlyph, { color: theme.accentText }], children: "\u2713" }) }),
|
|
2045
|
+
/* @__PURE__ */ jsx3(Text2, { style: [promptStyle(theme), { color: theme.text, textAlign: "center", marginTop: theme.spacing }], children: thanksMessage(survey.successMessage) })
|
|
2046
|
+
] }) })
|
|
2047
|
+
}
|
|
2048
|
+
)
|
|
1899
2049
|
);
|
|
1900
2050
|
}
|
|
1901
2051
|
return /* @__PURE__ */ jsxs2(View3, { onLayout: (e) => setHeight(e.nativeEvent.layout.height), style: styles3.card, children: [
|
|
@@ -1973,7 +2123,8 @@ var styles3 = StyleSheet3.create({
|
|
|
1973
2123
|
scroll: { flexGrow: 0, flexShrink: 1 },
|
|
1974
2124
|
button: { alignItems: "center", justifyContent: "center" },
|
|
1975
2125
|
thanks: { alignItems: "center", justifyContent: "center" },
|
|
1976
|
-
|
|
2126
|
+
// Stretch so a long message wraps inside the card instead of overflowing it.
|
|
2127
|
+
thanksStack: { alignItems: "center", alignSelf: "stretch" },
|
|
1977
2128
|
check: { width: 48, height: 48, borderRadius: 24, alignItems: "center", justifyContent: "center" },
|
|
1978
2129
|
checkGlyph: { fontSize: 26, fontWeight: "700", lineHeight: 30 }
|
|
1979
2130
|
});
|
|
@@ -2227,7 +2378,11 @@ function OverlayHost({ instance, fontFamily }) {
|
|
|
2227
2378
|
}),
|
|
2228
2379
|
[instance]
|
|
2229
2380
|
);
|
|
2381
|
+
useEffect3(() => {
|
|
2382
|
+
current?.active.shown();
|
|
2383
|
+
}, [current]);
|
|
2230
2384
|
function showNext() {
|
|
2385
|
+
current?.active.close();
|
|
2231
2386
|
const next = queue.current.shift();
|
|
2232
2387
|
if (next) {
|
|
2233
2388
|
setCurrent({ active: next, id: nextId.current++ });
|
|
@@ -2273,7 +2428,7 @@ function MicroSurvey({ surveyId, onComplete, style }) {
|
|
|
2273
2428
|
const scheme = useColorScheme2() === "dark" ? "dark" : "light";
|
|
2274
2429
|
const [survey, setSurvey] = useState5(null);
|
|
2275
2430
|
const [closed, setClosed] = useState5(false);
|
|
2276
|
-
const
|
|
2431
|
+
const showing = useRef4(null);
|
|
2277
2432
|
const result = useRef4(null);
|
|
2278
2433
|
useEffect4(() => {
|
|
2279
2434
|
if (!instance) return;
|
|
@@ -2281,8 +2436,14 @@ function MicroSurvey({ surveyId, onComplete, style }) {
|
|
|
2281
2436
|
}, [instance, surveyId]);
|
|
2282
2437
|
const projectTheme = instance?.getTheme();
|
|
2283
2438
|
const theme = useMemo4(() => resolveTheme(projectTheme, { scheme, fontFamily }), [projectTheme, scheme, fontFamily]);
|
|
2439
|
+
const visible = !!instance && !!survey && !closed;
|
|
2440
|
+
if (visible && (!showing.current || showing.current.survey.id !== survey.id)) {
|
|
2441
|
+
showing.current = instance.presentInline(survey);
|
|
2442
|
+
}
|
|
2443
|
+
useEffect4(() => {
|
|
2444
|
+
if (visible) showing.current?.shown();
|
|
2445
|
+
}, [visible, survey]);
|
|
2284
2446
|
if (!instance || !survey || closed) return null;
|
|
2285
|
-
if (!shownAt.current) shownAt.current = /* @__PURE__ */ new Date();
|
|
2286
2447
|
return /* @__PURE__ */ jsx6(
|
|
2287
2448
|
View5,
|
|
2288
2449
|
{
|
|
@@ -2298,7 +2459,7 @@ function MicroSurvey({ surveyId, onComplete, style }) {
|
|
|
2298
2459
|
variant: "inline",
|
|
2299
2460
|
onResult: (r) => {
|
|
2300
2461
|
result.current = r;
|
|
2301
|
-
|
|
2462
|
+
showing.current?.close(r);
|
|
2302
2463
|
},
|
|
2303
2464
|
onClose: () => {
|
|
2304
2465
|
setClosed(true);
|