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

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 (98) hide show
  1. package/README.md +13 -6
  2. package/android/src/main/java/com/lodev09/truesheet/TrueSheetContainerView.kt +29 -33
  3. package/android/src/main/java/com/lodev09/truesheet/TrueSheetModule.kt +3 -1
  4. package/android/src/main/java/com/lodev09/truesheet/TrueSheetView.kt +48 -43
  5. package/android/src/main/java/com/lodev09/truesheet/TrueSheetViewController.kt +387 -88
  6. package/android/src/main/java/com/lodev09/truesheet/TrueSheetViewManager.kt +22 -4
  7. package/android/src/main/java/com/lodev09/truesheet/core/RNScreensFragmentObserver.kt +0 -5
  8. package/android/src/main/java/com/lodev09/truesheet/core/TrueSheetDialogObserver.kt +67 -0
  9. package/android/src/main/java/com/lodev09/truesheet/core/TrueSheetGrabberView.kt +44 -0
  10. package/android/src/main/java/com/lodev09/truesheet/events/TrueSheetDragEvents.kt +71 -0
  11. package/android/src/main/java/com/lodev09/truesheet/events/TrueSheetFocusEvents.kt +65 -0
  12. package/android/src/main/java/com/lodev09/truesheet/events/TrueSheetLifecycleEvents.kt +94 -0
  13. package/android/src/main/java/com/lodev09/truesheet/events/TrueSheetStateEvents.kt +56 -0
  14. package/android/src/main/java/com/lodev09/truesheet/utils/ScreenUtils.kt +37 -33
  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/TrueSheetContainerView.mm +4 -0
  19. package/ios/TrueSheetContentView.h +2 -1
  20. package/ios/TrueSheetContentView.mm +91 -11
  21. package/ios/TrueSheetView.mm +65 -41
  22. package/ios/TrueSheetViewController.h +21 -10
  23. package/ios/TrueSheetViewController.mm +330 -165
  24. package/ios/core/TrueSheetBlurView.h +24 -0
  25. package/ios/{utils/ConversionUtil.mm → core/TrueSheetBlurView.mm} +65 -3
  26. package/ios/events/TrueSheetDragEvents.h +39 -0
  27. package/ios/events/TrueSheetDragEvents.mm +62 -0
  28. package/ios/events/{OnPositionChangeEvent.h → TrueSheetFocusEvents.h} +8 -5
  29. package/ios/events/TrueSheetFocusEvents.mm +49 -0
  30. package/ios/events/TrueSheetLifecycleEvents.h +40 -0
  31. package/ios/events/TrueSheetLifecycleEvents.mm +71 -0
  32. package/ios/events/TrueSheetStateEvents.h +35 -0
  33. package/ios/events/TrueSheetStateEvents.mm +49 -0
  34. package/ios/utils/GestureUtil.h +7 -0
  35. package/ios/utils/GestureUtil.mm +12 -0
  36. package/lib/module/TrueSheet.js +65 -12
  37. package/lib/module/TrueSheet.js.map +1 -1
  38. package/lib/module/fabric/TrueSheetViewNativeComponent.ts +15 -5
  39. package/lib/module/index.js +0 -1
  40. package/lib/module/index.js.map +1 -1
  41. package/lib/module/reanimated/ReanimatedTrueSheet.js +13 -7
  42. package/lib/module/reanimated/ReanimatedTrueSheet.js.map +1 -1
  43. package/lib/module/reanimated/ReanimatedTrueSheetProvider.js +4 -2
  44. package/lib/module/reanimated/ReanimatedTrueSheetProvider.js.map +1 -1
  45. package/lib/typescript/src/TrueSheet.d.ts +4 -0
  46. package/lib/typescript/src/TrueSheet.d.ts.map +1 -1
  47. package/lib/typescript/src/TrueSheet.types.d.ts +58 -6
  48. package/lib/typescript/src/TrueSheet.types.d.ts.map +1 -1
  49. package/lib/typescript/src/fabric/TrueSheetViewNativeComponent.d.ts +14 -5
  50. package/lib/typescript/src/fabric/TrueSheetViewNativeComponent.d.ts.map +1 -1
  51. package/lib/typescript/src/index.d.ts +0 -1
  52. package/lib/typescript/src/index.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 +80 -10
  58. package/src/TrueSheet.types.ts +65 -6
  59. package/src/__mocks__/index.js +0 -5
  60. package/src/fabric/TrueSheetViewNativeComponent.ts +15 -5
  61. package/src/index.ts +0 -1
  62. package/src/reanimated/ReanimatedTrueSheet.tsx +12 -7
  63. package/src/reanimated/ReanimatedTrueSheetProvider.tsx +11 -3
  64. package/android/src/main/java/com/lodev09/truesheet/events/DetentChangeEvent.kt +0 -26
  65. package/android/src/main/java/com/lodev09/truesheet/events/DidDismissEvent.kt +0 -20
  66. package/android/src/main/java/com/lodev09/truesheet/events/DidPresentEvent.kt +0 -26
  67. package/android/src/main/java/com/lodev09/truesheet/events/DragBeginEvent.kt +0 -26
  68. package/android/src/main/java/com/lodev09/truesheet/events/DragChangeEvent.kt +0 -26
  69. package/android/src/main/java/com/lodev09/truesheet/events/DragEndEvent.kt +0 -26
  70. package/android/src/main/java/com/lodev09/truesheet/events/MountEvent.kt +0 -20
  71. package/android/src/main/java/com/lodev09/truesheet/events/PositionChangeEvent.kt +0 -32
  72. package/android/src/main/java/com/lodev09/truesheet/events/WillDismissEvent.kt +0 -20
  73. package/android/src/main/java/com/lodev09/truesheet/events/WillPresentEvent.kt +0 -26
  74. package/ios/events/OnDetentChangeEvent.h +0 -28
  75. package/ios/events/OnDetentChangeEvent.mm +0 -30
  76. package/ios/events/OnDidDismissEvent.h +0 -26
  77. package/ios/events/OnDidDismissEvent.mm +0 -25
  78. package/ios/events/OnDidPresentEvent.h +0 -28
  79. package/ios/events/OnDidPresentEvent.mm +0 -30
  80. package/ios/events/OnDragBeginEvent.h +0 -28
  81. package/ios/events/OnDragBeginEvent.mm +0 -30
  82. package/ios/events/OnDragChangeEvent.h +0 -28
  83. package/ios/events/OnDragChangeEvent.mm +0 -30
  84. package/ios/events/OnDragEndEvent.h +0 -28
  85. package/ios/events/OnDragEndEvent.mm +0 -30
  86. package/ios/events/OnMountEvent.h +0 -26
  87. package/ios/events/OnMountEvent.mm +0 -25
  88. package/ios/events/OnPositionChangeEvent.mm +0 -32
  89. package/ios/events/OnWillDismissEvent.h +0 -26
  90. package/ios/events/OnWillDismissEvent.mm +0 -25
  91. package/ios/events/OnWillPresentEvent.h +0 -28
  92. package/ios/events/OnWillPresentEvent.mm +0 -30
  93. package/ios/utils/ConversionUtil.h +0 -24
  94. package/lib/module/TrueSheetGrabber.js +0 -51
  95. package/lib/module/TrueSheetGrabber.js.map +0 -1
  96. package/lib/typescript/src/TrueSheetGrabber.d.ts +0 -39
  97. package/lib/typescript/src/TrueSheetGrabber.d.ts.map +0 -1
  98. package/src/TrueSheetGrabber.tsx +0 -82
