@delacour/react-native-ui 0.6.0-alpha.20261103135630 → 0.6.0-alpha.20261103150033

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@delacour/react-native-ui",
3
- "version": "0.6.0-alpha.20261103135630",
3
+ "version": "0.6.0-alpha.20261103150033",
4
4
  "description": "React Native UI components — Uniwind, Reanimated, Gesture Handler",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -181,8 +181,8 @@
181
181
  "expo-blur": ">=15",
182
182
  "@maplibre/maplibre-react-native": "^11.5.0",
183
183
  "@central-icons-react-native/round-outlined-radius-1-stroke-1.5": "^1.1",
184
- "@delacour/react-native-bottom-sheet": "0.6.0-alpha.20261103135630",
185
- "@delacour/react-native-charts": "0.6.0-alpha.20261103135630",
184
+ "@delacour/react-native-bottom-sheet": "0.6.0-alpha.20261103150033",
185
+ "@delacour/react-native-charts": "0.6.0-alpha.20261103150033",
186
186
  "@legendapp/list": ">=3.3",
187
187
  "react-native-skia": ">=3.9.0",
188
188
  "expo-linear-gradient": ">=15",
@@ -354,6 +354,27 @@ describe("week start", () => {
354
354
  expect(resolveWeekStart("not a locale!!")).toBe(1);
355
355
  });
356
356
 
