@lodev09/react-native-true-sheet 3.0.0-beta.11 → 3.0.0-beta.13

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 (61) hide show
  1. package/README.md +1 -1
  2. package/android/src/main/java/com/lodev09/truesheet/TrueSheetModule.kt +3 -1
  3. package/android/src/main/java/com/lodev09/truesheet/TrueSheetView.kt +33 -45
  4. package/android/src/main/java/com/lodev09/truesheet/TrueSheetViewController.kt +151 -22
  5. package/android/src/main/java/com/lodev09/truesheet/core/TrueSheetDialogObserver.kt +93 -0
  6. package/android/src/main/java/com/lodev09/truesheet/events/BlurEvent.kt +20 -0
  7. package/android/src/main/java/com/lodev09/truesheet/events/DetentChangeEvent.kt +2 -1
  8. package/android/src/main/java/com/lodev09/truesheet/events/DidPresentEvent.kt +2 -1
  9. package/android/src/main/java/com/lodev09/truesheet/events/DragBeginEvent.kt +2 -1
  10. package/android/src/main/java/com/lodev09/truesheet/events/DragChangeEvent.kt +2 -1
  11. package/android/src/main/java/com/lodev09/truesheet/events/DragEndEvent.kt +2 -1
  12. package/android/src/main/java/com/lodev09/truesheet/events/FocusEvent.kt +20 -0
  13. package/android/src/main/java/com/lodev09/truesheet/events/PositionChangeEvent.kt +5 -3
  14. package/android/src/main/java/com/lodev09/truesheet/events/WillPresentEvent.kt +2 -1
  15. package/android/src/main/res/anim/true_sheet_slide_in.xml +13 -0
  16. package/android/src/main/res/anim/true_sheet_slide_out.xml +13 -0
  17. package/android/src/main/res/values/styles.xml +13 -1
  18. package/ios/TrueSheetContentView.mm +37 -30
  19. package/ios/TrueSheetView.mm +26 -8
  20. package/ios/TrueSheetViewController.h +7 -1
  21. package/ios/TrueSheetViewController.mm +110 -40
  22. package/ios/events/OnDetentChangeEvent.h +2 -1
  23. package/ios/events/OnDetentChangeEvent.mm +3 -1
  24. package/ios/events/OnDidBlurEvent.h +26 -0
  25. package/ios/events/OnDidBlurEvent.mm +25 -0
  26. package/ios/events/OnDidFocusEvent.h +26 -0
  27. package/ios/events/OnDidFocusEvent.mm +25 -0
  28. package/ios/events/OnDidPresentEvent.h +2 -1
  29. package/ios/events/OnDidPresentEvent.mm +3 -1
  30. package/ios/events/OnDragBeginEvent.h +2 -1
  31. package/ios/events/OnDragBeginEvent.mm +3 -1
  32. package/ios/events/OnDragChangeEvent.h +2 -1
  33. package/ios/events/OnDragChangeEvent.mm +3 -1
  34. package/ios/events/OnDragEndEvent.h +2 -1
  35. package/ios/events/OnDragEndEvent.mm +3 -1
  36. package/ios/events/OnPositionChangeEvent.h +2 -1
  37. package/ios/events/OnPositionChangeEvent.mm +4 -2
  38. package/ios/events/OnWillPresentEvent.h +2 -1
  39. package/ios/events/OnWillPresentEvent.mm +3 -1
  40. package/lib/module/TrueSheet.js +10 -0
  41. package/lib/module/TrueSheet.js.map +1 -1
  42. package/lib/module/fabric/TrueSheetViewNativeComponent.ts +5 -1
  43. package/lib/module/reanimated/ReanimatedTrueSheet.js +9 -4
  44. package/lib/module/reanimated/ReanimatedTrueSheet.js.map +1 -1
  45. package/lib/module/reanimated/ReanimatedTrueSheetProvider.js +4 -2
  46. package/lib/module/reanimated/ReanimatedTrueSheetProvider.js.map +1 -1
  47. package/lib/typescript/src/TrueSheet.d.ts +2 -0
  48. package/lib/typescript/src/TrueSheet.d.ts.map +1 -1
  49. package/lib/typescript/src/TrueSheet.types.d.ts +14 -0
  50. package/lib/typescript/src/TrueSheet.types.d.ts.map +1 -1
  51. package/lib/typescript/src/fabric/TrueSheetViewNativeComponent.d.ts +5 -1
  52. package/lib/typescript/src/fabric/TrueSheetViewNativeComponent.d.ts.map +1 -1
  53. package/lib/typescript/src/reanimated/ReanimatedTrueSheet.d.ts.map +1 -1
  54. package/lib/typescript/src/reanimated/ReanimatedTrueSheetProvider.d.ts +8 -2
  55. package/lib/typescript/src/reanimated/ReanimatedTrueSheetProvider.d.ts.map +1 -1
  56. package/package.json +1 -1
  57. package/src/TrueSheet.tsx +14 -0
  58. package/src/TrueSheet.types.ts +16 -0
  59. package/src/fabric/TrueSheetViewNativeComponent.ts +5 -1
  60. package/src/reanimated/ReanimatedTrueSheet.tsx +9 -4
  61. package/src/reanimated/ReanimatedTrueSheetProvider.tsx +11 -3