@@ -0,0 +1,24 @@
1
+ //
2
+ // Created by Jovanni Lo (@lodev09)
3
+ // Copyright (c) 2024-present. All rights reserved.
4
+ //
5
+ // This source code is licensed under the MIT license found in the
6
+ // LICENSE file in the root directory of this source tree.
7
+ //
8
+
9
+ #import <UIKit/UIKit.h>
10
+
11
+ NS_ASSUME_NONNULL_BEGIN
12
+
13
+ @interface TrueSheetBlurView : UIVisualEffectView
14
+
15
+ @property (nonatomic, copy, nullable) NSString *blurTint;
16
+ @property (nonatomic, strong, nullable) NSNumber *blurIntensity;
17
+ @property (nonatomic, assign) BOOL blurInteraction;
18
+
19
+ - (void)applyBlurEffect;
20
+ - (void)removeBlurEffect;
21
+
22
+ @end
23
+
24
+ NS_ASSUME_NONNULL_END
@@ -6,9 +6,13 @@
6
6
  // LICENSE file in the root directory of this source tree.
7
7
  //
8
8
 
9
- #import "ConversionUtil.h"
9
+ #import "TrueSheetBlurView.h"
10
10
 
11
- @implementation ConversionUtil
11
+ @implementation TrueSheetBlurView {
12
+ UIViewPropertyAnimator *_blurAnimator;
13
+ }
14
+
15
+ #pragma mark - Private
12
16
 
