@terreno/ui 56.0.0-beta.0 → 56.0.0-beta.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.
@@ -1,9 +1,15 @@
1
- // noExplicitAny: test mock typing
2
- // biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
3
- import {afterAll, afterEach, beforeAll, describe, expect, it, mock} from "bun:test";
1
+ import {afterAll, afterEach, beforeAll, describe, expect, it, type Mock, mock} from "bun:test";
4
2
  import {act, render} from "@testing-library/react-native";
5
- import {createRef} from "react";
6
- import {Text} from "react-native";
3
+ import {createRef, type RefObject} from "react";
4
+ import {
5
+ Animated,
6
+ Dimensions,
7
+ type KeyboardEvent,
8
+ type LayoutChangeEvent,
9
+ type NativeScrollEvent,
10
+ type NativeSyntheticEvent,
11
+ Text,
12
+ } from "react-native";
7
13
 
8
14
  import {
9
15
  ActionSheet,
@@ -14,11 +20,32 @@ import {
14
20
  } from "./ActionSheet";
15
21
  import {ThemeProvider} from "./Theme";
16
22
 
23
+ const scrollEvent = (y: number): NativeSyntheticEvent<NativeScrollEvent> =>
24
+ ({nativeEvent: {contentOffset: {x: 0, y}}}) as NativeSyntheticEvent<NativeScrollEvent>;
25
+
26
+ const layoutEvent = (height: number, width: number): LayoutChangeEvent =>
27
+ ({nativeEvent: {layout: {height, width, x: 0, y: 0}}}) as LayoutChangeEvent;
28
+
29
+ /** Stands in for the SafeAreaView ref, whose measureInWindow reports `height`. */
30
+ const measuringSafeAreaRef = (
31
+ height: number
32
+ ): React.RefObject<{
33
+ measureInWindow: (
34
+ callback: (x: number, y: number, width: number, height: number) => void
35
+ ) => void;
36
+ }> => ({
37
+ current: {
38
+ measureInWindow: (callback) => {
39
+ callback(0, 0, 100, height);
40
+ },
41
+ },
42
+ });
43
+
17
44
  beforeAll(() => {
18
- (global as any).requestAnimationFrame = (callback: FrameRequestCallback) => {
45
+ globalThis.requestAnimationFrame = (callback: FrameRequestCallback) => {
19
46
  return setTimeout(() => callback(Date.now()), 0) as unknown as number;
20
47
  };
21
- (global as any).cancelAnimationFrame = (id: number) => {
48
+ globalThis.cancelAnimationFrame = (id: number) => {
22
49
  clearTimeout(id);
23
50
  };
24
51
  });
@@ -232,7 +259,7 @@ describe("ActionSheet", () => {
232
259
  act(() => {
233
260
  ref.current?.show();
234
261
  });
235
- expect(() => (ref.current as any)._onRequestClose()).not.toThrow();
262
+ expect(() => ref.current!._onRequestClose()).not.toThrow();
236
263
  });
237
264
 
238
265
  it("_onTouchBackdrop hides modal when closeOnTouchBackdrop is true", () => {
@@ -247,7 +274,7 @@ describe("ActionSheet", () => {
247
274
  act(() => {
248
275
  ref.current?.show();
249
276
  });
250
- expect(() => (ref.current as any)._onTouchBackdrop()).not.toThrow();
277
+ expect(() => ref.current!._onTouchBackdrop()).not.toThrow();
251
278
  });
252
279
 
253
280
  it("_onRequestClose does not hide when closeOnPressBack is false", () => {
@@ -262,7 +289,7 @@ describe("ActionSheet", () => {
262
289
  act(() => {
263
290
  ref.current?.show();
264
291
  });
265
- (ref.current as any)._onRequestClose();
292
+ ref.current!._onRequestClose();
266
293
  expect(ref.current?.state.modalVisible).toBe(true);
267
294
  });
268
295
 
@@ -278,7 +305,7 @@ describe("ActionSheet", () => {
278
305
  act(() => {
279
306
  ref.current?.show();
280
307
  });
281
- (ref.current as any)._onTouchBackdrop();
308
+ ref.current!._onTouchBackdrop();
282
309
  expect(ref.current?.state.modalVisible).toBe(true);
283
310
  });
284
311
 
@@ -291,11 +318,7 @@ describe("ActionSheet", () => {
291
318
  </ActionSheet>
292
319
  </ThemeProvider>
293
320
  );
294
- expect(() =>
295
- (ref.current as any)._onScroll({
296
- nativeEvent: {contentOffset: {x: 0, y: 10}},
297
- })
298
- ).not.toThrow();
321
+ expect(() => ref.current!._onScroll(scrollEvent(10))).not.toThrow();
299
322
  });
300
323
 
301
324
  it("_onTouchStart and _onTouchMove do not throw", () => {
@@ -307,9 +330,9 @@ describe("ActionSheet", () => {
307
330
  </ActionSheet>
308
331
  </ThemeProvider>
309
332
  );
310
- expect(() => (ref.current as any)._onTouchStart()).not.toThrow();
311
- expect(() => (ref.current as any)._onTouchMove()).not.toThrow();
312
- expect(() => (ref.current as any)._onTouchEnd()).not.toThrow();
333
+ expect(() => ref.current!._onTouchStart()).not.toThrow();
334
+ expect(() => ref.current!._onTouchMove()).not.toThrow();
335
+ expect(() => ref.current!._onTouchEnd()).not.toThrow();
313
336
  });
314
337
 
315
338
  describe("getDeviceHeight", () => {
@@ -356,7 +379,7 @@ describe("ActionSheet", () => {
356
379
  </ActionSheet>
357
380
  </ThemeProvider>
358
381
  );
359
- const result = await (ref.current as any).measure();
382
+ const result = await ref.current!.measure();
360
383
  expect(result).toBe(20);
361
384
  });
362
385
 
@@ -369,14 +392,8 @@ describe("ActionSheet", () => {
369
392
  </ActionSheet>
370
393
  </ThemeProvider>
371
394
  );
372
- (ref.current as any).safeAreaViewRef = {
373
- current: {
374
- measureInWindow: (_cb: any) => {
375
- _cb(0, 0, 100, 44);
376
- },
377
- },
378
- };
379
- const result = await (ref.current as any).measure();
395
+ ref.current!.safeAreaViewRef = measuringSafeAreaRef(44);
396
+ const result = await ref.current!.measure();
380
397
  expect(result).toBe(44);
381
398
  });
382
399
 
@@ -389,14 +406,8 @@ describe("ActionSheet", () => {
389
406
  </ActionSheet>
390
407
  </ThemeProvider>
391
408
  );
392
- (ref.current as any).safeAreaViewRef = {
393
- current: {
394
- measureInWindow: (_cb: any) => {
395
- _cb(0, 0, 100, 0);
396
- },
397
- },
398
- };
399
- const result = await (ref.current as any).measure();
409
+ ref.current!.safeAreaViewRef = measuringSafeAreaRef(0);
410
+ const result = await ref.current!.measure();
400
411
  expect(result).toBe(20);
401
412
  });
402
413
  });
@@ -411,7 +422,7 @@ describe("ActionSheet", () => {
411
422
  </ActionSheet>
412
423
  </ThemeProvider>
413
424
  );
414
- await (ref.current as any)._showModal({});
425
+ await ref.current!._showModal({} as LayoutChangeEvent);
415
426
  expect(ref.current).toBeTruthy();
416
427
  });
417
428
 
@@ -425,10 +436,8 @@ describe("ActionSheet", () => {
425
436
  </ThemeProvider>
426
437
  );
427
438
  ref.current!.layoutHasCalled = false;
428
- await (ref.current as any)._showModal({
429
- nativeEvent: {layout: {height: 500, width: 400}},
430
- });
431
- expect((ref.current as any).actionSheetHeight).toBe(500);
439
+ await ref.current!._showModal(layoutEvent(500, 400));
440
+ expect(ref.current!.actionSheetHeight).toBe(500);
432
441
  expect(ref.current!.layoutHasCalled).toBe(true);
433
442
  });
434
443
 
@@ -442,11 +451,9 @@ describe("ActionSheet", () => {
442
451
  </ThemeProvider>
443
452
  );
444
453
  ref.current!.layoutHasCalled = true;
445
- (ref.current as any).actionSheetHeight = 400;
446
- await (ref.current as any)._showModal({
447
- nativeEvent: {layout: {height: 600, width: 400}},
448
- });
449
- expect((ref.current as any).actionSheetHeight).toBe(600);
454
+ ref.current!.actionSheetHeight = 400;
455
+ await ref.current!._showModal(layoutEvent(600, 400));
456
+ expect(ref.current!.actionSheetHeight).toBe(600);
450
457
  });
451
458
  });
