@lodev09/react-native-true-sheet 4.0.0-beta.3 → 4.0.0-beta.5

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 (47) hide show
  1. package/README.md +21 -2
  2. package/android/src/main/java/com/lodev09/truesheet/TrueSheetContainerView.kt +24 -7
  3. package/android/src/main/java/com/lodev09/truesheet/TrueSheetContentView.kt +195 -174
  4. package/android/src/main/java/com/lodev09/truesheet/TrueSheetContentViewManager.kt +5 -1
  5. package/android/src/main/java/com/lodev09/truesheet/TrueSheetFooterView.kt +6 -17
  6. package/android/src/main/java/com/lodev09/truesheet/TrueSheetView.kt +50 -8
  7. package/android/src/main/java/com/lodev09/truesheet/TrueSheetViewController.kt +101 -18
  8. package/android/src/main/java/com/lodev09/truesheet/TrueSheetViewManager.kt +24 -1
  9. package/android/src/main/java/com/lodev09/truesheet/core/TrueSheetCoordinatorLayout.kt +3 -3
  10. package/android/src/main/java/com/lodev09/truesheet/core/TrueSheetDetentCalculator.kt +14 -24
  11. package/android/src/main/java/com/lodev09/truesheet/utils/ViewUtils.kt +0 -7
  12. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetContentViewComponentDescriptor.h +0 -8
  13. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetContentViewShadowNode.cpp +54 -29
  14. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetContentViewShadowNode.h +6 -1
  15. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetContentViewState.cpp +1 -1
  16. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetContentViewState.h +6 -4
  17. package/ios/TrueSheetContainerView.h +9 -7
  18. package/ios/TrueSheetContainerView.mm +6 -7
  19. package/ios/TrueSheetContentView.h +28 -14
  20. package/ios/TrueSheetContentView.mm +122 -179
  21. package/ios/TrueSheetFooterView.mm +17 -0
  22. package/ios/TrueSheetView.mm +13 -10
  23. package/ios/TrueSheetViewController.mm +35 -27
  24. package/ios/utils/UIView+ScrollEdgeInteraction.h +1 -0
  25. package/ios/utils/UIView+ScrollEdgeInteraction.mm +24 -2
  26. package/lib/module/TrueSheet.js +47 -14
  27. package/lib/module/TrueSheet.js.map +1 -1
  28. package/lib/module/TrueSheet.web.js +26 -24
  29. package/lib/module/TrueSheet.web.js.map +1 -1
  30. package/lib/module/fabric/TrueSheetContentViewNativeComponent.ts +1 -1
  31. package/lib/module/fabric/TrueSheetViewNativeComponent.ts +4 -0
  32. package/lib/typescript/src/TrueSheet.d.ts +2 -0
  33. package/lib/typescript/src/TrueSheet.d.ts.map +1 -1
  34. package/lib/typescript/src/TrueSheet.types.d.ts +64 -1
  35. package/lib/typescript/src/TrueSheet.types.d.ts.map +1 -1
  36. package/lib/typescript/src/TrueSheet.web.d.ts.map +1 -1
  37. package/lib/typescript/src/fabric/TrueSheetViewNativeComponent.d.ts +3 -0
  38. package/lib/typescript/src/fabric/TrueSheetViewNativeComponent.d.ts.map +1 -1
  39. package/lib/typescript/src/navigation/types.d.ts +1 -1
  40. package/lib/typescript/src/navigation/types.d.ts.map +1 -1
  41. package/package.json +1 -1
  42. package/src/TrueSheet.tsx +48 -13
  43. package/src/TrueSheet.types.ts +68 -1
  44. package/src/TrueSheet.web.tsx +39 -24
  45. package/src/fabric/TrueSheetContentViewNativeComponent.ts +1 -1
  46. package/src/fabric/TrueSheetViewNativeComponent.ts +4 -0
  47. package/src/navigation/types.ts +1 -0