13
17
  + (UIBlurEffectStyle)blurEffectStyleFromString:(NSString *)tintString {
14
18
  static NSDictionary<NSString *, NSNumber *> *styleMap = nil;
@@ -43,8 +47,66 @@
43
47
  return (UIBlurEffectStyle)[style integerValue];
44
48
  }
45
49
 
46
- // Default to light if not recognized
47
50
  return UIBlurEffectStyleLight;
48
51
  }
49
52
 
53
+ #pragma mark - Initialization
54
+
55
+ - (instancetype)init {
56
+ if (self = [super init]) {
57
+ _blurInteraction = YES;
58
+ }
59
+ return self;
60
+ }
61
+
62
+ #pragma mark - Public
63
+
64
+ - (void)applyBlurEffect {
65
+ if (!self.blurTint || self.blurTint.length == 0) {
66
+ [self removeBlurEffect];
67
+ return;
68
+ }
69
+
70
+ // Stop and clear existing animator
71
+ if (_blurAnimator) {
72
+ [_blurAnimator stopAnimation:YES];
73
+ _blurAnimator = nil;
74
+ }
75
+
76
+ // Clear existing effect
77
+ self.effect = nil;
78
+
79
+ UIBlurEffectStyle style = [TrueSheetBlurView blurEffectStyleFromString:self.blurTint];
80
+ UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:style];
81
+
82
+ self.userInteractionEnabled = self.blurInteraction;
83
+
84
+ // Use animator to control blur intensity
85
+ __weak __typeof(self) weakSelf = self;
86
+ _blurAnimator = [[UIViewPropertyAnimator alloc] initWithDuration:1.0
87
+ curve:UIViewAnimationCurveLinear
88
+ animations:^{
89
+ weakSelf.effect = blurEffect;
90
+ }];
91
+ _blurAnimator.pausesOnCompletion = YES;
92
+
93
+ // Set intensity: nil means system default (100%), otherwise use provided value (0-100)
94
+ CGFloat intensity =
95
+ (self.blurIntensity && [self.blurIntensity floatValue] >= 0) ? [self.blurIntensity floatValue] / 100.0 : 1.0;
96
+ _blurAnimator.fractionComplete = intensity;
97
+ }
98
+
99
+ - (void)removeBlurEffect {
100
+ if (_blurAnimator) {
101
+ [_blurAnimator stopAnimation:YES];
102
+ _blurAnimator = nil;
103
+ }
104
+
105
+ self.effect = nil;
106
+ }
107
+
108
+ - (void)dealloc {
109
+ [self removeBlurEffect];
110
+ }
111
+
50
112
  @end