452
459
 
@@ -460,7 +467,7 @@ describe("ActionSheet", () => {
460
467
  </ActionSheet>
461
468
  </ThemeProvider>
462
469
  );
463
- expect(() => (ref.current as any)._openAnimation(100)).not.toThrow();
470
+ expect(() => ref.current!._openAnimation(100)).not.toThrow();
464
471
  });
465
472
 
466
473
  it("sets opacity directly when animated is false", () => {
@@ -472,7 +479,7 @@ describe("ActionSheet", () => {
472
479
  </ActionSheet>
473
480
  </ThemeProvider>
474
481
  );
475
- expect(() => (ref.current as any)._openAnimation(100)).not.toThrow();
482
+ expect(() => ref.current!._openAnimation(100)).not.toThrow();
476
483
  });
477
484
  });
478
485
 
@@ -486,10 +493,8 @@ describe("ActionSheet", () => {
486
493
  </ActionSheet>
487
494
  </ThemeProvider>
488
495
  );
489
- await (ref.current as any)._onScrollBeginDrag({
490
- nativeEvent: {contentOffset: {y: 42}},
491
- });
492
- expect((ref.current as any).prevScroll).toBe(42);
496
+ await ref.current!._onScrollBeginDrag(scrollEvent(42));
497
+ expect(ref.current!.prevScroll).toBe(42);
493
498
  });
