@microsurveysai/react-native 0.1.7 → 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/dist/index.cjs CHANGED
@@ -221,6 +221,7 @@ function normalizeSurvey(raw) {
221
221
  dismissible: typeof raw.dismissible === "boolean" ? raw.dismissible : null,
222
222
  presentation: strOrUndef(raw.presentation) ?? null,
223
223
  successMessage: strOrUndef(raw.successMessage) ?? null,
224
+ successPace: raw.successPace === "slow" || raw.successPace === "fast" ? raw.successPace : null,
224
225
  platforms: Array.isArray(raw.platforms) ? raw.platforms.filter((p) => typeof p === "string") : null
225
226
  };
226
227
  }
@@ -959,7 +960,7 @@ function debugProperties(properties) {
959
960
  }
960
961
 
961
962
  // src/core/version.ts
962
- var SDK_VERSION = "0.1.7";
963
+ var SDK_VERSION = "0.1.8";
963
964
 
964
965
  // src/core/client.ts
965
966
  var DEFAULT_BASE_URL = "https://console.microsurveys.ai";
@@ -1323,6 +1324,19 @@ function createClient(opts) {
1323
1324
  return new MicroSurveysClient(opts);
1324
1325
  }
1325
1326
 
1327
+ // src/core/thanks.ts
1328
+ var DEFAULT_SUCCESS_MESSAGE = "Thanks!";
1329
+ function thanksMessage(message) {
1330
+ const trimmed = message?.trim();
1331
+ return trimmed ? trimmed : DEFAULT_SUCCESS_MESSAGE;
1332
+ }
1333
+ function thanksDurationMs(message, pace) {
1334
+ const chars = [...thanksMessage(message)].length;
1335
+ const base = Math.min(Math.max(1e3 + 50 * chars, 1300), 7e3);
1336
+ const percent = pace === "slow" ? 150 : pace === "fast" ? 70 : 100;
1337
+ return Math.round(base * percent / 100);
1338
+ }
1339
+
1326
1340
  // src/amplitude.ts
