@lodev09/react-native-true-sheet 4.0.0-beta.2 → 4.0.0-beta.21

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 (205) hide show
  1. package/README.md +25 -4
  2. package/android/build.gradle +22 -1
  3. package/android/src/main/java/com/lodev09/truesheet/TrueSheetContainerView.kt +50 -16
  4. package/android/src/main/java/com/lodev09/truesheet/TrueSheetContentView.kt +303 -184
  5. package/android/src/main/java/com/lodev09/truesheet/TrueSheetContentViewManager.kt +5 -1
  6. package/android/src/main/java/com/lodev09/truesheet/TrueSheetFooterView.kt +21 -110
  7. package/android/src/main/java/com/lodev09/truesheet/TrueSheetOverlayView.kt +116 -0
  8. package/android/src/main/java/com/lodev09/truesheet/TrueSheetOverlayViewManager.kt +45 -0
  9. package/android/src/main/java/com/lodev09/truesheet/TrueSheetPackage.kt +2 -1
  10. package/android/src/main/java/com/lodev09/truesheet/TrueSheetStateUpdater.kt +18 -0
  11. package/android/src/main/java/com/lodev09/truesheet/TrueSheetView.kt +124 -50
  12. package/android/src/main/java/com/lodev09/truesheet/TrueSheetViewController.kt +369 -163
  13. package/android/src/main/java/com/lodev09/truesheet/TrueSheetViewManager.kt +59 -12
  14. package/android/src/main/java/com/lodev09/truesheet/core/TrueSheetBottomSheetBehavior.kt +126 -0
  15. package/android/src/main/java/com/lodev09/truesheet/core/TrueSheetBottomSheetView.kt +22 -9
  16. package/android/src/main/java/com/lodev09/truesheet/core/TrueSheetCoordinatorLayout.kt +84 -5
  17. package/android/src/main/java/com/lodev09/truesheet/core/TrueSheetDetentCalculator.kt +104 -39
  18. package/android/src/main/java/com/lodev09/truesheet/core/TrueSheetDimView.kt +3 -0
  19. package/android/src/main/java/com/lodev09/truesheet/core/TrueSheetOverlayRootView.kt +137 -0
  20. package/android/src/main/java/com/lodev09/truesheet/events/TrueSheetLifecycleEvents.kt +15 -0
  21. package/android/src/main/java/com/lodev09/truesheet/utils/KeyboardUtils.kt +15 -2
  22. package/android/src/main/java/com/lodev09/truesheet/utils/ScreenUtils.kt +0 -12
  23. package/android/src/main/java/com/lodev09/truesheet/utils/ViewUtils.kt +19 -7
  24. package/android/src/main/jni/TrueSheetSpec.h +1 -0
  25. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetContentViewComponentDescriptor.h +1 -9
  26. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetContentViewShadowNode.cpp +110 -30
  27. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetContentViewShadowNode.h +30 -7
  28. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetContentViewState.cpp +2 -2
  29. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetContentViewState.h +9 -8
  30. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetFooterViewComponentDescriptor.h +3 -5
  31. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetFooterViewShadowNode.cpp +9 -3
  32. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetFooterViewShadowNode.h +3 -6
  33. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetFooterViewState.cpp +1 -1
  34. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetFooterViewState.h +4 -6
  35. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetInsets.cpp +1 -1
  36. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetInsets.h +1 -1
  37. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetLayoutUtils.h +43 -0
  38. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetOverlayViewComponentDescriptor.h +21 -0
  39. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetOverlayViewShadowNode.cpp +17 -0
  40. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetOverlayViewShadowNode.h +33 -0
  41. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetViewComponentDescriptor.h +3 -5
  42. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetViewShadowNode.cpp +7 -40
  43. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetViewShadowNode.h +3 -7
  44. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetViewState.cpp +3 -5
  45. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetViewState.h +4 -5
  46. package/ios/TrueSheetContainerView.h +27 -7
  47. package/ios/TrueSheetContainerView.mm +31 -11
  48. package/ios/TrueSheetContentView.h +43 -15
  49. package/ios/TrueSheetContentView.mm +211 -189
  50. package/ios/TrueSheetFooterView.h +6 -0
  51. package/ios/TrueSheetFooterView.mm +93 -17
  52. package/ios/TrueSheetModule.h +2 -7
  53. package/ios/TrueSheetModule.mm +7 -16
  54. package/ios/TrueSheetOverlayView.h +32 -0
  55. package/ios/TrueSheetOverlayView.mm +161 -0
  56. package/ios/TrueSheetView.mm +275 -56
  57. package/ios/TrueSheetViewController.h +31 -3
  58. package/ios/TrueSheetViewController.mm +393 -94
  59. package/ios/core/TrueSheetBlurView.h +0 -2
  60. package/ios/core/TrueSheetBlurView.mm +3 -36
  61. package/ios/core/TrueSheetDetentCalculator.h +7 -1
  62. package/ios/core/TrueSheetDetentCalculator.mm +27 -4
  63. package/ios/core/TrueSheetGrabberView.mm +13 -3
  64. package/ios/core/TrueSheetKeyboardObserver.mm +2 -0
  65. package/ios/core/TrueSheetOverlayContainerView.h +31 -0
  66. package/ios/core/TrueSheetOverlayContainerView.mm +35 -0
  67. package/ios/events/TrueSheetLifecycleEvents.h +2 -0
  68. package/ios/events/TrueSheetLifecycleEvents.mm +8 -0
  69. package/ios/tvos/TrueSheetStubs.mm +12 -0
  70. package/ios/utils/UIView+ScrollEdgeInteraction.h +1 -0
  71. package/ios/utils/UIView+ScrollEdgeInteraction.mm +24 -2
  72. package/lib/module/TrueSheet.js +175 -39
  73. package/lib/module/TrueSheet.js.map +1 -1
  74. package/lib/module/TrueSheet.web.js +220 -243
  75. package/lib/module/TrueSheet.web.js.map +1 -1
  76. package/lib/module/TrueSheetBackground.js +15 -0
  77. package/lib/module/TrueSheetBackground.js.map +1 -0
  78. package/lib/module/TrueSheetOverlay.js +30 -0
  79. package/lib/module/TrueSheetOverlay.js.map +1 -0
  80. package/lib/module/TrueSheetOverlay.web.js +35 -0
  81. package/lib/module/TrueSheetOverlay.web.js.map +1 -0
  82. package/lib/module/TrueSheetPeek.web.js +20 -15
  83. package/lib/module/TrueSheetPeek.web.js.map +1 -1
  84. package/lib/module/detentBackgrounds.js +21 -0
  85. package/lib/module/detentBackgrounds.js.map +1 -0
  86. package/lib/module/fabric/TrueSheetContentViewNativeComponent.ts +1 -1
  87. package/lib/module/fabric/TrueSheetOverlayViewNativeComponent.ts +12 -0
  88. package/lib/module/fabric/TrueSheetViewNativeComponent.ts +15 -10
  89. package/lib/module/index.js +1 -0
  90. package/lib/module/index.js.map +1 -1
  91. package/lib/module/mocks/index.js +18 -2
  92. package/lib/module/mocks/index.js.map +1 -1
  93. package/lib/module/mocks/navigationExpoRouter.js.map +1 -1
  94. package/lib/module/navigation/base-types.js +2 -0
  95. package/lib/module/navigation/base-types.js.map +1 -0
  96. package/lib/module/navigation/createTrueSheetRouter.js +0 -9
  97. package/lib/module/navigation/createTrueSheetRouter.js.map +1 -1
  98. package/lib/module/navigation/expo-router/base-types.js +2 -0
  99. package/lib/module/navigation/expo-router/base-types.js.map +1 -0
  100. package/lib/module/navigation/expo-router/index.js +10 -7
  101. package/lib/module/navigation/expo-router/index.js.map +1 -1
  102. package/lib/module/navigation/expo-router/types.js +4 -0
  103. package/lib/module/navigation/expo-router/types.js.map +1 -0
  104. package/lib/module/navigation/index.js.map +1 -1
  105. package/lib/module/navigation/screen/useSheetScreenState.js +1 -0
  106. package/lib/module/navigation/screen/useSheetScreenState.js.map +1 -1
  107. package/lib/module/web/constants.js +1 -1
  108. package/lib/module/web/constants.js.map +1 -1
  109. package/lib/module/web/layout.js +168 -0
  110. package/lib/module/web/layout.js.map +1 -0
  111. package/lib/module/web/vaul/constants.js +9 -0
  112. package/lib/module/web/vaul/constants.js.map +1 -1
  113. package/lib/module/web/vaul/context.js.map +1 -1
  114. package/lib/module/web/vaul/helpers.js +1 -0
  115. package/lib/module/web/vaul/helpers.js.map +1 -1
  116. package/lib/module/web/vaul/index.js +47 -7
  117. package/lib/module/web/vaul/index.js.map +1 -1
  118. package/lib/module/web/vaul/use-snap-points.js +21 -10
  119. package/lib/module/web/vaul/use-snap-points.js.map +1 -1
  120. package/lib/typescript/src/TrueSheet.d.ts +6 -0
  121. package/lib/typescript/src/TrueSheet.d.ts.map +1 -1
  122. package/lib/typescript/src/TrueSheet.types.d.ts +157 -34
  123. package/lib/typescript/src/TrueSheet.types.d.ts.map +1 -1
  124. package/lib/typescript/src/TrueSheet.web.d.ts.map +1 -1
  125. package/lib/typescript/src/TrueSheetBackground.d.ts +3 -0
  126. package/lib/typescript/src/TrueSheetBackground.d.ts.map +1 -0
  127. package/lib/typescript/src/TrueSheetOverlay.d.ts +8 -0
  128. package/lib/typescript/src/TrueSheetOverlay.d.ts.map +1 -0
  129. package/lib/typescript/src/TrueSheetOverlay.web.d.ts +8 -0
  130. package/lib/typescript/src/TrueSheetOverlay.web.d.ts.map +1 -0
  131. package/lib/typescript/src/TrueSheetPeek.web.d.ts +8 -4
  132. package/lib/typescript/src/TrueSheetPeek.web.d.ts.map +1 -1
  133. package/lib/typescript/src/detentBackgrounds.d.ts +10 -0
  134. package/lib/typescript/src/detentBackgrounds.d.ts.map +1 -0
  135. package/lib/typescript/src/fabric/TrueSheetOverlayViewNativeComponent.d.ts +6 -0
  136. package/lib/typescript/src/fabric/TrueSheetOverlayViewNativeComponent.d.ts.map +1 -0
  137. package/lib/typescript/src/fabric/TrueSheetViewNativeComponent.d.ts +12 -7
  138. package/lib/typescript/src/fabric/TrueSheetViewNativeComponent.d.ts.map +1 -1
  139. package/lib/typescript/src/index.d.ts +1 -0
  140. package/lib/typescript/src/index.d.ts.map +1 -1
  141. package/lib/typescript/src/mocks/index.d.ts +4 -0
  142. package/lib/typescript/src/mocks/index.d.ts.map +1 -1
  143. package/lib/typescript/src/mocks/navigationExpoRouter.d.ts +3 -3
  144. package/lib/typescript/src/mocks/navigationExpoRouter.d.ts.map +1 -1
  145. package/lib/typescript/src/navigation/base-types.d.ts +9 -0
  146. package/lib/typescript/src/navigation/base-types.d.ts.map +1 -0
  147. package/lib/typescript/src/navigation/createTrueSheetRouter.d.ts +2 -13
  148. package/lib/typescript/src/navigation/createTrueSheetRouter.d.ts.map +1 -1
  149. package/lib/typescript/src/navigation/expo-router/base-types.d.ts +8 -0
  150. package/lib/typescript/src/navigation/expo-router/base-types.d.ts.map +1 -0
  151. package/lib/typescript/src/navigation/expo-router/index.d.ts +8 -6
  152. package/lib/typescript/src/navigation/expo-router/index.d.ts.map +1 -1
  153. package/lib/typescript/src/navigation/expo-router/types.d.ts +44 -0
  154. package/lib/typescript/src/navigation/expo-router/types.d.ts.map +1 -0
  155. package/lib/typescript/src/navigation/index.d.ts +3 -4
  156. package/lib/typescript/src/navigation/index.d.ts.map +1 -1
  157. package/lib/typescript/src/navigation/screen/useSheetScreenState.d.ts +2 -1
  158. package/lib/typescript/src/navigation/screen/useSheetScreenState.d.ts.map +1 -1
  159. package/lib/typescript/src/navigation/types.d.ts +41 -5
  160. package/lib/typescript/src/navigation/types.d.ts.map +1 -1
  161. package/lib/typescript/src/web/constants.d.ts +1 -1
  162. package/lib/typescript/src/web/constants.d.ts.map +1 -1
  163. package/lib/typescript/src/web/layout.d.ts +19 -0
  164. package/lib/typescript/src/web/layout.d.ts.map +1 -0
  165. package/lib/typescript/src/web/vaul/constants.d.ts +3 -0
  166. package/lib/typescript/src/web/vaul/constants.d.ts.map +1 -1
  167. package/lib/typescript/src/web/vaul/context.d.ts +1 -0
  168. package/lib/typescript/src/web/vaul/context.d.ts.map +1 -1
  169. package/lib/typescript/src/web/vaul/helpers.d.ts +1 -0
  170. package/lib/typescript/src/web/vaul/helpers.d.ts.map +1 -1
  171. package/lib/typescript/src/web/vaul/index.d.ts +13 -1
  172. package/lib/typescript/src/web/vaul/index.d.ts.map +1 -1
  173. package/lib/typescript/src/web/vaul/use-snap-points.d.ts +2 -1
  174. package/lib/typescript/src/web/vaul/use-snap-points.d.ts.map +1 -1
  175. package/package.json +17 -8
  176. package/react-native.config.js +1 -0
  177. package/src/TrueSheet.tsx +208 -48
  178. package/src/TrueSheet.types.ts +166 -35
  179. package/src/TrueSheet.web.tsx +272 -290
  180. package/src/TrueSheetBackground.tsx +17 -0
  181. package/src/TrueSheetOverlay.tsx +24 -0
  182. package/src/TrueSheetOverlay.web.tsx +33 -0
  183. package/src/TrueSheetPeek.web.tsx +25 -23
  184. package/src/detentBackgrounds.ts +24 -0
  185. package/src/fabric/TrueSheetContentViewNativeComponent.ts +1 -1
  186. package/src/fabric/TrueSheetOverlayViewNativeComponent.ts +12 -0
  187. package/src/fabric/TrueSheetViewNativeComponent.ts +15 -10
  188. package/src/index.ts +1 -0
  189. package/src/mocks/index.ts +17 -2
  190. package/src/mocks/navigationExpoRouter.ts +6 -5
  191. package/src/navigation/base-types.ts +20 -0
  192. package/src/navigation/createTrueSheetRouter.ts +5 -33
  193. package/src/navigation/expo-router/base-types.ts +18 -0
  194. package/src/navigation/expo-router/index.ts +28 -30
  195. package/src/navigation/expo-router/types.ts +116 -0
  196. package/src/navigation/index.ts +6 -7
  197. package/src/navigation/screen/useSheetScreenState.ts +2 -0
  198. package/src/navigation/types.ts +75 -22
  199. package/src/web/constants.ts +1 -1
  200. package/src/web/layout.ts +196 -0
  201. package/src/web/vaul/constants.ts +9 -0
  202. package/src/web/vaul/context.ts +1 -0
  203. package/src/web/vaul/helpers.ts +5 -0
  204. package/src/web/vaul/index.tsx +75 -5
  205. package/src/web/vaul/use-snap-points.ts +32 -15