@@ -0,0 +1,39 @@
1
+ //
2
+ // Created by Jovanni Lo (@lodev09)
3
+ // Copyright (c) 2024-present. All rights reserved.
4
+ //
5
+ // This source code is licensed under the MIT license found in the
6
+ // LICENSE file in the root directory of this source tree.
7
+ //
8
+
9
+ #ifdef RCT_NEW_ARCH_ENABLED
10
+
11
+ #import <Foundation/Foundation.h>
12
+ #import <react/renderer/components/TrueSheetSpec/EventEmitters.h>
13
+
14
+ using namespace facebook::react;
15
+
16
+ NS_ASSUME_NONNULL_BEGIN
17
+
18
+ @interface TrueSheetDragEvents : NSObject
19
+
20
+ + (void)emitDragBegin:(std::shared_ptr<const facebook::react::EventEmitter>)eventEmitter
21
+ index:(NSInteger)index
22
+ position:(CGFloat)position
23
+ detent:(CGFloat)detent;
24
+
25
+ + (void)emitDragChange:(std::shared_ptr<const facebook::react::EventEmitter>)eventEmitter
26
+ index:(NSInteger)index
27
+ position:(CGFloat)position
28
+ detent:(CGFloat)detent;
29
+
30
+ + (void)emitDragEnd:(std::shared_ptr<const facebook::react::EventEmitter>)eventEmitter
31
+ index:(NSInteger)index
32
+ position:(CGFloat)position
33
+ detent:(CGFloat)detent;
34
+
35
+ @end
36
+
37
+ NS_ASSUME_NONNULL_END
38
+
39
+ #endif // RCT_NEW_ARCH_ENABLED
@@ -0,0 +1,62 @@
1
+ //
2
+ // Created by Jovanni Lo (@lodev09)
3
+ // Copyright (c) 2024-present. All rights reserved.
4
+ //
5
+ // This source code is licensed under the MIT license found in the
6
+ // LICENSE file in the root directory of this source tree.
7
+ //
8
+
9
+ #ifdef RCT_NEW_ARCH_ENABLED
10
+
11
+ #import "TrueSheetDragEvents.h"
12
+
13
+ @implementation TrueSheetDragEvents
14
+
15
+ + (void)emitDragBegin:(std::shared_ptr<const facebook::react::EventEmitter>)eventEmitter
16
+ index:(NSInteger)index
17
+ position:(CGFloat)position
18
+ detent:(CGFloat)detent {
19
+ if (!eventEmitter)
20
+ return;
21
+
22
+ auto emitter = std::static_pointer_cast<TrueSheetViewEventEmitter const>(eventEmitter);
23
+ TrueSheetViewEventEmitter::OnDragBegin event;
24
+ event.index = static_cast<int>(index);
25
+ event.position = static_cast<double>(position);
26
+ event.detent = static_cast<double>(detent);
27
+ emitter->onDragBegin(event);
28
+ }
29
+
30
+ + (void)emitDragChange:(std::shared_ptr<const facebook::react::EventEmitter>)eventEmitter
31
+ index:(NSInteger)index
32
+ position:(CGFloat)position
33
+ detent:(CGFloat)detent {
34
+ if (!eventEmitter)
35
+ return;
36
+
37
+ auto emitter = std::static_pointer_cast<TrueSheetViewEventEmitter const>(eventEmitter);
38
+ TrueSheetViewEventEmitter::OnDragChange event;
39
+ event.index = static_cast<int>(index);
40
+ event.position = static_cast<double>(position);
41
+ event.detent = static_cast<double>(detent);
42
+ emitter->onDragChange(event);
43
+ }
44
+
45
+ + (void)emitDragEnd:(std::shared_ptr<const facebook::react::EventEmitter>)eventEmitter
46
+ index:(NSInteger)index
47
+ position:(CGFloat)position
48
+ detent:(CGFloat)detent {
49
+ if (!eventEmitter)
50
+ return;
51
+
52
+ auto emitter = std::static_pointer_cast<TrueSheetViewEventEmitter const>(eventEmitter);
53
+ TrueSheetViewEventEmitter::OnDragEnd event;
54
+ event.index = static_cast<int>(index);
55
+ event.position = static_cast<double>(position);
56
+ event.detent = static_cast<double>(detent);
57
+ emitter->onDragEnd(event);
58
+ }
59
+
60
+ @end
61
+
62
+ #endif // RCT_NEW_ARCH_ENABLED
@@ -15,12 +15,15 @@ using namespace facebook::react;
15
15
 
16
16
  NS_ASSUME_NONNULL_BEGIN
17
17
 
18
- @interface OnPositionChangeEvent : NSObject
18
+ @interface TrueSheetFocusEvents : NSObject
19
19
 
20
- + (void)emit:(std::shared_ptr<const facebook::react::EventEmitter>)eventEmitter
21
- index:(NSInteger)index
22
- position:(CGFloat)position
23
- transitioning:(BOOL)transitioning;
20
+ + (void)emitWillFocus:(std::shared_ptr<const facebook::react::EventEmitter>)eventEmitter;
21
+
22
+ + (void)emitDidFocus:(std::shared_ptr<const facebook::react::EventEmitter>)eventEmitter;
23
+
24
+ + (void)emitWillBlur:(std::shared_ptr<const facebook::react::EventEmitter>)eventEmitter;
25
+
26
+ + (void)emitDidBlur:(std::shared_ptr<const facebook::react::EventEmitter>)eventEmitter;
24
27
 
25
28
  @end
26
29
 
