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

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 (50) hide show
  1. package/README.md +1 -0
  2. package/android/src/main/java/com/lodev09/truesheet/TrueSheetContainerView.kt +51 -99
  3. package/android/src/main/java/com/lodev09/truesheet/TrueSheetContainerViewManager.kt +0 -7
  4. package/android/src/main/java/com/lodev09/truesheet/TrueSheetContentView.kt +10 -18
  5. package/android/src/main/java/com/lodev09/truesheet/TrueSheetFooterView.kt +76 -20
  6. package/android/src/main/java/com/lodev09/truesheet/TrueSheetHeaderView.kt +38 -0
  7. package/android/src/main/java/com/lodev09/truesheet/TrueSheetHeaderViewManager.kt +21 -0
  8. package/android/src/main/java/com/lodev09/truesheet/TrueSheetPackage.kt +1 -0
  9. package/android/src/main/java/com/lodev09/truesheet/TrueSheetView.kt +106 -136
  10. package/android/src/main/java/com/lodev09/truesheet/TrueSheetViewController.kt +305 -419
  11. package/android/src/main/java/com/lodev09/truesheet/TrueSheetViewManager.kt +9 -4
  12. package/android/src/main/java/com/lodev09/truesheet/core/RNScreensFragmentObserver.kt +116 -0
  13. package/android/src/main/java/com/lodev09/truesheet/utils/ScreenUtils.kt +33 -5
  14. package/android/src/main/jni/TrueSheetSpec.h +1 -1
  15. package/common/cpp/react/renderer/components/TrueSheetSpec/{TrueSheetContainerViewComponentDescriptor.h → TrueSheetViewComponentDescriptor.h} +5 -5
  16. package/common/cpp/react/renderer/components/TrueSheetSpec/{TrueSheetContainerViewShadowNode.cpp → TrueSheetViewShadowNode.cpp} +4 -4
  17. package/common/cpp/react/renderer/components/TrueSheetSpec/{TrueSheetContainerViewShadowNode.h → TrueSheetViewShadowNode.h} +8 -8
  18. package/common/cpp/react/renderer/components/TrueSheetSpec/{TrueSheetContainerViewState.cpp → TrueSheetViewState.cpp} +2 -2
  19. package/common/cpp/react/renderer/components/TrueSheetSpec/{TrueSheetContainerViewState.h → TrueSheetViewState.h} +6 -6
  20. package/ios/TrueSheetContainerView.h +20 -2
  21. package/ios/TrueSheetContainerView.mm +62 -62
  22. package/ios/TrueSheetContentView.h +4 -2
  23. package/ios/TrueSheetContentView.mm +29 -72
  24. package/ios/TrueSheetFooterView.mm +2 -2
  25. package/ios/TrueSheetHeaderView.h +29 -0
  26. package/ios/TrueSheetHeaderView.mm +60 -0
  27. package/ios/TrueSheetView.mm +195 -214
  28. package/ios/TrueSheetViewController.h +2 -2
  29. package/ios/TrueSheetViewController.mm +126 -231
  30. package/ios/utils/LayoutUtil.h +2 -1
  31. package/ios/utils/LayoutUtil.mm +14 -1
  32. package/lib/module/TrueSheet.js +9 -2
  33. package/lib/module/TrueSheet.js.map +1 -1
  34. package/lib/module/fabric/TrueSheetContainerViewNativeComponent.ts +1 -3
  35. package/lib/module/fabric/TrueSheetHeaderViewNativeComponent.ts +8 -0
  36. package/lib/module/fabric/TrueSheetViewNativeComponent.ts +3 -1
  37. package/lib/typescript/src/TrueSheet.d.ts.map +1 -1
  38. package/lib/typescript/src/TrueSheet.types.d.ts +9 -9
  39. package/lib/typescript/src/TrueSheet.types.d.ts.map +1 -1
  40. package/lib/typescript/src/fabric/TrueSheetContainerViewNativeComponent.d.ts.map +1 -1
  41. package/lib/typescript/src/fabric/TrueSheetHeaderViewNativeComponent.d.ts +6 -0
  42. package/lib/typescript/src/fabric/TrueSheetHeaderViewNativeComponent.d.ts.map +1 -0
  43. package/lib/typescript/src/fabric/TrueSheetViewNativeComponent.d.ts.map +1 -1
  44. package/package.json +6 -3
  45. package/react-native.config.js +1 -1
  46. package/src/TrueSheet.tsx +9 -0
  47. package/src/TrueSheet.types.ts +10 -11
  48. package/src/fabric/TrueSheetContainerViewNativeComponent.ts +1 -3
  49. package/src/fabric/TrueSheetHeaderViewNativeComponent.ts +8 -0
  50. package/src/fabric/TrueSheetViewNativeComponent.ts +3 -1