357
+ test("reads the device locale when the engine has no Intl.Locale and none is passed", () => {
358
+ // A plain stub, not a runner's spy: a copied suite runs under Bun, Jest and Vitest alike.
359
+ const intl: { Locale?: typeof Intl.Locale } = Intl;
360
+ const original = intl.Locale;
361
+ const proto = Intl.DateTimeFormat.prototype;
362
+ const resolvedOptions = proto.resolvedOptions;
363
+ const real = new Intl.DateTimeFormat().resolvedOptions();
364
+ let device = "en-US";
365
+ proto.resolvedOptions = () => ({ ...real, locale: device });
366
+ intl.Locale = undefined;
367
+ try {
368
+ expect(resolveWeekStart(undefined)).toBe(0);
369
+ device = "ar-EG";
370
+ expect(resolveWeekStart(undefined)).toBe(6);
371
+ expect(resolveWeekStart("en-NZ")).toBe(1);
372
+ } finally {
373
+ intl.Locale = original;
374
+ proto.resolvedOptions = resolvedOptions;
375
+ }
376
+ });
377
+
357
378
  test("the region table stands in where Intl has no week info", () => {
358
379
  expect(weekStartFromRegion("US")).toBe(0);
359
380
  expect(weekStartFromRegion("NZ")).toBe(1);
@@ -433,6 +433,15 @@ type LocaleWithWeekInfo = Intl.Locale & {
433
433
  weekInfo?: { firstDay: number };
434
434
  };
435
435
 
436
+ /** The device's locale as `Intl.DateTimeFormat` resolves it, or `undefined` when it cannot. */
437
+ function deviceLocale(): string | undefined {
438
+ try {
439
+ return new Intl.DateTimeFormat().resolvedOptions().locale;
440
+ } catch {
441
+ return undefined;
442
+ }
443
+ }
444
+
436
445
  /**
437
446
  * The first day of the week in a locale.
438
447
  *
@@ -442,14 +451,19 @@ type LocaleWithWeekInfo = Intl.Locale & {
442
451
  * A tag nothing can read is Monday.
443
452
  */
444
453
  export function resolveWeekStart(locale: string | undefined): Weekday {
454
+ // The tag is resolved once, before `Intl.Locale` is touched, so the fallback below reads the
455
+ // device locale too. Without that, an en-US phone on an engine with no `Intl.Locale` started
456
+ // the week on Monday.
457
+ const raw = locale ?? deviceLocale();
458
+ if (!raw) return DEFAULT_WEEK_START;
445
459
  try {
446
- const tag = new Intl.Locale(locale ?? new Intl.DateTimeFormat().resolvedOptions().locale) as LocaleWithWeekInfo;
460
+ const tag = new Intl.Locale(raw) as LocaleWithWeekInfo;
447
461
  const info = typeof tag.getWeekInfo === "function" ? tag.getWeekInfo() : tag.weekInfo;
448
462
  if (info && Number.isInteger(info.firstDay)) return (info.firstDay % 7) as Weekday;
449
463
  const region = tag.region ?? (typeof tag.maximize === "function" ? tag.maximize().region : undefined);
450
464
  return weekStartFromRegion(region ?? LIKELY_REGION[tag.language]);
451
465
  } catch {
452
- const match = locale?.match(/^([a-z]{2,3})(?:[-_][A-Za-z]{4})?(?:[-_]([A-Za-z]{2}))?(?:[-_]|$)/);
466
+ const match = raw.match(/^([a-z]{2,3})(?:[-_][A-Za-z]{4})?(?:[-_]([A-Za-z]{2}))?(?:[-_]|$)/);
453
467
  if (!match) return DEFAULT_WEEK_START;
454
468
  return weekStartFromRegion(match[2] ?? LIKELY_REGION[match[1] ?? ""]);
455
469
  }
@@ -22,12 +22,15 @@ import {
22
22
  } from "./calendar.date";
23
23
  import type { CalendarProps, CalendarSelection } from "./calendar.types";
24
24
  import {
25
+ CALENDAR_NO_PAGING,
26
+ type CalendarPaging,
25
27
  type CalendarView,
26
28
  calendarVariants,
27
29
  isDateSelected,
28
30
  isMonthInBounds,
29
31
  reconcileVisibleMonth,
30
32
  resolveCalendarAxes,
33
+ resolveCommittedPageDirection,
31
34
  resolveMonthBounds,
32
35
  resolveRangeRole,
33
36
  resolveSelectionPage,
@@ -166,14 +169,19 @@ function CalendarRoot(props: CalendarProps): ReactElement {
166
169
  const visibleMonth = useMemo(() => startOfMonth(visibleMonthRaw), [visibleMonthRaw]);
167
170
 
168
171
  const [view, setView] = useState<CalendarView>("days");
169
- const [pageDirection, setPageDirection] = useState<-1 | 0 | 1>(0);
172
+ // The direction counts only for the month the calendar paged to. When `month` changes from
173
+ // outside, the stale page is dropped during render, so the new month never slides in from the
174
+ // side of an earlier page.
175
+ const [paging, setPaging] = useState<CalendarPaging>(CALENDAR_NO_PAGING);
176
+ if (paging.month && !isSameMonth(paging.month, visibleMonth)) setPaging(CALENDAR_NO_PAGING);
177
+ const pageDirection = resolveCommittedPageDirection(paging, visibleMonth);
170
178
 
171
179
  // New bounds can leave the visible month outside them. Move it to the nearest bound and report
172
180
  // the change, so the arrows and the swipe always have somewhere to go.
173
181
  useEffect(() => {
174
182
  const held = reconcileVisibleMonth(visibleMonth, monthBounds);
175
183
  if (!held) return;
176
- setPageDirection(0);
184
+ setPaging(CALENDAR_NO_PAGING);
177
185
  setVisibleMonth(held);
178
186
  }, [monthBounds, setVisibleMonth, visibleMonth]);
179
187
 
@@ -181,7 +189,7 @@ function CalendarRoot(props: CalendarProps): ReactElement {
181
189
  (date: CalendarDate) => {
182
190
  const target = startOfMonth(clampDate(startOfMonth(date), monthBounds.first, monthBounds.last));
183
191
  if (isSameMonth(target, visibleMonth)) return;
184
- setPageDirection(0);
192
+ setPaging(CALENDAR_NO_PAGING);
185
193
  setVisibleMonth(target);
186
194
  },
187
195
  [monthBounds.first, monthBounds.last, setVisibleMonth, visibleMonth]
@@ -204,7 +212,7 @@ function CalendarRoot(props: CalendarProps): ReactElement {
204
212
  const target = addMonths(visibleMonth, direction * step);
205
213
  const held = startOfMonth(clampDate(target, monthBounds.first, monthBounds.last));
206
214
  if (compareMonths(held, visibleMonth) === 0) return;
207
- setPageDirection(view === "days" ? direction : 0);
215
+ setPaging({ direction: view === "days" ? direction : 0, month: held });
208
216
  setVisibleMonth(held);
209
217
  },
210
218
  [monthBounds.first, monthBounds.last, setVisibleMonth, step, view, visibleMonth]
@@ -223,8 +231,9 @@ function CalendarRoot(props: CalendarProps): ReactElement {
223
231
  setSelection(nextSelection(selection, date, isDateDisabled));
224
232
  const direction = resolveSelectionPage(date, visibleMonth, monthBounds);
225
233
  if (direction === 0) return;
226
- setPageDirection(direction);
227
- setVisibleMonth(startOfMonth(date));
234
+ const target = startOfMonth(date);
235
+ setPaging({ direction, month: target });
236
+ setVisibleMonth(target);
228
237
  },
229
238
  [
230
239
  axes.isDisabled,
@@ -14,6 +14,7 @@ import {
14
14
  reconcileVisibleMonth,
15
15
  resolveCalendarAxes,
16
16
  resolveCaptionPage,
17
+ resolveCommittedPageDirection,
17
18
  resolveDayState,
18
19
  resolveDayTone,
19
20
  resolveMonthBounds,
@@ -410,6 +411,18 @@ describe("resolvePageDirection", () => {
410
411
  });
411
412
  });
412
413
 
414
+ describe("resolveCommittedPageDirection", () => {
415
+ test("slides the month the calendar paged to in from the side it paged", () => {
416
+ expect(resolveCommittedPageDirection({ direction: 1, month: d(2026, 11, 1) }, d(2026, 11, 1))).toBe(1);
417
+ expect(resolveCommittedPageDirection({ direction: -1, month: d(2026, 9, 1) }, d(2026, 9, 1))).toBe(-1);
418
+ });
419
+
420
+ test("does not slide a month the parent set", () => {
421
+ expect(resolveCommittedPageDirection({ direction: 1, month: d(2026, 11, 1) }, d(2026, 3, 1))).toBe(0);
422
+ expect(resolveCommittedPageDirection({ direction: 0, month: null }, d(2026, 3, 1))).toBe(0);
423
+ });
424
+ });
425
+
413
426
  describe("resolveCaptionPage", () => {
414
427
  const open = { canGoNext: true, canGoPrev: true, isDisabled: false, view: "days" } as const;
415
428
 
@@ -406,6 +406,22 @@ export function resolveCaptionPage({
406
406
  return 0;
407
407
  }
408
408
 
409
+ /** A page the calendar asked for: the month it moved to, and the side that month enters from. */
410
+ export type CalendarPaging = { direction: -1 | 0 | 1; month: CalendarDate | null };
411
+
412
+ /** No page in flight: the next month change, wherever it comes from, does not slide. */
413
+ export const CALENDAR_NO_PAGING: CalendarPaging = { direction: 0, month: null };
414
+
415
+ /**
416
+ * Which way the grid slides the visible month in. It uses the paging direction only while the
417
+ * calendar itself moved to that month. A month that the parent sets through a controlled `month`
418
+ * gets `0`. Without this check, reopening a picker on an earlier month after "next" would slide
419
+ * that month in from the right.
420
+ */
421
+ export function resolveCommittedPageDirection(paging: CalendarPaging, visibleMonth: CalendarDate): -1 | 0 | 1 {
422
+ return paging.month && isSameMonth(paging.month, visibleMonth) ? paging.direction : 0;
423
+ }
424
+
409
425
  /**
410
426
  * Which way a released swipe pages: `1` forward, `-1` back, `0` settle where it was.
411
427
  *