494
499
  });
495
500
 
@@ -503,11 +508,9 @@ describe("ActionSheet", () => {
503
508
  </ActionSheet>
504
509
  </ThemeProvider>
505
510
  );
506
- (ref.current as any).actionSheetHeight = 99999;
507
- (ref.current as any)._applyHeightLimiter();
508
- expect((ref.current as any).actionSheetHeight).toBeLessThanOrEqual(
509
- ref.current!.state.deviceHeight
510
- );
511
+ ref.current!.actionSheetHeight = 99999;
512
+ ref.current!._applyHeightLimiter();
513
+ expect(ref.current!.actionSheetHeight).toBeLessThanOrEqual(ref.current!.state.deviceHeight);
511
514
  });
512
515
 
513
516
  it("does not change actionSheetHeight when smaller than deviceHeight", () => {
@@ -519,9 +522,9 @@ describe("ActionSheet", () => {
519
522
  </ActionSheet>
520
523
  </ThemeProvider>
521
524
  );
522
- (ref.current as any).actionSheetHeight = 100;
523
- (ref.current as any)._applyHeightLimiter();
524
- expect((ref.current as any).actionSheetHeight).toBe(100);
525
+ ref.current!.actionSheetHeight = 100;
526
+ ref.current!._applyHeightLimiter();
527
+ expect(ref.current!.actionSheetHeight).toBe(100);
525
528
  });
526
529
  });
527
530
 
@@ -535,12 +538,10 @@ describe("ActionSheet", () => {
535
538
  </ActionSheet>
536
539
  </ThemeProvider>
537
540
  );
538
- (ref.current as any).prevScroll = 100;
539
- (ref.current as any).actionSheetHeight = 500;
540
- (ref.current as any).isRecoiling = false;
541
- await (ref.current as any)._onScrollEnd({
542
- nativeEvent: {contentOffset: {y: 200}},
543
- });
541
+ ref.current!.prevScroll = 100;
542
+ ref.current!.actionSheetHeight = 500;
543
+ ref.current!.isRecoiling = false;
544
+ await ref.current!._onScrollEnd(scrollEvent(200));
544
545
  expect(ref.current).toBeTruthy();
545
546
  });
546
547
 