@@ -0,0 +1,49 @@
1
+ //
2
+ // Created by Jovanni Lo (@lodev09)
3
+ // Copyright (c) 2024-present. All rights reserved.
4
+ //
5
+ // This source code is licensed under the MIT license found in the
6
+ // LICENSE file in the root directory of this source tree.
7
+ //
8
+
9
+ #ifdef RCT_NEW_ARCH_ENABLED
10
+
11
+ #import "TrueSheetFocusEvents.h"
12
+
13
+ @implementation TrueSheetFocusEvents
14
+
15
+ + (void)emitWillFocus:(std::shared_ptr<const facebook::react::EventEmitter>)eventEmitter {
16
+ if (!eventEmitter)
17
+ return;
18
+
19
+ auto emitter = std::static_pointer_cast<TrueSheetViewEventEmitter const>(eventEmitter);
20
+ emitter->onWillFocus({});
21
+ }
22
+
23
+ + (void)emitDidFocus:(std::shared_ptr<const facebook::react::EventEmitter>)eventEmitter {
24
+ if (!eventEmitter)
25
+ return;
26
+
27
+ auto emitter = std::static_pointer_cast<TrueSheetViewEventEmitter const>(eventEmitter);
28
+ emitter->onDidFocus({});
29
+ }
30
+
31
+ + (void)emitWillBlur:(std::shared_ptr<const facebook::react::EventEmitter>)eventEmitter {
32
+ if (!eventEmitter)
33
+ return;
34
+
35
+ auto emitter = std::static_pointer_cast<TrueSheetViewEventEmitter const>(eventEmitter);
36
+ emitter->onWillBlur({});
37
+ }
38
+
39
+ + (void)emitDidBlur:(std::shared_ptr<const facebook::react::EventEmitter>)eventEmitter {
40
+ if (!eventEmitter)
41
+ return;
42
+
43
+ auto emitter = std::static_pointer_cast<TrueSheetViewEventEmitter const>(eventEmitter);
44
+ emitter->onDidBlur({});
45
+ }
46
+
47
+ @end
48
+
49
+ #endif // RCT_NEW_ARCH_ENABLED
@@ -0,0 +1,40 @@
1
+ //
2
+ // Created by Jovanni Lo (@lodev09)
3
+ // Copyright (c) 2024-present. All rights reserved.
4
+ //
5
+ // This source code is licensed under the MIT license found in the
6
+ // LICENSE file in the root directory of this source tree.
7
+ //
8
+
9
+ #ifdef RCT_NEW_ARCH_ENABLED
10
+
11
+ #import <Foundation/Foundation.h>
12
+ #import <react/renderer/components/TrueSheetSpec/EventEmitters.h>
13
+
14
+ using namespace facebook::react;
15
+
16
+ NS_ASSUME_NONNULL_BEGIN
17
+
18
+ @interface TrueSheetLifecycleEvents : NSObject
19
+
20
+ + (void)emitMount:(std::shared_ptr<const facebook::react::EventEmitter>)eventEmitter;
21
+
22
+ + (void)emitWillPresent:(std::shared_ptr<const facebook::react::EventEmitter>)eventEmitter
23
+ index:(NSInteger)index
24
+ position:(CGFloat)position
25
+ detent:(CGFloat)detent;
26
+
27
+ + (void)emitDidPresent:(std::shared_ptr<const facebook::react::EventEmitter>)eventEmitter
28
+ index:(NSInteger)index
29
+ position:(CGFloat)position
30
+ detent:(CGFloat)detent;
31
+
32
+ + (void)emitWillDismiss:(std::shared_ptr<const facebook::react::EventEmitter>)eventEmitter;
33
+
34
+ + (void)emitDidDismiss:(std::shared_ptr<const facebook::react::EventEmitter>)eventEmitter;
35
+
36
+ @end
37
+
38
+ NS_ASSUME_NONNULL_END
39
+
40
+ #endif // RCT_NEW_ARCH_ENABLED
@@ -0,0 +1,71 @@
1
+ //
2
+ // Created by Jovanni Lo (@lodev09)
3
+ // Copyright (c) 2024-present. All rights reserved.
4
+ //
5
+ // This source code is licensed under the MIT license found in the
6
+ // LICENSE file in the root directory of this source tree.
7
+ //
8
+
9
+ #ifdef RCT_NEW_ARCH_ENABLED
10
+
11
+ #import "TrueSheetLifecycleEvents.h"
12
+
13
+ @implementation TrueSheetLifecycleEvents
14
+
15
+ + (void)emitMount:(std::shared_ptr<const facebook::react::EventEmitter>)eventEmitter {
16
+ if (!eventEmitter)
17
+ return;
18
+
19
+ auto emitter = std::static_pointer_cast<TrueSheetViewEventEmitter const>(eventEmitter);
20
+ emitter->onMount({});
21
+ }
22
+
23
+ + (void)emitWillPresent:(std::shared_ptr<const facebook::react::EventEmitter>)eventEmitter
24
+ index:(NSInteger)index
25
+ position:(CGFloat)position
26
+ detent:(CGFloat)detent {
27
+ if (!eventEmitter)
28
+ return;
29
+
30
+ auto emitter = std::static_pointer_cast<TrueSheetViewEventEmitter const>(eventEmitter);
31
+ TrueSheetViewEventEmitter::OnWillPresent event;
32
+ event.index = static_cast<int>(index);
33
+ event.position = static_cast<double>(position);
34
+ event.detent = static_cast<double>(detent);
35
+ emitter->onWillPresent(event);
36
+ }
37
+
38
+ + (void)emitDidPresent:(std::shared_ptr<const facebook::react::EventEmitter>)eventEmitter
39
+ index:(NSInteger)index
40
+ position:(CGFloat)position
41
+ detent:(CGFloat)detent {
42
+ if (!eventEmitter)
43
+ return;
44
+
45
+ auto emitter = std::static_pointer_cast<TrueSheetViewEventEmitter const>(eventEmitter);
46
+ TrueSheetViewEventEmitter::OnDidPresent event;
47
+ event.index = static_cast<int>(index);
48
+ event.position = static_cast<double>(position);
49
+ event.detent = static_cast<double>(detent);
50
+ emitter->onDidPresent(event);
51
+ }
52
+
53
+ + (void)emitWillDismiss:(std::shared_ptr<const facebook::react::EventEmitter>)eventEmitter {
54
+ if (!eventEmitter)
55
+ return;
56
+
57
+ auto emitter = std::static_pointer_cast<TrueSheetViewEventEmitter const>(eventEmitter);
58
+ emitter->onWillDismiss({});
59
+ }
60
+
61
+ + (void)emitDidDismiss:(std::shared_ptr<const facebook::react::EventEmitter>)eventEmitter {
62
+ if (!eventEmitter)
63
+ return;
64
+
65
+ auto emitter = std::static_pointer_cast<TrueSheetViewEventEmitter const>(eventEmitter);
66
+ emitter->onDidDismiss({});
67
+ }
68
+
69
+ @end
70
+
71
+ #endif // RCT_NEW_ARCH_ENABLED
@@ -0,0 +1,35 @@
1
+ //
2
+ // Created by Jovanni Lo (@lodev09)
3
+ // Copyright (c) 2024-present. All rights reserved.
4
+ //
5
+ // This source code is licensed under the MIT license found in the
6
+ // LICENSE file in the root directory of this source tree.
7
+ //
8
+
9
+ #ifdef RCT_NEW_ARCH_ENABLED
10
+
11
+ #import <Foundation/Foundation.h>
12
+ #import <react/renderer/components/TrueSheetSpec/EventEmitters.h>
13
+
14
+ using namespace facebook::react;
15
+
16
+ NS_ASSUME_NONNULL_BEGIN
17
+
18
+ @interface TrueSheetStateEvents : NSObject
19
+
20
+ + (void)emitDetentChange:(std::shared_ptr<const facebook::react::EventEmitter>)eventEmitter
21
+ index:(NSInteger)index
22
+ position:(CGFloat)position
23
+ detent:(CGFloat)detent;
24
+
25
+ + (void)emitPositionChange:(std::shared_ptr<const facebook::react::EventEmitter>)eventEmitter
26
+ index:(CGFloat)index
27
+ position:(CGFloat)position
28
+ detent:(CGFloat)detent
29
+ realtime:(BOOL)realtime;
30
+
31
+ @end
32
+
33
+ NS_ASSUME_NONNULL_END
34
+
35
+ #endif // RCT_NEW_ARCH_ENABLED
@@ -0,0 +1,49 @@
1
+ //
2
+ // Created by Jovanni Lo (@lodev09)
3
+ // Copyright (c) 2024-present. All rights reserved.
4
+ //
5
+ // This source code is licensed under the MIT license found in the
6
+ // LICENSE file in the root directory of this source tree.
7
+ //
8
+
9
+ #ifdef RCT_NEW_ARCH_ENABLED
10
+
11
+ #import "TrueSheetStateEvents.h"
12
+
13
+ @implementation TrueSheetStateEvents
14
+
15
+ + (void)emitDetentChange:(std::shared_ptr<const facebook::react::EventEmitter>)eventEmitter
16
+ index:(NSInteger)index
17
+ position:(CGFloat)position
18
+ detent:(CGFloat)detent {
19
+ if (!eventEmitter)
20
+ return;
21
+
22
+ auto emitter = std::static_pointer_cast<TrueSheetViewEventEmitter const>(eventEmitter);
23
+ TrueSheetViewEventEmitter::OnDetentChange event;
24
+ event.index = static_cast<int>(index);
25
+ event.position = static_cast<double>(position);
26
+ event.detent = static_cast<double>(detent);
27
+ emitter->onDetentChange(event);
28
+ }
29
+
30
+ + (void)emitPositionChange:(std::shared_ptr<const facebook::react::EventEmitter>)eventEmitter
31
+ index:(CGFloat)index
32
+ position:(CGFloat)position
33
+ detent:(CGFloat)detent
34
+ realtime:(BOOL)realtime {
35
+ if (!eventEmitter)
36
+ return;
37
+
38
+ auto emitter = std::static_pointer_cast<TrueSheetViewEventEmitter const>(eventEmitter);
39
+ TrueSheetViewEventEmitter::OnPositionChange event;
40
+ event.index = static_cast<double>(index);
41
+ event.position = static_cast<double>(position);
42
+ event.detent = static_cast<double>(detent);
43
+ event.realtime = static_cast<bool>(realtime);
44
+ emitter->onPositionChange(event);
45
+ }
46
+
47
+ @end
48
+
49
+ #endif // RCT_NEW_ARCH_ENABLED
@@ -20,6 +20,13 @@ NS_ASSUME_NONNULL_BEGIN
20
20
  */
