@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.
- package/README.md +21 -2
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetContainerView.kt +24 -7
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetContentView.kt +195 -174
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetContentViewManager.kt +5 -1
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetFooterView.kt +6 -17
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetView.kt +50 -8
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetViewController.kt +101 -18
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetViewManager.kt +24 -1
- package/android/src/main/java/com/lodev09/truesheet/core/TrueSheetCoordinatorLayout.kt +3 -3
- package/android/src/main/java/com/lodev09/truesheet/core/TrueSheetDetentCalculator.kt +14 -24
- package/android/src/main/java/com/lodev09/truesheet/utils/ViewUtils.kt +0 -7
- package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetContentViewComponentDescriptor.h +0 -8
- package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetContentViewShadowNode.cpp +54 -29
- package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetContentViewShadowNode.h +6 -1
- package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetContentViewState.cpp +1 -1
- package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetContentViewState.h +6 -4
- package/ios/TrueSheetContainerView.h +9 -7
- package/ios/TrueSheetContainerView.mm +6 -7
- package/ios/TrueSheetContentView.h +28 -14
- package/ios/TrueSheetContentView.mm +122 -179
- package/ios/TrueSheetFooterView.mm +17 -0
- package/ios/TrueSheetView.mm +13 -10
- package/ios/TrueSheetViewController.mm +35 -27
- package/ios/utils/UIView+ScrollEdgeInteraction.h +1 -0
- package/ios/utils/UIView+ScrollEdgeInteraction.mm +24 -2
- package/lib/module/TrueSheet.js +47 -14
- package/lib/module/TrueSheet.js.map +1 -1
- package/lib/module/TrueSheet.web.js +26 -24
- package/lib/module/TrueSheet.web.js.map +1 -1
- package/lib/module/fabric/TrueSheetContentViewNativeComponent.ts +1 -1
- package/lib/module/fabric/TrueSheetViewNativeComponent.ts +4 -0
- package/lib/typescript/src/TrueSheet.d.ts +2 -0
- package/lib/typescript/src/TrueSheet.d.ts.map +1 -1
- package/lib/typescript/src/TrueSheet.types.d.ts +64 -1
- package/lib/typescript/src/TrueSheet.types.d.ts.map +1 -1
- package/lib/typescript/src/TrueSheet.web.d.ts.map +1 -1
- package/lib/typescript/src/fabric/TrueSheetViewNativeComponent.d.ts +3 -0
- package/lib/typescript/src/fabric/TrueSheetViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/navigation/types.d.ts +1 -1
- package/lib/typescript/src/navigation/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/TrueSheet.tsx +48 -13
- package/src/TrueSheet.types.ts +68 -1
- package/src/TrueSheet.web.tsx +39 -24
- package/src/fabric/TrueSheetContentViewNativeComponent.ts +1 -1
- package/src/fabric/TrueSheetViewNativeComponent.ts +4 -0
- package/src/navigation/types.ts +1 -0
package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetContentViewShadowNode.cpp
CHANGED
|
@@ -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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
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
|
|
@@ -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
|
-
*
|
|
14
|
-
* content
|
|
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
|
-
:
|
|
26
|
+
: naturalHeight(previousState.naturalHeight) {}
|
|
25
27
|
#endif
|
|
26
28
|
|
|
27
|
-
|
|
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
|
-
*
|
|
51
|
+
* Options for scrollable behavior
|
|
50
52
|
*/
|
|
51
|
-
@property (nonatomic,
|
|
53
|
+
@property (nonatomic, strong, nullable) ScrollableOptions *scrollableOptions;
|
|
52
54
|
|
|
53
55
|
/**
|
|
54
|
-
*
|
|
56
|
+
* React tag of the user-provided scrollable within the content (see the `scrollableRef` prop)
|
|
55
57
|
*/
|
|
56
|
-
@property (nonatomic,
|
|
58
|
+
@property (nonatomic, assign) NSInteger scrollableHandle;
|
|
57
59
|
|
|
58
60
|
/**
|
|
59
|
-
* Whether the
|
|
60
|
-
*
|
|
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
|
|
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
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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 —
|
|
39
|
-
*
|
|
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
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
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,
|
|
57
|
+
@property (nonatomic, readonly) CGFloat naturalHeight;
|
|
49
58
|
|
|
50
59
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
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,
|
|
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
|
-
*
|
|
61
|
-
* @param bottomInset Bottom content inset for the scroll view
|
|
75
|
+
* Resolve the ScrollView from `scrollableHandle`, wiring keyboard handling
|
|
62
76
|
*/
|
|
63
|
-
- (void)
|
|
77
|
+
- (void)setupScrollable;
|
|
64
78
|
|
|
65
79
|
/**
|
|
66
|
-
* Apply scroll edge effects to the
|
|
80
|
+
* Apply scroll edge effects to the detected scroll view (iOS 26+)
|
|
67
81
|
*/
|
|
68
82
|
- (void)applyScrollEdgeEffects:(nullable ScrollableOptions *)options;
|
|
69
83
|
|