@@ -10,6 +10,10 @@ export interface DetentInfoEventPayload {
10
10
  * The Y position of the sheet relative to the screen.
11
11
  */
12
12
  position: number;
13
+ /**
14
+ * The detent value (0-1) for the current index.
15
+ */
16
+ detent: number;
13
17
  }
14
18
 
15
19
  export interface PositionChangeEventPayload extends DetentInfoEventPayload {
@@ -30,6 +34,8 @@ export type DragBeginEvent = NativeSyntheticEvent<DetentInfoEventPayload>;
30
34
  export type DragChangeEvent = NativeSyntheticEvent<DetentInfoEventPayload>;
31
35
  export type DragEndEvent = NativeSyntheticEvent<DetentInfoEventPayload>;
32
36
  export type PositionChangeEvent = NativeSyntheticEvent<PositionChangeEventPayload>;
37
+ export type DidFocusEvent = NativeSyntheticEvent<null>;
38
+ export type DidBlurEvent = NativeSyntheticEvent<null>;
33
39
 
34
40
  /**
35
41
  * Blur style mapped to native values in IOS.
@@ -297,4 +303,14 @@ export interface TrueSheetProps extends ViewProps {
297
303
  * Comes with the detent info.
298
304
  */
299
305
  onPositionChange?: (event: PositionChangeEvent) => void;
306
+
307
+ /**
308
+ * Called when the sheet regains focus after a sheet presented on top of it is dismissed.
309
+ */
310
+ onDidFocus?: (event: DidFocusEvent) => void;
311
+
312
+ /**
313
+ * Called when the sheet loses focus because another sheet is presented on top of it.
314
+ */
315
+ onDidBlur?: (event: DidBlurEvent) => void;
300
316
  }
@@ -11,11 +11,13 @@ import { codegenNativeComponent } from 'react-native';
11
11
  export interface DetentInfoEventPayload {
12
12
  index: Int32;
13
13
  position: Double;
14
+ detent: Double;
14
15
  }
15
16
 
16
17
  export interface PositionChangeEventPayload {
17
- index: Int32;
18
+ index: Double;
18
19
  position: Double;
20
+ detent: Double;
19
21
  transitioning: boolean;
20
22
  }
21
23
 
@@ -54,6 +56,8 @@ export interface NativeProps extends ViewProps {
54
56
  onDragChange?: DirectEventHandler<DetentInfoEventPayload>;
55
57
  onDragEnd?: DirectEventHandler<DetentInfoEventPayload>;
56
58
  onPositionChange?: DirectEventHandler<PositionChangeEventPayload>;
59
+ onDidFocus?: DirectEventHandler<null>;
60
+ onDidBlur?: DirectEventHandler<null>;
57
61
  }