@@ -553,10 +554,8 @@ describe("ActionSheet", () => {
553
554
  </ActionSheet>
554
555
  </ThemeProvider>
555
556
  );
556
- (ref.current as any).isRecoiling = true;
557
- await (ref.current as any)._onScrollEnd({
558
- nativeEvent: {contentOffset: {y: 50}},
559
- });
557
+ ref.current!.isRecoiling = true;
558
+ await ref.current!._onScrollEnd(scrollEvent(50));
560
559
  expect(ref.current).toBeTruthy();
561
560
  });
562
561
 
@@ -569,11 +568,9 @@ describe("ActionSheet", () => {
569
568
  </ActionSheet>
570
569
  </ThemeProvider>
571
570
  );
572
- (ref.current as any).prevScroll = 200;
573
- (ref.current as any).isRecoiling = false;
574
- await (ref.current as any)._onScrollEnd({
575
- nativeEvent: {contentOffset: {y: 50}},
576
- });
571
+ ref.current!.prevScroll = 200;
572
+ ref.current!.isRecoiling = false;
573
+ await ref.current!._onScrollEnd(scrollEvent(50));
577
574
  expect(ref.current).toBeTruthy();
578
575
  });
579
576
 
@@ -586,11 +583,9 @@ describe("ActionSheet", () => {
586
583
  </ActionSheet>
587
584
  </ThemeProvider>
588
585
  );
589
- (ref.current as any).prevScroll = 100;
590
- (ref.current as any).isRecoiling = false;
591
- await (ref.current as any)._onScrollEnd({
592
- nativeEvent: {contentOffset: {y: 95}},
593
- });
586
+ ref.current!.prevScroll = 100;
587
+ ref.current!.isRecoiling = false;
588
+ await ref.current!._onScrollEnd(scrollEvent(95));
594
589
  expect(ref.current).toBeTruthy();
595
590
  });
596
591
 
@@ -603,17 +598,53 @@ describe("ActionSheet", () => {
603
598
  </ActionSheet>
604
599
  </ThemeProvider>
605
600
  );
606
- (ref.current as any).prevScroll = 100;
607
- (ref.current as any).actionSheetHeight = 500;
608
- (ref.current as any).isRecoiling = false;
609
- await (ref.current as any)._onScrollEnd({
610
- nativeEvent: {contentOffset: {y: 110}},
611
- });
601
+ ref.current!.prevScroll = 100;
602
+ ref.current!.actionSheetHeight = 500;
603
+ ref.current!.isRecoiling = false;
604
+ await ref.current!._onScrollEnd(scrollEvent(110));
612
605
  expect(ref.current).toBeTruthy();
613
606
  });
614
607
  });
615
608
 