@@ -1,6 +1,10 @@
1
1
  #include "TrueSheetContentViewShadowNode.h"
2
2
 
3
+ #include <limits>
4
+
3
5
  #include <react/renderer/components/view/conversions.h>
6
+ #include <react/renderer/core/LayoutConstraints.h>
7
+ #include <react/renderer/core/LayoutContext.h>
4
8
 
5
9
  namespace facebook::react {
6
10
 
@@ -8,35 +12,56 @@ using namespace yoga;
8
12
 
9
13
  extern const char TrueSheetContentViewComponentName[] = "TrueSheetContentView";
10
14
 
11
- void TrueSheetContentViewShadowNode::adjustLayoutWithState() {
12
- ensureUnsealed();
13
-
14
- auto state = std::static_pointer_cast<
15
- const TrueSheetContentViewShadowNode::ConcreteState>(getState());
16
- auto stateData = state->getData();
17
-
18
- auto &props = getConcreteProps();
19
-
20
- // When a ScrollView is pinned under an auto detent, fill the container so
21
- // descendant flex layouts (flex:1 wrappers, the ScrollView itself) resolve
22
- // against a definite height and the viewport is bounded natural layout is
23
- // circular there since the sheet height derives from the ScrollView's content
24
- // size instead (see ContentView's naturalHeight on each platform). For fixed
25
- // detents, content lays out naturally like a regular view.
26
- auto flexGrow = stateData.scrollableBounded
27
- ? FloatOptional{1.0f}
28
- : props.yogaStyle.flexGrow();
29
- auto flexShrink = stateData.scrollableBounded
30
- ? FloatOptional{1.0f}
31
- : props.yogaStyle.flexShrink();
32
-
33
- if (yogaNode_.style().flexGrow() != flexGrow ||
34
- yogaNode_.style().flexShrink() != flexShrink) {
35
- yoga::Style adjustedStyle = props.yogaStyle;
36
- adjustedStyle.setFlexGrow(flexGrow);
37
- adjustedStyle.setFlexShrink(flexShrink);
38
- yogaNode_.setStyle(adjustedStyle);
39
- yogaNode_.setDirty(true);
15
+ // measure() lays out a clone of this node, which re-enters layout() on the
16
+ // clone — guard so the measurement pass doesn't measure again recursively.
17
+ static thread_local bool gIsMeasuringNaturalHeight = false;
18
+
19
+ void TrueSheetContentViewShadowNode::layout(LayoutContext layoutContext) {
20
+ ConcreteViewShadowNode::layout(layoutContext);
21
+ updateNaturalHeightIfNeeded(layoutContext);
22
+ }
23
+
24
+ // The content's committed height follows the container instead of its own
25
+ // content when it can grow/shrink along the main axis or uses a percent
26
+ // height. Reporting that height as the natural height would echo the sheet's
27
+ // own size back as a content size change e.g. flex: 1 content tracking a
28
+ // drag frame by frame.
29
+ static bool isHeightContainerDerived(const yoga::Style &style) {
30
+ return style.flexGrow().unwrapOrDefault(0) > 0 ||
31
+ style.flexShrink().unwrapOrDefault(0) > 0 ||
32
+ style.dimension(Dimension::Height).isPercent();
33
+ }
34
+
35
+ // The natural height is the height the content wants when unbounded — the
36
+ // source for the auto detent. When the content's height derives from the
37
+ // container, the committed layout doesn't reflect it — lay out a clone of the
38
+ // subtree with an unconstrained height instead. Yoga respects the user's
39
+ // styles: an explicit-height ScrollView keeps its height while a flexible one
40
+ // expands to its content — no ScrollView discovery involved.
41
+ void TrueSheetContentViewShadowNode::updateNaturalHeightIfNeeded(
42
+ const LayoutContext &layoutContext) {
43
+ if (gIsMeasuringNaturalHeight) {
44
+ return;
45
+ }
46
+
47
+ auto stateData = getStateData();
48
+ auto size = getLayoutMetrics().frame.size;
49
+
50
+ Float naturalHeight = size.height;
51
+ if (isHeightContainerDerived(getConcreteProps().yogaStyle)) {
52
+ auto constraints = LayoutConstraints{};
53
+ constraints.minimumSize = {size.width, 0};
54
+ constraints.maximumSize = {size.width, std::numeric_limits<Float>::infinity()};
55
+ constraints.layoutDirection = getLayoutMetrics().layoutDirection;
56
+
57
+ gIsMeasuringNaturalHeight = true;
58
+ naturalHeight = measure(layoutContext, constraints).height;
59
+ gIsMeasuringNaturalHeight = false;
60
+ }
61
+
62
+ if (stateData.naturalHeight != naturalHeight) {
63
+ stateData.naturalHeight = naturalHeight;
64
+ setStateData(std::move(stateData));
40
65
  }
41
66
  }
42
67
 
@@ -22,7 +22,12 @@ class JSI_EXPORT TrueSheetContentViewShadowNode final
22
22
  using ConcreteViewShadowNode::ConcreteViewShadowNode;
23
23
 
24
24
  public:
25
- void adjustLayoutWithState();
25
+ #pragma mark - LayoutableShadowNode
26
+
27
+ void layout(LayoutContext layoutContext) override;
28
+
29
+ private:
30
+ void updateNaturalHeightIfNeeded(const LayoutContext &layoutContext);
26
31
  };
27
32
 
28
33
  } // namespace facebook::react
@@ -4,7 +4,7 @@ namespace facebook::react {
4
4
 
5
5
  #ifdef ANDROID
6
6
  folly::dynamic TrueSheetContentViewState::getDynamic() const {
7
- return folly::dynamic::object("scrollableBounded", scrollableBounded);
7
+ return folly::dynamic::object("naturalHeight", naturalHeight);
8
8
  }
9
9
  #endif
10
10
 
@@ -1,5 +1,7 @@
1
1
  #pragma once
2
2
 
3
+ #include <react/renderer/graphics/Float.h>
4
+
3
5
  #ifdef ANDROID
4
6
  #include <folly/dynamic.h>
5
7
  #include <react/renderer/mapbuffer/MapBuffer.h>
@@ -10,8 +12,8 @@ namespace facebook::react {
10
12
 
11
13
  /*
12
14
  * State for <TrueSheetContentView> component.
13
- * Set from native when a ScrollView is pinned so the shadow node bounds the
14
- * content to the container via flexShrink (see TrueSheetContentViewShadowNode).
15
+ * `naturalHeight` is measured by the shadow node during layout — the height
16
+ * the content wants when unbounded (see TrueSheetContentViewShadowNode).
15
17
  */
16
18
  class TrueSheetContentViewState final {
17
19
  public:
@@ -21,10 +23,10 @@ class TrueSheetContentViewState final {
21
23
  TrueSheetContentViewState(
22
24
  TrueSheetContentViewState const &previousState,
23
25
  folly::dynamic data)
24
- : scrollableBounded(data["scrollableBounded"].getBool()) {}
26
+ : naturalHeight(previousState.naturalHeight) {}
25
27
  #endif
26
28
 
27
- bool scrollableBounded{false};
29
+ Float naturalHeight{0};
28
30
 
29
31
  #ifdef ANDROID
30
32
  folly::dynamic getDynamic() const;
@@ -16,7 +16,9 @@ NS_ASSUME_NONNULL_BEGIN
16
16
 
17
17
  @interface ScrollableOptions : NSObject
18
18
 
19
+ @property (nonatomic, assign) BOOL contentInsetAdjustment;
19
20
  @property (nonatomic, assign) CGFloat keyboardScrollOffset;
21
+ @property (nonatomic, assign) CGFloat keyboardOffset;
20
22
  @property (nonatomic, assign) BOOL scrollingExpandsSheet;
21
23
  @property (nonatomic, assign) facebook::react::TrueSheetViewTopScrollEdgeEffect topScrollEdgeEffect;
22
24
  @property (nonatomic, assign) facebook::react::TrueSheetViewBottomScrollEdgeEffect bottomScrollEdgeEffect;
@@ -46,20 +48,20 @@ NS_ASSUME_NONNULL_BEGIN
46
48
  @property (nonatomic, weak, nullable) id<TrueSheetContainerViewDelegate> delegate;
47
49
 
48
50
  /**
49
- * Inset adjustment mode for scrollable content
51
+ * Options for scrollable behavior
50
52
  */
51
- @property (nonatomic, assign) facebook::react::TrueSheetViewInsetAdjustment insetAdjustment;
53
+ @property (nonatomic, strong, nullable) ScrollableOptions *scrollableOptions;
52
54
 
53
55
  /**
54
- * Options for scrollable behavior
56
+ * React tag of the user-provided scrollable within the content (see the `scrollableRef` prop)
55
57
  */
56
- @property (nonatomic, strong, nullable) ScrollableOptions *scrollableOptions;
58
+ @property (nonatomic, assign) NSInteger scrollableHandle;
57
59
 
58
60
  /**
59
- * Whether the sheet has an `auto` detent bounds the pinned scrollable's
60
- * viewport to the container so the sheet height can derive from its content size
61
+ * Whether the resolved scrollable's `contentInsetAdjustmentBehavior` is set to
62
+ * `automatic` already gated by the sheet's `insetAdjustment`
61
63
  */
62
- @property (nonatomic, assign) BOOL hasAutoDetent;
64
+ @property (nonatomic, assign) BOOL contentInsetAdjustment;
63
65
 
64
66
  /**
65
67
  * Bottom safe-area inset the footer absorbs as padding — the footer
@@ -17,7 +17,6 @@
17
17
  #import "TrueSheetViewController.h"
18
18
  #import "core/TrueSheetKeyboardObserver.h"
19
19
  #import "utils/UIView+ScrollEdgeInteraction.h"
20
- #import "utils/WindowUtil.h"
21
20
 
22
21
  #import <react/renderer/components/TrueSheetSpec/ComponentDescriptors.h>
23
22
  #import <react/renderer/components/TrueSheetSpec/EventEmitters.h>
@@ -33,7 +32,9 @@ using namespace facebook::react;
33
32
 
34
33
  - (instancetype)init {
35
34
  if (self = [super init]) {
35
+ _contentInsetAdjustment = YES;
36
36
  _keyboardScrollOffset = 0;
37
+ _keyboardOffset = 0;
37
38
  _scrollingExpandsSheet = YES;
38
39
  _topScrollEdgeEffect = TrueSheetViewTopScrollEdgeEffect::Hidden;
39
40
  _bottomScrollEdgeEffect = TrueSheetViewBottomScrollEdgeEffect::Hidden;
@@ -149,16 +150,14 @@ using namespace facebook::react;
149
150
  - (void)setScrollableOptions:(ScrollableOptions *)scrollableOptions {
150
151
  _scrollableOptions = scrollableOptions;
151
152
  _contentView.keyboardScrollOffset = scrollableOptions ? scrollableOptions.keyboardScrollOffset : 0;
153
+ _contentView.keyboardOffset = scrollableOptions ? scrollableOptions.keyboardOffset : 0;
152
154
  }
153
155
 
154
156
  - (void)setupScrollable {
155
157
  if (_contentView) {
156
- CGFloat bottomInset = 0;
157
- if (_insetAdjustment == TrueSheetViewInsetAdjustment::Automatic) {
158
- bottomInset = [WindowUtil keyWindow].safeAreaInsets.bottom;
159
- }
160
- _contentView.hasAutoDetent = _hasAutoDetent;
161
- [_contentView setupScrollableWithBottomInset:bottomInset];
158
+ _contentView.scrollableHandle = _scrollableHandle;
159
+ _contentView.contentInsetAdjustment = _contentInsetAdjustment;
160
+ [_contentView setupScrollable];
162
161
  [_contentView applyScrollEdgeEffects:_scrollableOptions];
163
162
  if (@available(iOS 26.0, *)) {
164
163
  [self setupEdgeInteractions];
@@ -32,38 +32,52 @@ NS_ASSUME_NONNULL_BEGIN
32
32
 
33
33
  @property (nonatomic, weak, nullable) id<TrueSheetContentViewDelegate> delegate;
34
34
  @property (nonatomic, assign) CGFloat keyboardScrollOffset;
35
+
36
+ /**
37
+ * Adjustment added to the keyboard bottom inset applied to the detected
38
+ * scrollable — negative values reduce the inset (e.g. to cancel out safe-area
39
+ * padding already baked into the content's paddingBottom).
40
+ */
41
+ @property (nonatomic, assign) CGFloat keyboardOffset;
42
+
35
43
  @property (nonatomic, weak, nullable) TrueSheetKeyboardObserver *keyboardObserver;
36
44
 
37
45
  /**
38
- * Sibling footer view — an absolute footer rises above the keyboard and
39
- * occludes the content's bottom edge, so it counts toward the keyboard inset.
46
+ * Sibling footer view — a relative footer shields part of the keyboard's
47
+ * overlap from the inset; an absolute footer extends the caret reveal target.
40
48
  */
41
49
  @property (nonatomic, weak, nullable) TrueSheetFooterView *footerView;
42
50
 
43
51
  /**
44
- * Whether the sheet has an `auto` detent. Deriving the sheet height from the
45
- * scroll content is circular with natural layout, so the pinned ScrollView's
46
- * viewport is force-bounded to the container only in this case.
52
+ * Content height measured unconstrained by the shadow node the height the
53
+ * content wants regardless of container bounds (see
54
+ * TrueSheetContentViewShadowNode). Falls back to the frame height before the
55
+ * first state update.
47
56
  */
48
- @property (nonatomic, assign) BOOL hasAutoDetent;
57
+ @property (nonatomic, readonly) CGFloat naturalHeight;
49
58
 
50
59
  /**
51
- * Content height with the pinned ScrollView's viewport replaced by its content
52
- * size the height the content wants regardless of container bounds.
53
- * Falls back to the frame height when no ScrollView is pinned.
60
+ * React tag of the user-provided scrollable (see the `scrollableRef` prop).
61
+ * Setting a new handle clears the currently resolved ScrollView.
54
62
  */
55
- @property (nonatomic, readonly) CGFloat naturalHeight;
63
+ @property (nonatomic, assign) NSInteger scrollableHandle;
64
+
65
+ /**
66
+ * Sets the resolved ScrollView's `contentInsetAdjustmentBehavior` to
67
+ * `automatic` while plugged so UIKit applies the bottom safe-area inset to
68
+ * the scroll content. The previous behavior is restored on clear.
69
+ */
70
+ @property (nonatomic, assign) BOOL contentInsetAdjustment;
56
71
 
57
72
  - (RCTScrollViewComponentView *_Nullable)findScrollView;
58
73
 
59
74
  /**
60
- * Pin the first ScrollView found in the content, wiring insets and keyboard handling
61
- * @param bottomInset Bottom content inset for the scroll view
75
+ * Resolve the ScrollView from `scrollableHandle`, wiring keyboard handling
62
76
  */
63
- - (void)setupScrollableWithBottomInset:(CGFloat)bottomInset;
77
+ - (void)setupScrollable;
64
78
 
65
79
  /**
66
- * Apply scroll edge effects to the pinned scroll view (iOS 26+)
80
+ * Apply scroll edge effects to the detected scroll view (iOS 26+)
67
81
  */
68
82
  - (void)applyScrollEdgeEffects:(nullable ScrollableOptions *)options;
69
83