21
21
  + (void)attachPanGestureHandler:(UIView *)view target:(id)target selector:(SEL)selector;
22
22
 
23
+ /**
24
+ * Enables or disables all pan gesture recognizers on a view
25
+ * @param view The view whose pan gesture recognizers to enable/disable
26
+ * @param enabled Whether the pan gestures should be enabled
27
+ */
28
+ + (void)setPanGesturesEnabled:(BOOL)enabled forView:(UIView *)view;
29
+
23
30
  @end
24
31
 
25
32
  NS_ASSUME_NONNULL_END
@@ -23,4 +23,16 @@
23
23
  }
24
24
  }
25
25
 
26
+ + (void)setPanGesturesEnabled:(BOOL)enabled forView:(UIView *)view {
27
+ if (!view) {
28
+ return;
29
+ }
30
+
31
+ for (UIGestureRecognizer *recognizer in view.gestureRecognizers ?: @[]) {
32
+ if ([recognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
33
+ recognizer.enabled = enabled;
34
+ }
35
+ }
36
+ }
37
+
26
38
  @end
@@ -7,12 +7,15 @@ import TrueSheetContentViewNativeComponent from './fabric/TrueSheetContentViewNa
7
7
  import TrueSheetHeaderViewNativeComponent from './fabric/TrueSheetHeaderViewNativeComponent';
8
8
  import TrueSheetFooterViewNativeComponent from './fabric/TrueSheetFooterViewNativeComponent';
9
9
  import TrueSheetModule from "./specs/NativeTrueSheetModule.js";
10
- import { Platform, processColor, StyleSheet, findNodeHandle } from 'react-native';
10
+ import { Platform, processColor, StyleSheet, findNodeHandle, View } from 'react-native';
11
11
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
12
12
  const LINKING_ERROR = `The package '@lodev09/react-native-true-sheet' doesn't seem to be linked. Make sure: \n\n` + Platform.select({
13
13
  ios: "- You have run 'pod install'\n",
14
14
  default: ''
15
15
  }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n' + '- You are using the new architecture (Fabric)\n';
16
+
17
+ // Material Design 3 minimum touch target
18
+ const ANDROID_HITBOX_HEIGHT = 48;
16
19
  if (!TrueSheetModule) {
17
20
  throw new Error(LINKING_ERROR);
18
21
  }
@@ -47,6 +50,10 @@ export class TrueSheet extends PureComponent {
47
50
  this.onDragChange = this.onDragChange.bind(this);
48
51
  this.onDragEnd = this.onDragEnd.bind(this);
49
52
  this.onPositionChange = this.onPositionChange.bind(this);
53
+ this.onWillFocus = this.onWillFocus.bind(this);
54
+ this.onDidFocus = this.onDidFocus.bind(this);
55
+ this.onWillBlur = this.onWillBlur.bind(this);
56
+ this.onDidBlur = this.onDidBlur.bind(this);
50
57
  }
51
58
  validateDetents() {
52
59
  const {
@@ -186,6 +193,18 @@ export class TrueSheet extends PureComponent {
186
193
  onPositionChange(event) {
187
194
  this.props.onPositionChange?.(event);
188
195
  }
196
+ onWillFocus(event) {
197
+ this.props.onWillFocus?.(event);
198
+ }
199
+ onDidFocus(event) {
200
+ this.props.onDidFocus?.(event);
201
+ }
202
+ onWillBlur(event) {
203
+ this.props.onWillBlur?.(event);
204
+ }
205
+ onDidBlur(event) {
206
+ this.props.onDidBlur?.(event);
207
+ }
189
208
 
190
209
  /**
191
210
  * Present the Sheet by `index` (Promise-based)
@@ -245,6 +264,7 @@ export class TrueSheet extends PureComponent {
245
264
  detents = [0.5, 1],
246
265
  backgroundColor,
247
266
  dismissible = true,
267
+ draggable = true,
248
268
  grabber = true,
249
269
  dimmed = true,
250
270
  initialDetentIndex = -1,
@@ -255,13 +275,12 @@ export class TrueSheet extends PureComponent {
255
275
  cornerRadius,
256
276
  maxHeight,
257
277
  edgeToEdgeFullScreen,
258
- fitScrollView = false,
278
+ scrollable = false,
259
279
  pageSizing = true,
260
280
  children,
261
281
  style,
262
282
  header,
263
283
  footer,
264
- testID,
265
284
  ...rest
266
285
  } = this.props;
267
286
 
@@ -275,6 +294,12 @@ export class TrueSheet extends PureComponent {
275
294
  // Clamp to maximum of 1
276
295
  return Math.min(1, detent);
277
296
  });
297
+ const containerStyle = this.props.scrollable && Platform.select({
298
+ android: styles.scrollableAndroidContainer
299
+ });
300
+ const contentStyle = this.props.scrollable && Platform.select({
301
+ android: styles.scrollableAndroidContent
302
+ });
278
303
  return /*#__PURE__*/_jsx(TrueSheetViewNativeComponent, {
279
304
  ...rest,
280
305
  ref: this.nativeRef,
@@ -290,9 +315,10 @@ export class TrueSheet extends PureComponent {
290
315
  initialDetentIndex: initialDetentIndex,
291
316
  initialDetentAnimated: initialDetentAnimated,
292
317
  dismissible: dismissible,
318
+ draggable: draggable,
293
319
  maxHeight: maxHeight,
294
320
  edgeToEdgeFullScreen: edgeToEdgeFullScreen,
295
- fitScrollView: fitScrollView,
321
+ scrollable: scrollable,
296
322
  pageSizing: pageSizing,
297
323
  onMount: this.onMount,
298
324
  onWillPresent: this.onWillPresent,
@@ -304,20 +330,23 @@ export class TrueSheet extends PureComponent {
304
330
  onDragChange: this.onDragChange,
305
331
  onDragEnd: this.onDragEnd,
306
332
  onPositionChange: this.onPositionChange,
333
+ onWillFocus: this.onWillFocus,
334
+ onDidFocus: this.onDidFocus,
335
+ onWillBlur: this.onWillBlur,
336
+ onDidBlur: this.onDidBlur,
307
337
  children: this.state.shouldRenderNativeView && /*#__PURE__*/_jsxs(TrueSheetContainerViewNativeComponent, {
308
- testID: testID,
309
- collapsable: false,
338
+ style: containerStyle,
310
339
  children: [header && /*#__PURE__*/_jsx(TrueSheetHeaderViewNativeComponent, {
311
- collapsable: false,
312
340
  children: /*#__PURE__*/isValidElement(header) ? header : /*#__PURE__*/createElement(header)
313
341
  }), /*#__PURE__*/_jsx(TrueSheetContentViewNativeComponent, {
314
- style: style,
315
- collapsable: false,
342
+ style: [style, contentStyle],
316
343
  children: children
317
344
  }), footer && /*#__PURE__*/_jsx(TrueSheetFooterViewNativeComponent, {
318
345
  style: styles.footer,
319
- collapsable: false,
320
346
  children: /*#__PURE__*/isValidElement(footer) ? footer : /*#__PURE__*/createElement(footer)
347
+ }), Platform.OS === 'android' && grabber && draggable && /*#__PURE__*/_jsx(View, {
348
+ collapsable: false,
349
+ style: styles.grabberHitbox
321
350
  })]
322
351
  })
323
352
  });
@@ -325,14 +354,38 @@ export class TrueSheet extends PureComponent {
325
354
  }
326
355
  const styles = StyleSheet.create({
327
356
  sheetView: {
357
+ zIndex: -9999,
328
358
  position: 'absolute',
329
- width: '100%',
330
- zIndex: -9999
359
+ top: 0,
360
+ left: 0,
361
+ right: 0,
362
+ // Android needs a fixed bottom to avoid jumping content
363
+ bottom: Platform.select({
364
+ android: 0
365
+ })
366
+ },
367
+ scrollableAndroidContainer: {
368
+ position: 'absolute',
369
+ top: 0,
370
+ left: 0,
371
+ right: 0,
372
+ bottom: 0
373
+ },
374
+ scrollableAndroidContent: {
375
+ flexGrow: 1,
376
+ flexBasis: 0
331
377
  },
332
378
  footer: {
333
379
  position: 'absolute',
334
380
  left: 0,
335
381
  right: 0
382
+ },
383
+ grabberHitbox: {
384
+ position: 'absolute',
385
+ top: 0,
386
+ left: 0,
387
+ right: 0,
388
+ height: ANDROID_HITBOX_HEIGHT
336
389
  }
337
390
  });
338
391
  //# sourceMappingURL=TrueSheet.js.map