1327
1341
  function createAmplitudePlugin(forwarder) {
1328
1342
  return {
@@ -1976,7 +1990,6 @@ var styles2 = import_react_native4.StyleSheet.create({
1976
1990
  // src/ui/SurveyCard.tsx
1977
1991
  var import_jsx_runtime3 = require("react/jsx-runtime");
1978
1992
  var CLIP_ROOM = 4;
1979
- var THANKS_MS = 1300;
1980
1993
  var SurveyCard = (0, import_react2.forwardRef)(function SurveyCard2({ survey, theme, variant, bottomInset, onResult, onClose }, ref) {
1981
1994
  const questions = (0, import_react2.useMemo)(() => [...survey.questions].sort((a, b) => a.order - b.order), [survey]);
1982
1995
  const dismissible = survey.dismissible !== false;
@@ -1987,9 +2000,27 @@ var SurveyCard = (0, import_react2.forwardRef)(function SurveyCard2({ survey, th
1987
2000
  const [height, setHeight] = (0, import_react2.useState)(0);
1988
2001
  const reported = (0, import_react2.useRef)(false);
1989
2002
  const closeTimer = (0, import_react2.useRef)(null);
2003
+ const closed = (0, import_react2.useRef)(false);
2004
+ const unmounted = (0, import_react2.useRef)(false);
1990
2005
  (0, import_react2.useEffect)(() => () => {
2006
+ unmounted.current = true;
1991
2007
  if (closeTimer.current) clearTimeout(closeTimer.current);
1992
2008
  }, []);
2009
+ function closeThanks() {
2010
+ if (closed.current) return;
2011
+ closed.current = true;
2012
+ if (closeTimer.current) clearTimeout(closeTimer.current);
2013
+ closeTimer.current = null;
2014
+ onClose();
2015
+ }
2016
+ function startThanksTimer() {
2017
+ const ms = thanksDurationMs(survey.successMessage, survey.successPace);
2018
+ const schedule = (screenReader) => {
2019
+ if (closed.current || unmounted.current || closeTimer.current) return;
2020
+ closeTimer.current = setTimeout(closeThanks, screenReader ? ms * 2 : ms);
2021
+ };
2022
+ import_react_native5.AccessibilityInfo.isScreenReaderEnabled().then(schedule, () => schedule(false));
2023
+ }
1993
2024
  const question = questions[index];
1994
2025
  const isLast = index >= questions.length - 1;
1995
2026
  const valid = question ? isAnswerValid(question, current) : false;
@@ -2019,7 +2050,7 @@ var SurveyCard = (0, import_react2.forwardRef)(function SurveyCard2({ survey, th
2019
2050
  }
2020
2051
  if (report(true)) {
2021
2052
  setDone(true);
2022
- closeTimer.current = setTimeout(onClose, THANKS_MS);
2053
+ startThanksTimer();
2023
2054
  }
2024
2055
  }
2025
2056
  const pad = theme.spacing + 4;
@@ -2027,13 +2058,22 @@ var SurveyCard = (0, import_react2.forwardRef)(function SurveyCard2({ survey, th
2027
2058
  const hasProgress = questions.length > 1;
2028
2059
  if (!question) return null;
2029
2060
  if (done) {
2030
- const custom = survey.successMessage?.trim();
2031
2061
  return (
2032
2062
  // Keep the card's height so the sheet doesn't jump when the content swaps.
2033
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native5.View, { style: [styles3.thanks, { minHeight: height, padding: pad }], accessibilityLiveRegion: "polite", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(FadeIn, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react_native5.View, { style: styles3.thanksStack, children: [
2034
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native5.View, { style: [styles3.check, { backgroundColor: theme.accent }], children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native5.Text, { allowFontScaling: false, style: [styles3.checkGlyph, { color: theme.accentText }], children: "\u2713" }) }),
2035
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native5.Text, { style: [promptStyle(theme), { color: theme.text, textAlign: "center", marginTop: theme.spacing }], children: custom || "Thanks!" })
2036
- ] }) }) })
2063
+ // Tapping the thanks closes it at once.
2064
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
2065
+ import_react_native5.Pressable,
2066
+ {
2067
+ onPress: closeThanks,
2068
+ accessibilityLiveRegion: "polite",
2069
+ accessibilityHint: "Closes the survey",
2070
+ style: [styles3.thanks, { minHeight: height, padding: pad }],
2071
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(FadeIn, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react_native5.View, { style: styles3.thanksStack, children: [
2072
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native5.View, { style: [styles3.check, { backgroundColor: theme.accent }], children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native5.Text, { allowFontScaling: false, style: [styles3.checkGlyph, { color: theme.accentText }], children: "\u2713" }) }),
2073
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native5.Text, { style: [promptStyle(theme), { color: theme.text, textAlign: "center", marginTop: theme.spacing }], children: thanksMessage(survey.successMessage) })
2074
+ ] }) })
2075
+ }
2076
+ )
2037
2077
  );
2038
2078
  }
2039
2079
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react_native5.View, { onLayout: (e) => setHeight(e.nativeEvent.layout.height), style: styles3.card, children: [
@@ -2111,7 +2151,8 @@ var styles3 = import_react_native5.StyleSheet.create({
2111
2151
  scroll: { flexGrow: 0, flexShrink: 1 },
2112
2152
  button: { alignItems: "center", justifyContent: "center" },
2113
2153
  thanks: { alignItems: "center", justifyContent: "center" },
2114
- thanksStack: { alignItems: "center" },
2154
+ // Stretch so a long message wraps inside the card instead of overflowing it.
2155
+ thanksStack: { alignItems: "center", alignSelf: "stretch" },
2115
2156
  check: { width: 48, height: 48, borderRadius: 24, alignItems: "center", justifyContent: "center" },
2116
2157
  checkGlyph: { fontSize: 26, fontWeight: "700", lineHeight: 30 }
2117
2158
  });