@@ -53,98 +53,55 @@ using namespace facebook::react;
53
53
  }
54
54
  }
55
55
 
56
- - (void)unpinScrollView {
56
+ - (void)unpinScrollViewFromParentView:(UIView *)parentView {
57
57
  // Unpin previous scroll view if exists
58
58
  if (_pinnedScrollView) {
59
- [LayoutUtil unpinView:_pinnedScrollView];
59
+ [LayoutUtil unpinView:_pinnedScrollView fromParentView:parentView];
60
60
  }
61
61
  }
62
62
 
63
- - (void)setupScrollViewPinning:(BOOL)pinned {
63
+ - (void)setupScrollViewPinning:(BOOL)pinned withHeaderView:(UIView *)headerView {
64
+ // Pin to container view (parent of content view)
65
+ UIView *containerView = self.superview;
66
+
64
67
  if (!pinned) {
65
- [self unpinScrollView];
68
+ [self unpinScrollViewFromParentView:containerView];
69
+ _pinnedScrollView = nil;
66
70
  return;
67
71
  }
68
72
 
69
73
  // Auto-detect and pin scroll views for proper sheet scrolling behavior
70
- // Pinning ensures ScrollView fills the sheet area and scrolls correctly with the sheet
71
- UIView *topSibling = nil;
72
- RCTScrollViewComponentView *scrollView = [self findScrollView:&topSibling];
73
-
74
- if (scrollView && scrollView != _pinnedScrollView) {
75
- [self unpinScrollView];
76
-
77
- // Pin to container view to enable proper scrolling within the sheet
78
- UIView *containerView = self.superview;
79
- if (containerView) {
80
- if (topSibling) {
81
- // Pin ScrollView below the top sibling
82
- [LayoutUtil pinView:scrollView
83
- toParentView:containerView
84
- withTopView:topSibling
85
- edges:UIRectEdgeLeft | UIRectEdgeRight | UIRectEdgeBottom];
86
- } else {
87
- // No top sibling, pin to all edges of container (original behavior)
88
- [LayoutUtil pinView:scrollView toParentView:containerView edges:UIRectEdgeAll];
89
- }
90
-
91
- _pinnedScrollView = scrollView;
74
+ // Pinning ensures ScrollView fills the available area and scrolls correctly with the sheet
75
+ RCTScrollViewComponentView *scrollView = [self findScrollView];
76
+
77
+ if (scrollView && containerView) {
78
+ // Always unpin first to remove old constraints
79
+ [self unpinScrollViewFromParentView:containerView];
80
+
81
+ if (headerView) {
82
+ // Pin ScrollView below the header view
83
+ [LayoutUtil pinView:scrollView
84
+ toParentView:containerView
85
+ withTopView:headerView
86
+ edges:UIRectEdgeLeft | UIRectEdgeRight | UIRectEdgeBottom];
87
+ } else {
88
+ // No header, pin to all edges of container
89
+ [LayoutUtil pinView:scrollView toParentView:containerView edges:UIRectEdgeAll];
92
90
  }
91
+
92
+ _pinnedScrollView = scrollView;
93
93
  }
94
94
  }
95
95
 
96
96
  - (RCTScrollViewComponentView *)findScrollView {
97
- return [self findScrollView:nil];
98
- }
99
-
100
- - (RCTScrollViewComponentView *)findScrollView:(UIView **)outTopSibling {
101
- if (self.subviews.count == 0) {
102
- return nil;
103
- }
104
-
105
- RCTScrollViewComponentView *scrollView = nil;
106
- UIView *topSibling = nil;
107
-
108
97
  // Check first-level children for scroll views (ScrollView or FlatList)
109
98
  for (UIView *subview in self.subviews) {
110
99
  if ([subview isKindOfClass:RCTScrollViewComponentView.class]) {
111
- scrollView = static_cast<RCTScrollViewComponentView *>(subview);
112
-
113
- // Find the view positioned directly above this ScrollView by frame position
114
- if (self.subviews.count > 1) {
115
- CGFloat scrollViewTop = CGRectGetMinY(scrollView.frame);
116
- CGFloat closestDistance = CGFLOAT_MAX;
117
-
118
- for (UIView *sibling in self.subviews) {
119
- // Skip the ScrollView itself
120
- if (sibling == scrollView) {
121
- continue;
122
- }
123
-
124
- CGFloat siblingBottom = CGRectGetMaxY(sibling.frame);
125
-
126
- // Check if this sibling is positioned above the ScrollView
127
- if (siblingBottom <= scrollViewTop) {
128
- CGFloat distance = scrollViewTop - siblingBottom;
129
-
130
- // Find the closest view above (smallest distance)
131
- if (distance < closestDistance) {
132
- closestDistance = distance;
133
- topSibling = sibling;
134
- }
135
- }
136
- }
137
- }
138
-
139
- break; // Found ScrollView, no need to continue
100
+ return (RCTScrollViewComponentView *)subview;
140
101
  }
141
102
  }
142
103
 
143
- if (outTopSibling) {
144
- *outTopSibling = topSibling;
145
- }
146
-
147
- return scrollView;
104
+ return nil;
148
105
  }
149
106
 
150
107
  - (void)prepareForRecycle {
@@ -152,7 +109,7 @@ using namespace facebook::react;
152
109
 
153
110
  // Remove scroll view constraints
154
111
  if (_pinnedScrollView) {
155
- [LayoutUtil unpinView:_pinnedScrollView];
112
+ [LayoutUtil unpinView:_pinnedScrollView fromParentView:self.superview];
156
113
  _pinnedScrollView = nil;
157
114
  }
158
115
  }
@@ -48,7 +48,7 @@ using namespace facebook::react;
48
48
  }
49
49
 
50
50
  // Remove existing constraints before applying new ones
51
- [LayoutUtil unpinView:self];
51
+ [LayoutUtil unpinView:self fromParentView:parentView];
52
52
 
53
53
  // Pin footer to bottom and sides of container with specific height
54
54
  [LayoutUtil pinView:self
@@ -90,7 +90,7 @@ using namespace facebook::react;
90
90
  [super prepareForRecycle];
91
91
 
92
92
  // Remove footer constraints
93
- [LayoutUtil unpinView:self];
93
+ [LayoutUtil unpinView:self fromParentView:self.superview];
94
94
 
95
95
  _lastHeight = 0;
96
96
  _didInitialLayout = NO;
@@ -0,0 +1,29 @@
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 <React/RCTViewComponentView.h>
12
+ #import <UIKit/UIKit.h>
13
+
14
+ NS_ASSUME_NONNULL_BEGIN
15
+
16
+ @protocol TrueSheetHeaderViewDelegate <NSObject>
17
+ @optional
18
+ - (void)headerViewDidChangeSize:(CGSize)size;
19
+ @end
20
+
21
+ @interface TrueSheetHeaderView : RCTViewComponentView
22
+
23
+ @property (nonatomic, weak, nullable) id<TrueSheetHeaderViewDelegate> delegate;
24
+
25
+ @end
26
+
27
+ NS_ASSUME_NONNULL_END
28
+
29
+ #endif
@@ -0,0 +1,60 @@
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 "TrueSheetHeaderView.h"
12
+ #import <react/renderer/components/TrueSheetSpec/ComponentDescriptors.h>
13
+ #import <react/renderer/components/TrueSheetSpec/EventEmitters.h>
14
+ #import <react/renderer/components/TrueSheetSpec/Props.h>
15
+ #import <react/renderer/components/TrueSheetSpec/RCTComponentViewHelpers.h>
16
+ #import "utils/LayoutUtil.h"
17
+
18
+ using namespace facebook::react;
19
+
20
+ @implementation TrueSheetHeaderView {
21
+ CGSize _lastSize;
22
+ }
23
+
24
+ + (ComponentDescriptorProvider)componentDescriptorProvider {
25
+ return concreteComponentDescriptorProvider<TrueSheetHeaderViewComponentDescriptor>();
26
+ }
27
+
28
+ - (instancetype)initWithFrame:(CGRect)frame {
29
+ if (self = [super initWithFrame:frame]) {
30
+ static const auto defaultProps = std::make_shared<const TrueSheetHeaderViewProps>();
31
+ _props = defaultProps;
32
+
33
+ _lastSize = CGSizeZero;
34
+ }
35
+ return self;
36
+ }
37
+
38
+ - (void)updateLayoutMetrics:(const facebook::react::LayoutMetrics &)layoutMetrics
39
+ oldLayoutMetrics:(const facebook::react::LayoutMetrics &)oldLayoutMetrics {
40
+ [super updateLayoutMetrics:layoutMetrics oldLayoutMetrics:oldLayoutMetrics];
41
+
42
+ CGSize newSize = CGSizeMake(layoutMetrics.frame.size.width, layoutMetrics.frame.size.height);
43
+
44
+ // Notify delegate when header size changes
45
+ if (!CGSizeEqualToSize(newSize, _lastSize)) {
46
+ _lastSize = newSize;
47
+ if ([self.delegate respondsToSelector:@selector(headerViewDidChangeSize:)]) {
48
+ [self.delegate headerViewDidChangeSize:newSize];
49
+ }
50
+ }
51
+ }
52
+
53
+ - (void)prepareForRecycle {
54
+ [super prepareForRecycle];
55
+ _lastSize = CGSizeZero;
56
+ }
57
+
58
+ @end
59
+
60
+ #endif