@@ -0,0 +1,17 @@
1
+ import { StyleSheet, View } from 'react-native';
2
+ import type { TrueSheetProps } from './TrueSheet.types';
3
+
4
+ export const TrueSheetBackground = ({
5
+ background,
6
+ backgroundStyle,
7
+ }: Pick<TrueSheetProps, 'background' | 'backgroundStyle'>) => (
8
+ <View
9
+ pointerEvents="none"
10
+ style={[
11
+ StyleSheet.absoluteFill,
12
+ { backgroundColor: StyleSheet.flatten(backgroundStyle)?.backgroundColor },
13
+ ]}
14
+ >
15
+ {background}
16
+ </View>
17
+ );
@@ -0,0 +1,24 @@
1
+ import { StyleSheet, type ViewProps } from 'react-native';
2
+
3
+ import TrueSheetOverlayViewNativeComponent from './fabric/TrueSheetOverlayViewNativeComponent';
4
+
5
+ /**
6
+ * Renders its children in a native layer above every presented sheet — for
7
+ * toasts, dialogs, and other content a sheet must not cover.
8
+ * Fills the window; touches that miss its children pass through to the views beneath.
9
+ */
10
+ export const TrueSheetOverlay = ({ style, ...rest }: ViewProps) => (
11
+ <TrueSheetOverlayViewNativeComponent {...rest} style={[styles.overlay, style]} />
12
+ );
13
+
14
+ const styles = StyleSheet.create({
15
+ // Sized to the window from native — absolute so it takes no layout space.
16
+ // Children render in a native container, so the host itself must never
17
+ // catch touches (Android forces it visible on layout).
18
+ overlay: {
19
+ position: 'absolute',
20
+ top: 0,
21
+ left: 0,
22
+ pointerEvents: 'none',
23
+ },
24
+ });
@@ -0,0 +1,33 @@
1
+ /// <reference lib="dom" />
2
+ import { useLayoutEffect, useState } from 'react';
3
+ import { createPortal } from 'react-dom';
4
+ import { StyleSheet, View, type ViewProps } from 'react-native';
5
+
6
+ /**
7
+ * Renders its children in a layer above every presented sheet — for
8
+ * toasts, dialogs, and other content a sheet must not cover.
9
+ * Fills the window; touches that miss its children pass through to the views beneath.
10
+ */
11
+ export const TrueSheetOverlay = ({ style, ...rest }: ViewProps) => {
12
+ // Portal target appended to the body so it stacks above the sheets' portal
13
+ const [container] = useState(() =>
14
+ typeof document !== 'undefined' ? document.createElement('div') : null
15
+ );
16
+
17
+ useLayoutEffect(() => {
18
+ if (!container) return;
19
+
20
+ container.style.cssText = 'position:fixed;inset:0;pointer-events:none';
21
+ document.body.appendChild(container);
22
+ return () => {
23
+ container.remove();
24
+ };
25
+ }, [container]);
26
+
27
+ if (!container) return null;
28
+
29
+ return createPortal(
30
+ <View pointerEvents="box-none" {...rest} style={[StyleSheet.absoluteFill, style]} />,
31
+ container
32
+ );
33
+ };
@@ -1,16 +1,15 @@
1
- import { createContext, type RefObject, useContext, useEffect, useRef } from 'react';
1
+ import { createContext, type RefObject, useContext, useLayoutEffect, useRef } from 'react';
2
2
  import { type LayoutChangeEvent, View, type ViewProps } from 'react-native';