616
609
  describe("_onKeyboardShow", () => {
610
+ const timing = (Animated as unknown as {timing: Mock<(...args: never[]) => unknown>}).timing;
611
+
612
+ /**
613
+ * Focuses a field at `pageY` with a 40pt height and measures it synchronously, mirroring
614
+ * how UIManager.measure calls back on a real device.
615
+ */
616
+ const withFocusedField = (pageY: number, run: () => void): void => {
617
+ const {TextInput: MockTextInput, UIManager: MockUIManager} = require("react-native");
618
+ const origState = MockTextInput.State;
619
+ const origMeasure = MockUIManager.measure;
620
+ MockTextInput.State = {currentlyFocusedField: () => 42};
621
+ MockUIManager.measure = (
622
+ _node: number,
623
+ callback: (
624
+ originX: number,
625
+ originY: number,
626
+ width: number,
627
+ height: number,
628
+ pageX: number,
629
+ pageY: number
630
+ ) => void
631
+ ): void => {
632
+ callback(0, 0, 100, 40, 0, pageY);
633
+ };
634
+ try {
635
+ run();
636
+ } finally {
637
+ MockTextInput.State = origState;
638
+ MockUIManager.measure = origMeasure;
639
+ }
640
+ };
641
+
642
+ const showKeyboard = (ref: RefObject<ActionSheet | null>, keyboardHeight: number): void => {
643
+ ref.current?._onKeyboardShow({
644
+ endCoordinates: {height: keyboardHeight, screenX: 0, screenY: 500, width: 400},
645
+ } as KeyboardEvent);
646
+ };
647
+
617
648
  it("sets keyboard state to true and handles no focused field", () => {
618
649
  const ref = createRef<ActionSheet>();
619
650
  render(
@@ -628,16 +659,16 @@ describe("ActionSheet", () => {
628
659
  MockTextInput.State = {
629
660
  currentlyFocusedField: () => null,
630
661
  };
662
+ const timingCallsBefore = timing.mock.calls.length;
631
663
  act(() => {
632
- (ref.current as any)._onKeyboardShow({
633
- endCoordinates: {height: 300, screenX: 0, screenY: 500, width: 400},
634
- });
664
+ showKeyboard(ref, 300);
635
665
  });
636
666
  expect(ref.current!.state.keyboard).toBe(true);
667
+ expect(timing.mock.calls.length).toBe(timingCallsBefore);
637
668
  MockTextInput.State = origState;
638
669
  });
639
670
 
640
- it("handles keyboard show with focused field", () => {
671
+ it("does not animate when the focused field stays above the keyboard", () => {
641
672
  const ref = createRef<ActionSheet>();
642
673
  render(
643
674
  <ThemeProvider>
@@ -646,26 +677,19 @@ describe("ActionSheet", () => {
646
677
  </ActionSheet>
647
678
  </ThemeProvider>
648
679
  );
649
- const {TextInput: MockTextInput, UIManager: MockUIManager} = require("react-native");
650
- const origState = MockTextInput.State;
651
- const origMeasure = MockUIManager.measure;
652
- MockTextInput.State = {
653
- currentlyFocusedField: () => 42,
654
- };
655
- MockUIManager.measure = (_node: any, cb: any) => {
656
- cb(0, 0, 100, 40, 0, 400);
657
- };
658
- act(() => {
659
- (ref.current as any)._onKeyboardShow({
660
- endCoordinates: {height: 300, screenX: 0, screenY: 500, width: 400},
680
+ const timingCallsBefore = timing.mock.calls.length;
681
+ withFocusedField(400, () => {
682
+ act(() => {
683
+ showKeyboard(ref, 300);
661
684
  });
662
685
  });
663
686
  expect(ref.current!.state.keyboard).toBe(true);
664
- MockTextInput.State = origState;
665
- MockUIManager.measure = origMeasure;
687
+ // windowHeight (896) - keyboardHeight (300) - (pageY (400) + fieldHeight (40)) = 156 above
688
+ // the keyboard, so no animation is needed.
689
+ expect(timing.mock.calls.length).toBe(timingCallsBefore);
666
690
  });
667
691
 
668
- it("handles keyboard show with enough gap (no animation needed)", () => {
692
+ it("animates the sheet up by the overlap when the keyboard covers the focused field", () => {
669
693
  const ref = createRef<ActionSheet>();
670
694
  render(
671
695
  <ThemeProvider>
@@ -674,23 +698,35 @@ describe("ActionSheet", () => {
674
698
  </ActionSheet>
675
699
  </ThemeProvider>
676
700
  );
677
- const {TextInput: MockTextInput, UIManager: MockUIManager} = require("react-native");
678
- const origState = MockTextInput.State;
679
- const origMeasure = MockUIManager.measure;
680
- MockTextInput.State = {
681
- currentlyFocusedField: () => 42,
682
- };
683
- MockUIManager.measure = (_node: any, cb: any) => {
684
- cb(0, 0, 100, 40, 0, 100);
685
- };
686
- act(() => {
687
- (ref.current as any)._onKeyboardShow({
688
- endCoordinates: {height: 100, screenX: 0, screenY: 500, width: 400},
701
+ const timingCallsBefore = timing.mock.calls.length;
702
+ withFocusedField(800, () => {
703
+ act(() => {
704
+ showKeyboard(ref, 300);
689
705
  });
690
706
  });
691
- expect(ref.current!.state.keyboard).toBe(true);
692
- MockTextInput.State = origState;
693
- MockUIManager.measure = origMeasure;
707
+ const {height: windowHeight} = Dimensions.get("window");
708
+ const gap = windowHeight - 300 - (800 + 40);
709
+ expect(timing.mock.calls.length).toBe(timingCallsBefore + 1);
710
+ expect(timing.mock.calls[timingCallsBefore][1].toValue).toBe(gap - 10);
711
+ });
712
+
713
+ it("shifts by the keyboard height instead of the overlap in position keyboard mode", () => {
714
+ const ref = createRef<ActionSheet>();
715
+ render(
716
+ <ThemeProvider>
717
+ <ActionSheet keyboardMode="position" ref={ref}>
718
+ <Text>Content</Text>
719
+ </ActionSheet>
720
+ </ThemeProvider>
721
+ );
722
+ const timingCallsBefore = timing.mock.calls.length;
723
+ withFocusedField(800, () => {
724
+ act(() => {
725
+ showKeyboard(ref, 300);
726
+ });
727
+ });
728
+ expect(timing.mock.calls.length).toBe(timingCallsBefore + 1);
729
+ expect(timing.mock.calls[timingCallsBefore][1].toValue).toBe(-(300 + 15));
694
730
  });
695
731
  });
696
732
 
@@ -705,7 +741,7 @@ describe("ActionSheet", () => {
705
741
  </ThemeProvider>
706
742
  );
707
743
  act(() => {
708
- (ref.current as any)._onKeyboardHide();
744
+ ref.current!._onKeyboardHide();
709
745
  });
710
746
  expect(ref.current!.state.keyboard).toBe(false);
711
747
  });
@@ -721,9 +757,9 @@ describe("ActionSheet", () => {
721
757
  </ActionSheet>
722
758
  </ThemeProvider>
723
759
  );
724
- (ref.current as any).offsetY = 200;
725
- (ref.current as any).prevScroll = 100;
726
- await (ref.current as any).handleChildScrollEnd();
760
+ ref.current!.offsetY = 200;
761
+ ref.current!.prevScroll = 100;
762
+ await ref.current!.handleChildScrollEnd();
727
763
  expect(ref.current).toBeTruthy();
728
764
  });
729
765
 
@@ -736,10 +772,10 @@ describe("ActionSheet", () => {
736
772
  </ActionSheet>
737
773
  </ThemeProvider>
738
774
  );
739
- (ref.current as any).offsetY = 0;
740
- (ref.current as any).prevScroll = 200;
741
- (ref.current as any).actionSheetHeight = 500;
742
- await (ref.current as any).handleChildScrollEnd();
775
+ ref.current!.offsetY = 0;
776
+ ref.current!.prevScroll = 200;
777
+ ref.current!.actionSheetHeight = 500;
778
+ await ref.current!.handleChildScrollEnd();
743
779
  expect(ref.current).toBeTruthy();
744
780
  });
745
781
 
@@ -752,9 +788,9 @@ describe("ActionSheet", () => {
752
788
  </ActionSheet>
753
789
  </ThemeProvider>
754
790
  );
755
- (ref.current as any).offsetY = 90;
756
- (ref.current as any).prevScroll = 100;
757
- await (ref.current as any).handleChildScrollEnd();
791
+ ref.current!.offsetY = 90;
792
+ ref.current!.prevScroll = 100;
793
+ await ref.current!.handleChildScrollEnd();
758
794
  expect(ref.current).toBeTruthy();
759
795
  });
760
796
 
@@ -767,10 +803,10 @@ describe("ActionSheet", () => {
767
803
  </ActionSheet>
768
804
  </ThemeProvider>
769
805
  );
770
- (ref.current as any).offsetY = 50;
771
- (ref.current as any).prevScroll = 200;
772
- (ref.current as any).actionSheetHeight = 200;
773
- await (ref.current as any).handleChildScrollEnd();
806
+ ref.current!.offsetY = 50;
807
+ ref.current!.prevScroll = 200;
808
+ ref.current!.actionSheetHeight = 200;
809
+ await ref.current!.handleChildScrollEnd();
774
810
  expect(ref.current).toBeTruthy();
775
811
  });
776
812
  });
@@ -800,11 +836,9 @@ describe("ActionSheet", () => {
800
836
  </ThemeProvider>
801
837
  );
802
838
  const existingTimeout = setTimeout(() => {}, 1000);
803
- (ref.current as any).timeout = existingTimeout;
804
- (ref.current as any)._onDeviceLayout({
805
- nativeEvent: {layout: {height: 812, width: 375}},
806
- });
807
- const newTimeout = (ref.current as any).timeout;
839
+ ref.current!.timeout = existingTimeout;
840
+ ref.current!._onDeviceLayout(layoutEvent(812, 375));
841
+ const newTimeout = ref.current!.timeout;
808
842
  expect(newTimeout).not.toBe(existingTimeout);
809
843
  clearTimeout(newTimeout);
810
844
  });
@@ -820,8 +854,8 @@ describe("ActionSheet", () => {
820
854
  </ActionSheet>
821
855
  </ThemeProvider>
822
856
  );
823
- (ref.current as any).actionSheetHeight = 500;
824
- const pos = (ref.current as any).getInitialScrollPosition();
857
+ ref.current!.actionSheetHeight = 500;
858
+ const pos = ref.current!.getInitialScrollPosition();
825
859
  expect(typeof pos).toBe("number");
826
860
  });
827
861
 
@@ -834,8 +868,8 @@ describe("ActionSheet", () => {
834
868
  </ActionSheet>
835
869
  </ThemeProvider>
836
870
  );
837
- (ref.current as any).actionSheetHeight = 500;
838
- const pos = (ref.current as any).getInitialScrollPosition();
871
+ ref.current!.actionSheetHeight = 500;
872
+ const pos = ref.current!.getInitialScrollPosition();
839
873
  expect(typeof pos).toBe("number");
840
874
  });
841
875
  });
@@ -853,9 +887,9 @@ describe("ActionSheet", () => {
853
887
  act(() => {
854
888
  ref.current?.show();
855
889
  });
856
- (ref.current as any).isClosing = false;
890
+ ref.current!.isClosing = false;
857
891
  act(() => {
858
- (ref.current as any)._hideAnimation();
892
+ ref.current!._hideAnimation();
859
893
  });
860
894
  await act(async () => {
861
895
  await new Promise((r) => setTimeout(r, 50));
@@ -875,9 +909,9 @@ describe("ActionSheet", () => {
875
909
  act(() => {
876
910
  ref.current?.show();
877
911
  });
878
- (ref.current as any).isClosing = false;
912
+ ref.current!.isClosing = false;
879
913
  act(() => {
880
- (ref.current as any)._hideAnimation();
914
+ ref.current!._hideAnimation();
881
915
  });
882
916
  await act(async () => {
883
917
  await new Promise((r) => setTimeout(r, 50));
@@ -896,7 +930,7 @@ describe("ActionSheet", () => {
896
930
  </ActionSheet>
897
931
  </ThemeProvider>
898
932
  );
899
- await expect((ref.current as any)._onScrollBegin()).resolves.toBeUndefined();
933
+ await expect(ref.current!._onScrollBegin()).resolves.toBeUndefined();
900
934
  });
901
935
  });
902
936
 
@@ -910,19 +944,19 @@ describe("ActionSheet", () => {
910
944
  </ActionSheet>
911
945
  </ThemeProvider>
912
946
  );
913
- (ref.current as any).actionSheetHeight = 100;
947
+ ref.current!.actionSheetHeight = 100;
914
948
  // scrollOffset ≈ 100*0.5 + deviceHeight*0.15 ≈ 150
915
949
  // Need offsetY > scrollOffset - 100, so offsetY = 120 works
916
- (ref.current as any).offsetY = 120;
917
- (ref.current as any).prevScroll = 200;
950
+ ref.current!.offsetY = 120;
951
+ ref.current!.prevScroll = 200;
918
952
  await act(async () => {
919
- await (ref.current as any).handleChildScrollEnd();
953
+ await ref.current!.handleChildScrollEnd();
920
954
  });
921
- expect((ref.current as any).isRecoiling).toBe(true);
955
+ expect(ref.current!.isRecoiling).toBe(true);
922
956
  await act(async () => {
923
957
  await new Promise((r) => setTimeout(r, 600));
924
958
  });
925
- expect((ref.current as any).isRecoiling).toBe(false);
959
+ expect(ref.current!.isRecoiling).toBe(false);
926
960
  });
927
961
  });
928
962
 
@@ -936,16 +970,16 @@ describe("ActionSheet", () => {
936
970
  </ActionSheet>
937
971
  </ThemeProvider>
938
972
  );
939
- (ref.current as any).offsetY = 98;
940
- (ref.current as any).prevScroll = 100;
973
+ ref.current!.offsetY = 98;
974
+ ref.current!.prevScroll = 100;
941
975
  await act(async () => {
942
- await (ref.current as any).handleChildScrollEnd();
976
+ await ref.current!.handleChildScrollEnd();
943
977
  });
944
- expect((ref.current as any).isRecoiling).toBe(true);
978
+ expect(ref.current!.isRecoiling).toBe(true);
945
979
  await act(async () => {
946
980
  await new Promise((r) => setTimeout(r, 600));
947
981
  });
948
- expect((ref.current as any).isRecoiling).toBe(false);
982
+ expect(ref.current!.isRecoiling).toBe(false);
949
983
  });
950
984
 
951
985
  it("recoils when within scroll threshold of initial position", async () => {
@@ -957,7 +991,7 @@ describe("ActionSheet", () => {
957
991
  </ActionSheet>
958
992
  </ThemeProvider>
959
993
  );
960
- const instance = ref.current as any;
994
+ const instance = ref.current!;
961
995
  instance.actionSheetHeight = 500;
962
996
  instance.prevScroll = 300;
963
997
  instance.offsetY = 250;
@@ -983,7 +1017,7 @@ describe("ActionSheet", () => {
983
1017
  </ActionSheet>
984
1018
  </ThemeProvider>
985
1019
  );
986
- const instance = ref.current as any;
1020
+ const instance = ref.current!;
987
1021
  instance.actionSheetHeight = 500;
988
1022
  instance.prevScroll = 300;
989
1023
  instance.offsetY = 100;
@@ -1005,7 +1039,7 @@ describe("ActionSheet", () => {
1005
1039
  </ActionSheet>
1006
1040
  </ThemeProvider>
1007
1041
  );
1008
- const instance = ref.current as any;
1042
+ const instance = ref.current!;
1009
1043
  instance.actionSheetHeight = 500;
1010
1044
  instance.prevScroll = 300;
1011
1045
  instance.offsetY = 290;
@@ -1029,7 +1063,7 @@ describe("ActionSheet", () => {
1029
1063
  </ActionSheet>
1030
1064
  </ThemeProvider>
1031
1065
  );
1032
- const instance = ref.current as any;
1066
+ const instance = ref.current!;
1033
1067
  instance.prevScroll = 200;
1034
1068
  instance.offsetY = 195;
1035
1069
  instance._scrollTo = mock(() => {});
@@ -1057,14 +1091,12 @@ describe("ActionSheet", () => {
1057
1091
  </ThemeProvider>
1058
1092
  );
1059
1093
  await act(async () => {
1060
- (ref.current as any)._onDeviceLayout({
1061
- nativeEvent: {layout: {height: 800, width: 400}},
1062
- });
1094
+ ref.current!._onDeviceLayout(layoutEvent(800, 400));
1063
1095
  // measure() has a 100ms timeout on iOS; on android it uses StatusBar.currentHeight
1064
1096
  await new Promise((r) => setTimeout(r, 200));
1065
1097
  });
1066
1098
  // The callback should have run and set deviceLayoutCalled
1067
- expect((ref.current as any).deviceLayoutCalled).toBe(true);
1099
+ expect(ref.current!.deviceLayoutCalled).toBe(true);
1068
1100
  });
1069
1101
 
1070
1102
  it("updates state after layout timeout fires without drawUnderStatusBar on android", async () => {
@@ -1077,12 +1109,10 @@ describe("ActionSheet", () => {
1077
1109
  </ThemeProvider>
1078
1110
  );
1079
1111
  await act(async () => {
1080
- (ref.current as any)._onDeviceLayout({
1081
- nativeEvent: {layout: {height: 900, width: 400}},
1082
- });
1112
+ ref.current!._onDeviceLayout(layoutEvent(900, 400));
1083
1113
  await new Promise((r) => setTimeout(r, 200));
1084
1114
  });
1085
- expect((ref.current as any).deviceLayoutCalled).toBe(true);
1115
+ expect(ref.current!.deviceLayoutCalled).toBe(true);
1086
1116
  });
1087
1117
  });
1088
1118
  });