58
62
 
59
63
  export default codegenNativeComponent<NativeProps>('TrueSheetView', {
@@ -70,24 +70,29 @@ const AnimatedTrueSheet = Animated.createAnimatedComponent(TrueSheet);
70
70
  export const ReanimatedTrueSheet = forwardRef<TrueSheet, ReanimatedTrueSheetProps>((props, ref) => {
71
71
  const { onPositionChange, ...rest } = props;
72
72
 
73
- const { animatedPosition, animatedIndex } = useReanimatedTrueSheet();
73
+ const { animatedPosition, animatedIndex, detent } = useReanimatedTrueSheet();
74
74
 
75
75
  const positionChangeHandler = useReanimatedPositionChangeHandler((payload) => {
76
76
  'worklet';
77
77
 
78
- // When transitioning=true, we animate the position manually for smooth transitions.
79
- // This is used when native can't provide real-time position updates during animations.
78
+ // Update detent directly (discrete value, not animated)
79
+ detent.value = payload.detent;
80
+
80
81
  if (payload.transitioning) {
82
+ // Animate position and index when transitioning
81
83
  if (Platform.OS === 'android') {
82
84
  animatedPosition.value = withTiming(payload.position, TIMING_CONFIG);
85
+ animatedIndex.value = withTiming(payload.index, TIMING_CONFIG);
83
86
  } else {
84
87
  animatedPosition.value = withSpring(payload.position, SPRING_CONFIG);
88
+ animatedIndex.value = withSpring(payload.index, SPRING_CONFIG);
85
89
  }
86
90
  } else {
91
+ // Update directly during drag
87
92
  animatedPosition.value = payload.position;
93
+ animatedIndex.value = payload.index;
88
94
  }
89
95
 
90
- animatedIndex.value = payload.index;
91
96
  onPositionChange?.({ nativeEvent: payload } as PositionChangeEvent);
92
97
  });
93
98
 
@@ -4,13 +4,19 @@ import { useSharedValue, type SharedValue } from 'react-native-reanimated';
4
4
 
5
5
  export interface ReanimatedTrueSheetContextValue {
6
6
  /**
7
- * Shared value representing the current sheet position (Y offset from bottom)
7
+ * Shared value representing the current sheet position (Y offset from top of screen)
8
8
  */
9
9
  animatedPosition: SharedValue<number>;
10
10
  /**
11
- * Shared value representing the current detent index
11
+ * Shared value representing the current detent index as a continuous float.
12
+ * Interpolates smoothly between -1 (off-screen) and the target detent index.
12
13
  */
13
14
  animatedIndex: SharedValue<number>;
15
+ /**
16
+ * Shared value representing the current detent value (0-1 fraction of screen height).
17
+ * This is the discrete value for the current/target detent index.
18
+ */
19
+ detent: SharedValue<number>;
14
20
  }
15
21
 
16
22
  const ReanimatedTrueSheetContext = createContext<ReanimatedTrueSheetContextValue | null>(null);
@@ -40,13 +46,15 @@ export const ReanimatedTrueSheetProvider = ({ children }: ReanimatedTrueSheetPro
40
46
  const { height } = useWindowDimensions();
41
47
  const animatedPosition = useSharedValue(height);
42
48
  const animatedIndex = useSharedValue(-1);
49
+ const detent = useSharedValue(0);
43
50
 
44
51
  const value = useMemo(
45
52
  () => ({
46
53
  animatedPosition,
47
54
  animatedIndex,
55
+ detent,
48
56
  }),
49
- [animatedPosition, animatedIndex]
57
+ [animatedPosition, animatedIndex, detent]
50
58
  );
51
59
 
52
60
  return (