3
3
 
4
- import { getDOMElement } from './web/dom';
5
-
6
4
  /**
7
- * Reports the measured peek content height to the owning TrueSheet.
5
+ * Registers a peek with the owning TrueSheet so it can measure the peek live.
8
6
  * @internal
9
7
  */
10
8
  export interface TrueSheetPeekContextValue {
11
9
  contentRef: RefObject<View | null>;
12
- peekRef: RefObject<View | null>;
13
- setPeekContentHeight: (height: number) => void;
10
+ attachPeek: (view: View) => void;
11
+ detachPeek: (view: View) => void;
12
+ measurePeek: (view: View) => void;
14
13
  }
15
14
 
16
15
  export const TrueSheetPeekContext = createContext<TrueSheetPeekContextValue | null>(null);
@@ -19,14 +18,19 @@ export const TrueSheetPeekContext = createContext<TrueSheetPeekContextValue | nu
19
18
  * Distance from the top of the content view to the bottom of the peek view,
20
19
  * so the peek view's offset within the content (padding, views above it)
21
20
  * counts toward the peek detent. Both rects live in the drawer's transformed
22
- * subtree, so an in-flight translate cancels out of the delta.
21
+ * subtree, so an in-flight translate cancels out of the delta. Rounded so the
22
+ * sub-pixel noise of a mid-transition measurement doesn't register as a
23
+ * change — the content re-measures every frame while the snap animates, and
24
+ * a new value would restart the snap.
23
25
  * @internal
