@swmansion/react-native-bottom-sheet 0.8.0-next.2 → 0.8.0-next.4
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/android/src/main/java/com/swmansion/reactnativebottomsheet/BottomSheetView.kt +3 -4
- package/common/cpp/react/renderer/components/ReactNativeBottomSheetSpec/ComponentDescriptors.h +10 -1
- package/ios/BottomSheetComponentView.mm +3 -3
- package/ios/BottomSheetContentView.h +1 -0
- package/ios/BottomSheetContentView.mm +5 -0
- package/ios/RNSBottomSheetHostingView.swift +12 -4
- package/package.json +1 -1
|
@@ -140,11 +140,10 @@ class BottomSheetView(context: Context) : ReactViewGroup(context) {
|
|
|
140
140
|
val closedTy = detentSpecs.lastOrNull()?.height ?: h.toFloat()
|
|
141
141
|
sheetContainer.translationY = closedTy
|
|
142
142
|
emitPosition()
|
|
143
|
-
snapToIndex(targetIndex, 0f)
|
|
143
|
+
snapToIndex(targetIndex, 0f, emitIndexChange = false)
|
|
144
144
|
} else {
|
|
145
145
|
sheetContainer.translationY = translationY(targetIndex)
|
|
146
146
|
emitPosition()
|
|
147
|
-
listener?.onIndexChange(targetIndex)
|
|
148
147
|
}
|
|
149
148
|
return
|
|
150
149
|
}
|
|
@@ -288,7 +287,7 @@ class BottomSheetView(context: Context) : ReactViewGroup(context) {
|
|
|
288
287
|
|
|
289
288
|
// MARK: - Spring animation
|
|
290
289
|
|
|
291
|
-
private fun snapToIndex(index: Int, velocity: Float) {
|
|
290
|
+
private fun snapToIndex(index: Int, velocity: Float, emitIndexChange: Boolean = true) {
|
|
292
291
|
if (index < 0 || index >= detentSpecs.size) return
|
|
293
292
|
targetIndex = index
|
|
294
293
|
|
|
@@ -310,7 +309,7 @@ class BottomSheetView(context: Context) : ReactViewGroup(context) {
|
|
|
310
309
|
emitPosition()
|
|
311
310
|
activeAnimation = null
|
|
312
311
|
updateInteractionState()
|
|
313
|
-
listener?.onIndexChange(index)
|
|
312
|
+
if (emitIndexChange) listener?.onIndexChange(index)
|
|
314
313
|
}
|
|
315
314
|
}
|
|
316
315
|
|
package/common/cpp/react/renderer/components/ReactNativeBottomSheetSpec/ComponentDescriptors.h
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
-
#include
|
|
3
|
+
#include "ShadowNodes.h"
|
|
4
4
|
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
|
5
5
|
|
|
6
6
|
namespace facebook::react {
|
|
7
7
|
|
|
8
8
|
class BottomSheetViewComponentDescriptor final
|
|
9
9
|
: public ConcreteComponentDescriptor<BottomSheetViewShadowNode> {
|
|
10
|
+
public:
|
|
10
11
|
using ConcreteComponentDescriptor::ConcreteComponentDescriptor;
|
|
12
|
+
|
|
13
|
+
State::Shared createInitialState(
|
|
14
|
+
const Props::Shared& /*props*/,
|
|
15
|
+
const ShadowNodeFamily::Shared& family) const override {
|
|
16
|
+
return std::make_shared<BottomSheetViewShadowNode::ConcreteState>(
|
|
17
|
+
std::make_shared<const BottomSheetViewState>(),
|
|
18
|
+
family);
|
|
19
|
+
}
|
|
11
20
|
};
|
|
12
21
|
|
|
13
22
|
} // namespace facebook::react
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#import "BottomSheetComponentView.h"
|
|
2
2
|
#import "BottomSheetContentView.h"
|
|
3
|
+
#import "../common/cpp/react/renderer/components/ReactNativeBottomSheetSpec/BottomSheetStateHelper.h"
|
|
4
|
+
#import "../common/cpp/react/renderer/components/ReactNativeBottomSheetSpec/ComponentDescriptors.h"
|
|
3
5
|
|
|
4
6
|
#import <React/RCTConversions.h>
|
|
5
7
|
#import <React/RCTFabricComponentsPlugins.h>
|
|
6
|
-
#import <react/renderer/components/ReactNativeBottomSheetSpec/BottomSheetStateHelper.h>
|
|
7
|
-
#import <react/renderer/components/ReactNativeBottomSheetSpec/ComponentDescriptors.h>
|
|
8
8
|
#import <react/renderer/components/ReactNativeBottomSheetSpec/EventEmitters.h>
|
|
9
9
|
#import <react/renderer/components/ReactNativeBottomSheetSpec/Props.h>
|
|
10
10
|
#import <react/renderer/components/ReactNativeBottomSheetSpec/RCTComponentViewHelpers.h>
|
|
@@ -107,7 +107,7 @@ using namespace facebook::react;
|
|
|
107
107
|
emitter->onPositionChange({.position = static_cast<double>(position)});
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
float contentOffsetY = static_cast<float>(
|
|
110
|
+
float contentOffsetY = static_cast<float>(view.currentContentOffsetY);
|
|
111
111
|
if (contentOffsetY == _lastContentOffsetY) {
|
|
112
112
|
return;
|
|
113
113
|
}
|
|
@@ -19,6 +19,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
19
19
|
- (void)setDetents:(NSArray<NSDictionary *> *)raw;
|
|
20
20
|
- (void)setDetentIndex:(NSInteger)newIndex;
|
|
21
21
|
- (void)setScrimColor:(UIColor *_Nullable)color;
|
|
22
|
+
- (CGFloat)currentContentOffsetY;
|
|
22
23
|
- (void)mountChildComponentView:(UIView *)childView atIndex:(NSInteger)index;
|
|
23
24
|
- (void)unmountChildComponentView:(UIView *)childView;
|
|
24
25
|
- (void)resetSheetState;
|
|
@@ -65,6 +65,11 @@
|
|
|
65
65
|
_impl.scrimColor = color;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
- (CGFloat)currentContentOffsetY
|
|
69
|
+
{
|
|
70
|
+
return _impl.currentContentOffsetY;
|
|
71
|
+
}
|
|
72
|
+
|
|
68
73
|
- (void)mountChildComponentView:(UIView *)childView atIndex:(NSInteger)index
|
|
69
74
|
{
|
|
70
75
|
[_impl mountChildComponentView:childView atIndex:index];
|
|
@@ -112,11 +112,10 @@ public final class RNSBottomSheetHostingView: UIView {
|
|
|
112
112
|
let closedTy = detentSpecs.last?.height ?? bounds.height
|
|
113
113
|
sheetContainer.transform = CGAffineTransform(translationX: 0, y: closedTy)
|
|
114
114
|
emitPosition()
|
|
115
|
-
snapToIndex(targetIndex, velocity: 0)
|
|
115
|
+
snapToIndex(targetIndex, velocity: 0, emitIndexChange: false)
|
|
116
116
|
} else {
|
|
117
117
|
sheetContainer.transform = CGAffineTransform(translationX: 0, y: translationY(for: targetIndex))
|
|
118
118
|
emitPosition()
|
|
119
|
-
eventDelegate?.bottomSheetHostingView(self, didChangeIndex: targetIndex)
|
|
120
119
|
}
|
|
121
120
|
return
|
|
122
121
|
}
|
|
@@ -237,6 +236,13 @@ public final class RNSBottomSheetHostingView: UIView {
|
|
|
237
236
|
return maxHeight - ty
|
|
238
237
|
}
|
|
239
238
|
|
|
239
|
+
public var currentContentOffsetY: CGFloat {
|
|
240
|
+
let maxHeight = detentSpecs.last?.height ?? bounds.height
|
|
241
|
+
let containerTop = bounds.height - maxHeight
|
|
242
|
+
let ty = sheetContainer.layer.presentation()?.affineTransform().ty ?? sheetContainer.transform.ty
|
|
243
|
+
return containerTop + ty
|
|
244
|
+
}
|
|
245
|
+
|
|
240
246
|
private var isScrimVisible: Bool {
|
|
241
247
|
modal && currentSheetHeight > 0.5
|
|
242
248
|
}
|
|
@@ -290,7 +296,7 @@ public final class RNSBottomSheetHostingView: UIView {
|
|
|
290
296
|
snapToIndex(closedIndex, velocity: 0)
|
|
291
297
|
}
|
|
292
298
|
|
|
293
|
-
private func snapToIndex(_ index: Int, velocity: CGFloat) {
|
|
299
|
+
private func snapToIndex(_ index: Int, velocity: CGFloat, emitIndexChange: Bool = true) {
|
|
294
300
|
guard index >= 0, index < detentSpecs.count else { return }
|
|
295
301
|
targetIndex = index
|
|
296
302
|
|
|
@@ -316,7 +322,9 @@ public final class RNSBottomSheetHostingView: UIView {
|
|
|
316
322
|
self.activeAnimator = nil
|
|
317
323
|
self.setContentInteractionEnabled(true)
|
|
318
324
|
self.updateInteractionState()
|
|
319
|
-
|
|
325
|
+
if emitIndexChange {
|
|
326
|
+
self.eventDelegate?.bottomSheetHostingView(self, didChangeIndex: index)
|
|
327
|
+
}
|
|
320
328
|
}
|
|
321
329
|
animator.startAnimation()
|
|
322
330
|
activeAnimator = animator
|
package/package.json
CHANGED