24
26
  */
25
27
  export const measurePeekContentHeight = (
26
28
  peekElement: HTMLElement,
27
29
  contentElement: HTMLElement
28
30
  ): number =>
29
- peekElement.getBoundingClientRect().bottom - contentElement.getBoundingClientRect().top;
31
+ Math.round(
32
+ peekElement.getBoundingClientRect().bottom - contentElement.getBoundingClientRect().top
33
+ );
30
34
 
31
35
  /**
32
36
  * Wrapper component that marks its children as the sheet's peek content.
@@ -36,25 +40,23 @@ export const measurePeekContentHeight = (
36
40
  */
37
41
  export const TrueSheetPeek = ({ onLayout, ...rest }: ViewProps) => {
38
42
  const context = useContext(TrueSheetPeekContext);
39
- const localRef = useRef<View>(null);
43
+ const viewRef = useRef<View>(null);
40
44
 
41
- // Register into the sheet's peek ref so it can measure the peek live
42
- // during detent geometry computation (state lags the first willPresent).
43
- const viewRef = context?.peekRef ?? localRef;
45
+ // Attach by instance rather than sharing a ref — during a screen swap the
46
+ // incoming peek mounts before the outgoing one unmounts, and a shared ref
47
+ // would be nulled by the outgoing unmount.
48
+ useLayoutEffect(() => {
49
+ const view = viewRef.current;
50
+ if (!context || !view) return;
44
51
 
45
- useEffect(() => () => context?.setPeekContentHeight(0), [context]);
52
+ context.attachPeek(view);
53
+ return () => context.detachPeek(view);
54
+ }, [context]);
46
55
 
47
56
  const handleLayout = (event: LayoutChangeEvent) => {
48
- if (context) {
49
- const peekElement = getDOMElement(viewRef.current);
50
- const contentElement = getDOMElement(context.contentRef.current);
51
-
52
- const bottom =
53
- peekElement && contentElement
54
- ? measurePeekContentHeight(peekElement, contentElement)
55
- : event.nativeEvent.layout.height;
56
-
57
- context.setPeekContentHeight(bottom);
57
+ const view = viewRef.current;
58
+ if (context && view) {
59
+ context.measurePeek(view);
58
60
  }
59
61
 
60
62
  onLayout?.(event);
@@ -0,0 +1,24 @@
1
+ import type { DetentBackground } from './TrueSheet.types';
2
+
3
+ export function normalizeDetentBackground(entry: DetentBackground | null | undefined) {
4
+ return typeof entry === 'string' ? { color: entry } : entry;
5
+ }
6
+
7
+ export function getDetentBackgroundIndex(
8
+ height: number,
9
+ detentHeights: readonly number[],
10
+ displayedIndex: number
11
+ ): number {
12
+ if (detentHeights.length === 0) return -1;
13
+
14
+ let nextIndex = Math.max(0, Math.min(displayedIndex, detentHeights.length - 1));
15
+ let distance = Math.abs(height - detentHeights[nextIndex]!);
16
+ for (let index = 0; index < detentHeights.length; index++) {
17
+ const nextDistance = Math.abs(height - detentHeights[index]!);
18
+ if (nextDistance < distance) {
19
+ nextIndex = index;
20
+ distance = nextDistance;
21
+ }
22
+ }
23
+ return nextIndex;
24
+ }
@@ -6,7 +6,7 @@ export interface NativeProps extends ViewProps {
6
6
  }
7
7
 
8
8
  // interfaceOnly: shadow node/state/descriptor are custom (common/cpp) so the
9
- // content can be bounded to the container when a ScrollView is pinned
9
+ // content can be bounded to the container when a ScrollView is detected
10
10
  export default codegenNativeComponent<NativeProps>('TrueSheetContentView', {
11
11
  interfaceOnly: true,
12
12
  });
@@ -0,0 +1,12 @@
1
+ import type { ViewProps } from 'react-native';
2
+ import { codegenNativeComponent } from 'react-native';
3
+
4
+ export interface NativeProps extends ViewProps {
5
+ // No props needed - sized to the window from native
6
+ }
7
+
8
+ // interfaceOnly: shadow node/state/descriptor are custom (common/cpp) so the
9
+ // overlay is sized to the window
10
+ export default codegenNativeComponent<NativeProps>('TrueSheetOverlayView', {
11
+ interfaceOnly: true,
12
+ });
@@ -27,15 +27,12 @@ type AccessibilityOptionsType = Readonly<{
27
27
  paneTitle?: WithDefault<string, 'Bottom sheet'>;
28
28
  }>;
29
29
 
30
- type BlurOptionsType = Readonly<{
31
- intensity?: WithDefault<Double, -1>;
32
- interaction?: WithDefault<boolean, true>;
33
- }>;
34
-
35
30
  type ScrollEdgeEffect = 'automatic' | 'hard' | 'soft' | 'hidden';
36
31
 
37
32
  type ScrollableOptionsType = Readonly<{
33
+ contentInsetAdjustment?: WithDefault<'automatic' | 'safe-area' | 'footer' | 'never', 'automatic'>;
38
34
  keyboardScrollOffset?: WithDefault<Double, 0>;
35
+ keyboardOffset?: WithDefault<Double, 0>;
39
36
  scrollingExpandsSheet?: WithDefault<boolean, true>;
40
37
  topScrollEdgeEffect?: WithDefault<ScrollEdgeEffect, 'hidden'>;
41
38
  bottomScrollEdgeEffect?: WithDefault<ScrollEdgeEffect, 'hidden'>;
@@ -46,6 +43,7 @@ type FooterOptionsType = Readonly<{
46
43
  // the field name, so a second `position` would redefine TrueSheetViewPosition
47
44
  footerPosition?: WithDefault<'relative' | 'absolute', 'relative'>;
48
45
  keyboardOffset?: WithDefault<Double, 0>;
46
+ avoidKeyboard?: WithDefault<boolean, true>;
49
47
  }>;
50
48
 
51
49
  type HeaderOptionsType = Readonly<{
@@ -68,6 +66,12 @@ export interface PositionChangeEventPayload {
68
66
  export interface NativeProps extends ViewProps {
69
67
  // Array properties
70
68
  detents?: ReadonlyArray<Double>;
69
+ detentBackgrounds?: ReadonlyArray<
70
+ Readonly<{
71
+ color?: ProcessedColorValue | null;
72
+ blur?: string;
73
+ }>
74
+ >;
71
75
 
72
76
  // Number properties - use 0 as default to avoid nil insertion
73
77
  maxContentHeight?: WithDefault<Double, 0>;
@@ -107,12 +111,10 @@ export interface NativeProps extends ViewProps {
107
111
  'none'
108
112
  >;
109
113
 
110
- anchor?: WithDefault<'left' | 'center' | 'right', 'center'>;
111
- anchorOffset?: WithDefault<Double, 16>;
114
+ placement?: WithDefault<'automatic' | 'leading' | 'center' | 'trailing', 'automatic'>;
115
+ placementOffset?: WithDefault<Double, 16>;
112
116
  insetAdjustment?: WithDefault<'automatic' | 'never', 'automatic'>;
113
-
114
- // Blur options
115
- blurOptions?: BlurOptionsType;
117
+ dismissThreshold?: WithDefault<'half' | 'short', 'half'>;
116
118
 
117
119
  // Boolean properties - match defaults from TrueSheet.types.ts
118
120
  grabber?: WithDefault<boolean, true>;
@@ -122,6 +124,8 @@ export interface NativeProps extends ViewProps {
122
124
  draggable?: WithDefault<boolean, true>;
123
125
  dimmed?: WithDefault<boolean, true>;
124
126
  initialDetentAnimated?: WithDefault<boolean, true>;
127
+ // React tag of the scrollable component within the content (see scrollableRef)
128
+ scrollableHandle?: WithDefault<Int32, -1>;
125
129
  scrollableOptions?: ScrollableOptionsType;
126
130
  headerOptions?: HeaderOptionsType;
127
131
  footerOptions?: FooterOptionsType;
@@ -133,6 +137,7 @@ export interface NativeProps extends ViewProps {
133
137
  onDidPresent?: DirectEventHandler<DetentInfoEventPayload>;
134
138
  onWillDismiss?: DirectEventHandler<null>;
135
139
  onDidDismiss?: DirectEventHandler<null>;
140
+ onDismissAttempt?: DirectEventHandler<null>;
136
141
  onDetentChange?: DirectEventHandler<DetentInfoEventPayload>;
137
142
  onDragBegin?: DirectEventHandler<DetentInfoEventPayload>;
138
143
  onDragChange?: DirectEventHandler<DetentInfoEventPayload>;
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './TrueSheet';
2
2
  export * from './TrueSheet.types';
3
3
  export { TrueSheetPeek } from './TrueSheetPeek';
4
+ export { TrueSheetOverlay } from './TrueSheetOverlay';
4
5
  export { TrueSheetProvider, useTrueSheet } from './TrueSheetProvider';
@@ -2,6 +2,7 @@ import React, { createElement, isValidElement, type ReactNode } from 'react';
2
2
  import { View, type ViewProps } from 'react-native';
3
3
 
4
4
  import type { TrueSheetProps, TrueSheetStaticMethods } from '../TrueSheet.types';
5
+ import { TrueSheetBackground } from '../TrueSheetBackground';
5
6
 
6
7
  interface TrueSheetState {
7
8
  shouldRenderNativeView: boolean;
@@ -54,8 +55,15 @@ export class TrueSheet extends React.Component<TrueSheetProps, TrueSheetState> {
54
55
  }
55
56
 
56
57
  render() {
57
- const { children, style } = this.props;
58
- return React.createElement(View, { style }, this.renderHeader(), children, this.renderFooter());
58
+ const { children, style, background, backgroundStyle } = this.props;
59
+ return React.createElement(
60
+ View,
61
+ { style },
62
+ React.createElement(TrueSheetBackground, { background, backgroundStyle }),
63
+ this.renderHeader(),
64
+ children,
65
+ this.renderFooter()
66
+ );
59
67
  }
60
68
  }
61
69
 
@@ -66,6 +74,13 @@ export function TrueSheetPeek({ children, ...rest }: ViewProps) {
66
74
  return React.createElement(View, rest, children);
67
75
  }
68
76
 
77
+ /**
78
+ * Mock TrueSheetOverlay component for testing.
79
+ */
80
+ export function TrueSheetOverlay({ children, ...rest }: ViewProps) {
81
+ return React.createElement(View, rest, children);
82
+ }
83
+
69
84
  /**
70
85
  * Mock TrueSheetProvider for testing.
71
86
  */
@@ -1,6 +1,5 @@
1
- import type { ParamListBase } from '@react-navigation/native';
2
-
3
- import type { TrueSheetNavigationProp } from '../navigation/types';
1
+ import type { ParamListBase } from '../navigation/expo-router/base-types';
2
+ import type { TrueSheetNavigationProp } from '../navigation/expo-router/types';
4
3
  import {
5
4
  TrueSheetActions,
6
5
  useTrueSheetNavigation as useTrueSheetNavigationMock,
@@ -22,8 +21,10 @@ export const Sheet = Object.assign(
22
21
  * Mock useTrueSheetNavigation hook for testing.
23
22
  */
24
23
  export const useTrueSheetNavigation = jest.fn(
24
+ // Double cast: the shared mock is typed against React Navigation, this entry
25
+ // against Expo Router's vendored copy — identical shapes, unrelated declarations
25
26
  <T extends ParamListBase = ParamListBase>(): TrueSheetNavigationProp<T> =>
26
- useTrueSheetNavigationMock() as TrueSheetNavigationProp<T>
27
+ useTrueSheetNavigationMock() as unknown as TrueSheetNavigationProp<T>
27
28
  );
28
29
 
29
30
  export { TrueSheetActions };
@@ -37,4 +38,4 @@ export type {
37
38
  TrueSheetNavigationProp,
38
39
  TrueSheetNavigationState,
39
40
  TrueSheetScreenProps,
40
- } from '../navigation/types';
41
+ } from '../navigation/expo-router/types';
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Base navigation types for the React Navigation entry point.
3
+ *
4
+ * The Expo Router entry has its own copy sourced from `expo-router/react-navigation`
5
+ * (see `./expo-router/base-types`) because Expo Router apps never install
6
+ * `@react-navigation/*` — importing it there would silently resolve to `any`.
7
+ */
8
+ export type {
9
+ DefaultNavigatorOptions,
10
+ Descriptor,
11
+ NavigationAction,
12
+ NavigationHelpers,
13
+ NavigationProp,
14
+ NavigationState,
15
+ ParamListBase,
16
+ RouteProp,
17
+ Router,
18
+ StackActionHelpers,
19
+ StackRouterOptions,
20
+ } from '@react-navigation/core';
@@ -1,29 +1,5 @@
1
- import type {
2
- NavigationAction,
3
- NavigationState,
4
- ParamListBase,
5
- Router,
6
- StackRouterOptions,
7
- } from '@react-navigation/core';
8
-
9
- import { TrueSheetActions, type TrueSheetActionType } from './actions';
10
- import type { TrueSheetNavigationState } from './types';
11
-
12
- export type TrueSheetRouterOptions = StackRouterOptions;
13
-
14
- /**
15
- * The base `StackRouter` factory to wrap, typed generically over the state and
16
- * action types the wrapper threads through — `StackRouter` is structural and
17
- * never touches the sheet-specific fields.
18
- * Injected by each entry point so the shared router never imports
19
- * `@react-navigation/*` at runtime (Expo Router apps don't install it).
20
- */
21
- export type StackRouterFactory = <
22
- State extends NavigationState<ParamListBase>,
23
- Action extends NavigationAction,
24
- >(
25
- options: TrueSheetRouterOptions
26
- ) => Router<State, Action>;
1
+ import { TrueSheetActions } from './actions';
2
+ import type { TrueSheetRouter, TrueSheetRouterFactory, TrueSheetRouterOptions } from './types';
27
3
 
28
4
  const uid = () => Math.random().toString(36).slice(2, 10);
29
5
 
@@ -56,13 +32,9 @@ const ensureBaseRoute = <T extends { routes: { name: string }[] }>(
56
32
  };
57
33
 
58
34
  export const createTrueSheetRouter =
59
- (stackRouter: StackRouterFactory) =>
60
- (
61
- routerOptions: TrueSheetRouterOptions
62
- ): Router<TrueSheetNavigationState<ParamListBase>, TrueSheetActionType> => {
63
- const baseRouter = stackRouter<TrueSheetNavigationState<ParamListBase>, TrueSheetActionType>(
64
- routerOptions
65
- );
35
+ (stackRouter: TrueSheetRouterFactory) =>
36
+ (routerOptions: TrueSheetRouterOptions): TrueSheetRouter => {
37
+ const baseRouter = stackRouter(routerOptions);
66
38
 
67
39
  return {
68
40
  ...baseRouter,
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Base navigation types for the Expo Router entry point.
3
+ *
4
+ * Sourced from Expo Router's vendored React Navigation so apps that only install
5
+ * `expo-router` still get real types — see `../base-types` for the React Navigation copy.
6
+ */
7
+ export type {
8
+ DefaultNavigatorOptions,
9
+ NavigationAction,
10
+ NavigationHelpers,
11
+ NavigationProp,
12
+ NavigationState,
13
+ ParamListBase,
14
+ RouteProp,
15
+ Router,
16
+ StackActionHelpers,
17
+ StackRouterOptions,
18
+ } from 'expo-router/react-navigation';
@@ -1,48 +1,46 @@
1
- import type { ParamListBase } from '@react-navigation/core';
2
1
  import { StackRouter, unstable_integrateWithRouter, useNavigation } from 'expo-router';
3
2
 
4
- import {
5
- createTrueSheetRouter,
6
- type StackRouterFactory,
7
- type TrueSheetRouterOptions,
8
- } from '../createTrueSheetRouter';
3
+ import { createTrueSheetRouter } from '../createTrueSheetRouter';
9
4
  import { trueSheetNavigator } from '../navigator';
5
+ import type { ParamListBase } from './base-types';
10
6
  import type {
7
+ StackRouterFactory,
11
8
  TrueSheetNavigationOptions,
12
9
  TrueSheetNavigationProp,
13
10
  TrueSheetNavigationState,
14
11
  TrueSheetNavigatorContentExtraProps,
15
12
  TrueSheetNavigatorProps,
13
+ TrueSheetRouterFactory,
14
+ TrueSheetRouterOptions,
16
15
  TrueSheetStandardEventMap,
17
- } from '../types';
16
+ } from './types';
18
17
 
18
+ // expo-router's vendored StackRouter is structurally identical to @react-navigation's.
19
+ // Pinned to this entry's own router types: `createTrueSheetRouter` is shared and typed
20
+ // against React Navigation, which resolves to `any` in apps that only install expo-router.
21
+ const sheetRouter: TrueSheetRouterFactory = createTrueSheetRouter(
22
+ StackRouter as StackRouterFactory
23
+ );
24
+
25
+ // `routes`/`dispatch` are injected by `createProps`, so they are declared as
26
+ // CreateProps (last generic) and excluded from the public navigator props
19
27
  const SheetNavigator = unstable_integrateWithRouter<
20
28
  TrueSheetNavigationOptions,
21
29
  TrueSheetNavigationState<ParamListBase>,
22
30
  TrueSheetStandardEventMap,
23
- TrueSheetNavigatorContentExtraProps,
24
- TrueSheetRouterOptions
25
- >(
26
- trueSheetNavigator,
27
- // expo-router's vendored StackRouter is structurally identical to @react-navigation's
28
- createTrueSheetRouter(StackRouter as StackRouterFactory),
29
- {
30
- createProps: ({ state, dispatch }) => ({
31
- routes: state.routes,
32
- dispatch,
33
- }),
34
- }
35
- );
31
+ object,
32
+ TrueSheetRouterOptions,
33
+ TrueSheetNavigatorContentExtraProps
34
+ >(trueSheetNavigator, sheetRouter, {
35
+ createProps: ({ state, dispatch }) => ({
36
+ routes: state.routes,
37
+ dispatch,
38
+ }),
39
+ });
36
40
 
37
- // Public props: `routes`/`dispatch` are injected by `createProps` (optional here
38
- // so the navigator type stays comparable), and expo-router intersects the event
39
- // map with an index signature which breaks precisely typed `screenListeners`
40
- // callbacks - replace it with the exact map
41
- type SheetProps = Omit<
42
- React.ComponentProps<typeof SheetNavigator>,
43
- 'screenListeners' | 'routes' | 'dispatch'
44
- > &
45
- Partial<Pick<React.ComponentProps<typeof SheetNavigator>, 'routes' | 'dispatch'>> &
41
+ // expo-router intersects the event map with an index signature which breaks
42
+ // precisely typed `screenListeners` callbacks - replace it with the exact map
43
+ type SheetProps = Omit<React.ComponentProps<typeof SheetNavigator>, 'screenListeners'> &
46
44
  Pick<TrueSheetNavigatorProps, 'screenListeners'>;
47
45
 
48
46
  /**
@@ -86,4 +84,4 @@ export type {
86
84
  TrueSheetNavigationProp,
87
85
  TrueSheetNavigationState,
88
86
  TrueSheetScreenProps,
89
- } from '../types';
87
+ } from './types';
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Expo Router flavour of `../types`: same shapes, but bound to Expo Router's
3
+ * vendored React Navigation types so apps that only install `expo-router` still
4
+ * get real types instead of `any` — see `./base-types`.
5
+ */
6
+ import type { TrueSheetActionType } from '../actions';
7
+ import type {
8
+ TrueSheetActionHelpersOf,
9
+ TrueSheetDispatch,
10
+ TrueSheetNavigationEventMap,
11
+ TrueSheetNavigationOptions,
12
+ TrueSheetStateOf,
13
+ } from '../types';
14
+ import type {
15
+ DefaultNavigatorOptions,
16
+ NavigationAction,
17
+ NavigationHelpers,
18
+ NavigationProp,
19
+ NavigationState,
20
+ ParamListBase,
21
+ RouteProp,
22
+ Router,
23
+ StackActionHelpers,
24
+ StackRouterOptions,
25
+ } from './base-types';
26
+
27
+ export type TrueSheetRouterOptions = StackRouterOptions;
28
+
29
+ export type TrueSheetNavigationState<ParamList extends ParamListBase> = TrueSheetStateOf<
30
+ NavigationState<ParamList>
31
+ >;
32
+
33
+ export type TrueSheetRouterState = TrueSheetNavigationState<ParamListBase>;
34
+
35
+ export type TrueSheetRouter = Router<TrueSheetRouterState, TrueSheetActionType>;
36
+
37
+ export type TrueSheetRouterFactory = (options: TrueSheetRouterOptions) => TrueSheetRouter;
38
+
39
+ /**
40
+ * The base `StackRouter` factory to wrap — see `../types` for the shared contract.
41
+ */
42
+ export type StackRouterFactory = <
43
+ State extends NavigationState<ParamListBase>,
44
+ Action extends NavigationAction,
45
+ >(
46
+ options: TrueSheetRouterOptions
47
+ ) => Router<State, Action>;
48
+
49
+ export type TrueSheetRoute = TrueSheetNavigationState<ParamListBase>['routes'][number];
50
+
51
+ /**
52
+ * Props injected into the navigator content by Expo Router's `createProps`.
53
+ * Raw routes carry the custom fields (`closing`, `resizeIndex`, `resizeKey`)
54
+ * that the standard state strips out.
55
+ */
56
+ export interface TrueSheetNavigatorContentExtraProps {
57
+ routes: TrueSheetRoute[];
58
+ dispatch: TrueSheetDispatch;
59
+ }
60
+
61
+ export type TrueSheetActionHelpers<ParamList extends ParamListBase> = TrueSheetActionHelpersOf<
62
+ StackActionHelpers<ParamList>
63
+ >;
64
+
65
+ export type TrueSheetNavigationProp<
66
+ ParamList extends ParamListBase,
67
+ RouteName extends keyof ParamList = string,
68
+ NavigatorID extends string | undefined = undefined,
69
+ > = NavigationProp<
70
+ ParamList,
71
+ RouteName,
72
+ NavigatorID,
73
+ TrueSheetNavigationState<ParamList>,
74
+ TrueSheetNavigationOptions,
75
+ TrueSheetNavigationEventMap
76
+ > &
77
+ TrueSheetActionHelpers<ParamList>;
78
+
79
+ export type TrueSheetScreenProps<
80
+ ParamList extends ParamListBase,
81
+ RouteName extends keyof ParamList = string,
82
+ NavigatorID extends string | undefined = undefined,
83
+ > = {
84
+ navigation: TrueSheetNavigationProp<ParamList, RouteName, NavigatorID>;
85
+ route: RouteProp<ParamList, RouteName>;
86
+ };
87
+
88
+ export type TrueSheetNavigationHelpers = NavigationHelpers<
89
+ ParamListBase,
90
+ TrueSheetNavigationEventMap
91
+ >;
92
+
93
+ export type TrueSheetNavigatorProps = DefaultNavigatorOptions<
94
+ ParamListBase,
95
+ string | undefined,
96
+ TrueSheetNavigationState<ParamListBase>,
97
+ TrueSheetNavigationOptions,
98
+ TrueSheetNavigationEventMap,
99
+ unknown
100
+ > & {
101
+ /**
102
+ * The name of the route to use as the base screen.
103
+ * This screen will be rendered as a regular screen, while other screens are presented as sheets.
104
+ * Defaults to the first screen defined in the navigator.
105
+ */
106
+ initialRouteName?: string;
107
+ };
108
+
109
+ export type {
110
+ PositionChangeHandler,
111
+ TrueSheetDispatch,
112
+ TrueSheetNavigationEventMap,
113
+ TrueSheetNavigationOptions,
114
+ TrueSheetNavigationSheetProps,
115
+ TrueSheetStandardEventMap,
116
+ } from '../types';