@swmansion/react-native-bottom-sheet 0.14.0 → 0.15.0-next.1
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 +9 -2
- package/android/src/main/java/com/swmansion/reactnativebottomsheet/BottomSheetView.kt +21 -9
- package/android/src/main/java/com/swmansion/reactnativebottomsheet/BottomSheetViewManager.kt +6 -2
- package/ios/BottomSheetComponentView.mm +5 -2
- package/ios/BottomSheetContentView.h +3 -1
- package/ios/BottomSheetContentView.mm +4 -2
- package/ios/BottomSheetHostingView.swift +28 -12
- package/lib/module/BottomSheet.js +3 -3
- package/lib/module/BottomSheet.js.map +1 -1
- package/lib/module/BottomSheetNativeComponent.ts +1 -1
- package/lib/typescript/src/BottomSheet.d.ts +7 -0
- package/lib/typescript/src/BottomSheet.d.ts.map +1 -1
- package/lib/typescript/src/BottomSheetNativeComponent.d.ts +1 -0
- package/lib/typescript/src/BottomSheetNativeComponent.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/BottomSheet.tsx +13 -3
- package/src/BottomSheetNativeComponent.ts +1 -1
package/README.md
CHANGED
|
@@ -303,7 +303,12 @@ drag snapping but can still be targeted via `index` updates.
|
|
|
303
303
|
|
|
304
304
|
Use `onPositionChange` to observe the sheet’s current position. It is a standard
|
|
305
305
|
native event; read the distance in pixels from the bottom of the screen to the
|
|
306
|
-
top of the sheet from `event.nativeEvent.position`.
|
|
306
|
+
top of the sheet from `event.nativeEvent.position`. The same event also
|
|
307
|
+
carries `event.nativeEvent.index`—the fractional detent index in
|
|
308
|
+
`0..(detents.length - 1)` (`0` at the shortest detent, `1` at the next, and so
|
|
309
|
+
on, interpolated in between)—the continuous counterpart of `onIndexChange`,
|
|
310
|
+
handy for driving a backdrop or per-detent animation without knowing the
|
|
311
|
+
sheet’s height.
|
|
307
312
|
|
|
308
313
|
```tsx
|
|
309
314
|
<BottomSheet // Or `ModalBottomSheet`.
|
|
@@ -311,7 +316,7 @@ top of the sheet from `event.nativeEvent.position`.
|
|
|
311
316
|
onIndexChange={setIndex}
|
|
312
317
|
surface={/* ... */}
|
|
313
318
|
onPositionChange={(event) => {
|
|
314
|
-
console.log(event.nativeEvent.position);
|
|
319
|
+
console.log(event.nativeEvent.position, event.nativeEvent.index);
|
|
315
320
|
}}
|
|
316
321
|
>
|
|
317
322
|
{/* ... */}
|
|
@@ -356,6 +361,7 @@ import {
|
|
|
356
361
|
|
|
357
362
|
```tsx
|
|
358
363
|
const position = useSharedValue(0);
|
|
364
|
+
const detentIndex = useSharedValue(0);
|
|
359
365
|
|
|
360
366
|
const onPositionChange = useEvent<
|
|
361
367
|
NativeSyntheticEvent<PositionChangeEventData>
|
|
@@ -363,6 +369,7 @@ const onPositionChange = useEvent<
|
|
|
363
369
|
(event) => {
|
|
364
370
|
'worklet';
|
|
365
371
|
position.value = event.position;
|
|
372
|
+
detentIndex.value = event.index;
|
|
366
373
|
},
|
|
367
374
|
['onPositionChange']
|
|
368
375
|
);
|
|
@@ -35,7 +35,7 @@ interface BottomSheetViewListener {
|
|
|
35
35
|
|
|
36
36
|
fun onSettle(index: Int)
|
|
37
37
|
|
|
38
|
-
fun onPositionChange(position: Double)
|
|
38
|
+
fun onPositionChange(position: Double, index: Double)
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
class BottomSheetView(context: Context) : ReactViewGroup(context) {
|
|
@@ -484,10 +484,17 @@ class BottomSheetView(context: Context) : ReactViewGroup(context) {
|
|
|
484
484
|
updateScrim(position)
|
|
485
485
|
updateSheetVisibility(position)
|
|
486
486
|
updateInteractionState()
|
|
487
|
-
listener?.onPositionChange((position / density).toDouble())
|
|
487
|
+
listener?.onPositionChange((position / density).toDouble(), detentIndexAt(position).toDouble())
|
|
488
488
|
updateShadowState(ty)
|
|
489
489
|
}
|
|
490
490
|
|
|
491
|
+
// Fractional detent index in 0..(detentSpecs.size - 1): 0 at the shortest
|
|
492
|
+
// detent, 1 at the next, and so on, interpolated by position in between. The
|
|
493
|
+
// continuous counterpart of `onIndexChange`, so consumers can drive a backdrop
|
|
494
|
+
// or animate per detent without knowing the sheet's height.
|
|
495
|
+
private fun detentIndexAt(position: Float): Float =
|
|
496
|
+
interpolateAtPosition(position, detentSpecs.indices.map { it.toFloat() })
|
|
497
|
+
|
|
491
498
|
private fun updateSheetVisibility(position: Float) {
|
|
492
499
|
sheetContainer.alpha = if (position <= 0.5f) 0f else 1f
|
|
493
500
|
}
|
|
@@ -911,15 +918,20 @@ class BottomSheetView(context: Context) : ReactViewGroup(context) {
|
|
|
911
918
|
* Interpolates the scrim opacity for a sheet height by bracketing it between adjacent detent
|
|
912
919
|
* heights and lerping each detent index's configured value.
|
|
913
920
|
*/
|
|
914
|
-
private fun scrimOpacityAt(position: Float): Float
|
|
921
|
+
private fun scrimOpacityAt(position: Float): Float =
|
|
922
|
+
interpolateAtPosition(
|
|
923
|
+
position,
|
|
924
|
+
detentSpecs.indices.map {
|
|
925
|
+
scrimOpacities[it.coerceAtMost(scrimOpacities.size - 1)].coerceIn(0f, 1f)
|
|
926
|
+
},
|
|
927
|
+
)
|
|
928
|
+
|
|
929
|
+
// Interpolates a per-detent value (one per detent, by index) by the sheet
|
|
930
|
+
// position, using each detent's resolved height as the breakpoint.
|
|
931
|
+
private fun interpolateAtPosition(position: Float, values: List<Float>): Float {
|
|
915
932
|
if (detentSpecs.isEmpty()) return 0f
|
|
916
933
|
val pairs =
|
|
917
|
-
detentSpecs.indices
|
|
918
|
-
.map { index ->
|
|
919
|
-
detentSpecs[index].height to
|
|
920
|
-
scrimOpacities[index.coerceAtMost(scrimOpacities.size - 1)].coerceIn(0f, 1f)
|
|
921
|
-
}
|
|
922
|
-
.sortedBy { it.first }
|
|
934
|
+
detentSpecs.indices.map { detentSpecs[it].height to values[it] }.sortedBy { it.first }
|
|
923
935
|
|
|
924
936
|
val first = pairs.first()
|
|
925
937
|
val last = pairs.last()
|
package/android/src/main/java/com/swmansion/reactnativebottomsheet/BottomSheetViewManager.kt
CHANGED
|
@@ -44,8 +44,12 @@ class BottomSheetViewManager :
|
|
|
44
44
|
dispatchEvent(view, "topSettle", event)
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
override fun onPositionChange(position: Double) {
|
|
48
|
-
val event =
|
|
47
|
+
override fun onPositionChange(position: Double, index: Double) {
|
|
48
|
+
val event =
|
|
49
|
+
Arguments.createMap().apply {
|
|
50
|
+
putDouble("position", position)
|
|
51
|
+
putDouble("index", index)
|
|
52
|
+
}
|
|
49
53
|
dispatchEvent(view, "topPositionChange", event)
|
|
50
54
|
}
|
|
51
55
|
}
|
|
@@ -140,11 +140,14 @@ using namespace facebook::react;
|
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
- (void)bottomSheetView:(BottomSheetContentView *)view
|
|
143
|
+
- (void)bottomSheetView:(BottomSheetContentView *)view
|
|
144
|
+
didChangePosition:(CGFloat)position
|
|
145
|
+
index:(CGFloat)index
|
|
144
146
|
{
|
|
145
147
|
if (_eventEmitter) {
|
|
146
148
|
auto emitter = std::static_pointer_cast<const BottomSheetViewEventEmitter>(_eventEmitter);
|
|
147
|
-
emitter->onPositionChange(
|
|
149
|
+
emitter->onPositionChange(
|
|
150
|
+
{.position = static_cast<double>(position), .index = static_cast<double>(index)});
|
|
148
151
|
}
|
|
149
152
|
|
|
150
153
|
float contentOffsetY = static_cast<float>(view.currentContentOffsetY);
|
|
@@ -7,7 +7,9 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
7
7
|
@protocol BottomSheetContentViewDelegate <NSObject>
|
|
8
8
|
- (void)bottomSheetView:(BottomSheetContentView *)view didChangeIndex:(NSInteger)index;
|
|
9
9
|
- (void)bottomSheetView:(BottomSheetContentView *)view didSettle:(NSInteger)index;
|
|
10
|
-
- (void)bottomSheetView:(BottomSheetContentView *)view
|
|
10
|
+
- (void)bottomSheetView:(BottomSheetContentView *)view
|
|
11
|
+
didChangePosition:(CGFloat)position
|
|
12
|
+
index:(CGFloat)index;
|
|
11
13
|
- (void)bottomSheetView:(BottomSheetContentView *)view didReportError:(NSString *)message;
|
|
12
14
|
@end
|
|
13
15
|
|
|
@@ -125,9 +125,11 @@
|
|
|
125
125
|
[self.delegate bottomSheetView:self didSettle:index];
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
- (void)bottomSheetHostingView:(BottomSheetHostingView *)view
|
|
128
|
+
- (void)bottomSheetHostingView:(BottomSheetHostingView *)view
|
|
129
|
+
didChangePosition:(CGFloat)position
|
|
130
|
+
index:(CGFloat)index
|
|
129
131
|
{
|
|
130
|
-
[self.delegate bottomSheetView:self didChangePosition:position];
|
|
132
|
+
[self.delegate bottomSheetView:self didChangePosition:position index:index];
|
|
131
133
|
}
|
|
132
134
|
|
|
133
135
|
- (void)bottomSheetHostingView:(BottomSheetHostingView *)view didReportError:(NSString *)message
|
|
@@ -3,7 +3,8 @@ import UIKit
|
|
|
3
3
|
@objc public protocol BottomSheetHostingViewDelegate: AnyObject {
|
|
4
4
|
func bottomSheetHostingView(_ view: BottomSheetHostingView, didChangeIndex index: Int)
|
|
5
5
|
func bottomSheetHostingView(_ view: BottomSheetHostingView, didSettle index: Int)
|
|
6
|
-
func bottomSheetHostingView(
|
|
6
|
+
func bottomSheetHostingView(
|
|
7
|
+
_ view: BottomSheetHostingView, didChangePosition position: CGFloat, index: CGFloat)
|
|
7
8
|
func bottomSheetHostingView(_ view: BottomSheetHostingView, didReportError message: String)
|
|
8
9
|
}
|
|
9
10
|
|
|
@@ -357,7 +358,8 @@ public final class BottomSheetHostingView: UIView {
|
|
|
357
358
|
updateScrim(forPosition: position)
|
|
358
359
|
updateSheetVisibility(forPosition: position)
|
|
359
360
|
updateInteractionState()
|
|
360
|
-
eventDelegate?.bottomSheetHostingView(
|
|
361
|
+
eventDelegate?.bottomSheetHostingView(
|
|
362
|
+
self, didChangePosition: position, index: detentIndex(forPosition: position))
|
|
361
363
|
}
|
|
362
364
|
|
|
363
365
|
private func startDisplayLink() {
|
|
@@ -899,26 +901,40 @@ private extension BottomSheetHostingView {
|
|
|
899
901
|
/// Interpolates the scrim opacity for a sheet height by bracketing it between
|
|
900
902
|
/// adjacent detent heights and lerping each detent index's configured value.
|
|
901
903
|
private func scrimOpacity(forPosition position: CGFloat) -> CGFloat {
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
.map {
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
904
|
+
interpolate(
|
|
905
|
+
forPosition: position,
|
|
906
|
+
values: detentSpecs.indices.map {
|
|
907
|
+
clampOpacity(scrimOpacities[min($0, scrimOpacities.count - 1)])
|
|
908
|
+
})
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
// Fractional detent index in 0...(detentSpecs.count - 1): 0 at the shortest
|
|
912
|
+
// detent, 1 at the next, and so on, interpolated by position in between. The
|
|
913
|
+
// continuous counterpart of `onIndexChange`, so consumers can drive a backdrop
|
|
914
|
+
// or animate per detent without knowing the sheet's height.
|
|
915
|
+
private func detentIndex(forPosition position: CGFloat) -> CGFloat {
|
|
916
|
+
interpolate(forPosition: position, values: detentSpecs.indices.map { CGFloat($0) })
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
// Interpolates a per-detent value (one per detent, by index) by the sheet
|
|
920
|
+
// position, using each detent's resolved height as the breakpoint.
|
|
921
|
+
private func interpolate(forPosition position: CGFloat, values: [CGFloat]) -> CGFloat {
|
|
922
|
+
let pairs = zip(detentSpecs.map(\.height), values)
|
|
923
|
+
.map { (height: $0, value: $1) }
|
|
908
924
|
.sorted { $0.height < $1.height }
|
|
909
925
|
|
|
910
926
|
guard let first = pairs.first, let last = pairs.last else { return 0 }
|
|
911
|
-
if position <= first.height { return first.
|
|
912
|
-
if position >= last.height { return last.
|
|
927
|
+
if position <= first.height { return first.value }
|
|
928
|
+
if position >= last.height { return last.value }
|
|
913
929
|
|
|
914
930
|
for i in 1 ..< pairs.count where position <= pairs[i].height {
|
|
915
931
|
let lower = pairs[i - 1]
|
|
916
932
|
let upper = pairs[i]
|
|
917
933
|
let span = upper.height - lower.height
|
|
918
934
|
let t = span <= 0 ? 1 : (position - lower.height) / span
|
|
919
|
-
return lower.
|
|
935
|
+
return lower.value + (upper.value - lower.value) * t
|
|
920
936
|
}
|
|
921
|
-
return last.
|
|
937
|
+
return last.value
|
|
922
938
|
}
|
|
923
939
|
|
|
924
940
|
private func clampOpacity(_ value: CGFloat) -> CGFloat {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import { useState } from 'react';
|
|
4
|
-
import { StyleSheet, View
|
|
5
|
-
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
4
|
+
import { StyleSheet, View } from 'react-native';
|
|
5
|
+
import { useSafeAreaFrame, useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
6
6
|
import BottomSheetNativeView from './BottomSheetNativeComponent';
|
|
7
7
|
import BottomSheetSurfaceNativeComponent from './BottomSheetSurfaceNativeComponent';
|
|
8
8
|
import { Portal } from "./BottomSheetProvider.js";
|
|
@@ -37,7 +37,7 @@ export const BottomSheet = ({
|
|
|
37
37
|
}) => {
|
|
38
38
|
const {
|
|
39
39
|
height: windowHeight
|
|
40
|
-
} =
|
|
40
|
+
} = useSafeAreaFrame();
|
|
41
41
|
const insets = useSafeAreaInsets();
|
|
42
42
|
const maxHeight = windowHeight - insets.top;
|
|
43
43
|
const nativeDetents = detents.map(detent => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useState","StyleSheet","View","
|
|
1
|
+
{"version":3,"names":["useState","StyleSheet","View","useSafeAreaFrame","useSafeAreaInsets","BottomSheetNativeView","BottomSheetSurfaceNativeComponent","Portal","jsx","_jsx","jsxs","_jsxs","programmatic","BottomSheet","children","surface","style","detents","index","animateIn","onIndexChange","onSettle","onPositionChange","wrapNativeView","modal","disableScrollableNegotiation","scrimColor","scrimOpacities","height","windowHeight","insets","maxHeight","top","nativeDetents","map","detent","isDetentProgrammatic","value","resolveDetentValue","kind","Math","max","min","clampedIndex","length","selectedDetentValue","isCollapsed","resolvedScrimOpacity","handleIndexChange","event","nativeEvent","handleSettle","NativeView","sheet","absoluteFill","pointerEvents","position","left","right","bottom","maxDetentHeight","collapsable","flex"],"sourceRoot":"../../src","sources":["BottomSheet.tsx"],"mappings":";;AAAA,SAASA,QAAQ,QAA4C,OAAO;AAEpE,SAASC,UAAU,EAAEC,IAAI,QAAQ,cAAc;AAC/C,SACEC,gBAAgB,EAChBC,iBAAiB,QACZ,gCAAgC;AAEvC,OAAOC,qBAAqB,MAErB,8BAA8B;AACrC,OAAOC,iCAAiC,MAAM,qCAAqC;AACnF,SAASC,MAAM,QAAQ,0BAAuB;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAG/C,SAASC,YAAY,QAAQ,uBAAoB;;AAEjD;AACA;AACA;AACA;;AAaA;AACA;AACA;;AAkFA;AACA,OAAO,MAAMC,WAAW,GAAGA,CAAC;EAC1BC,QAAQ;EACRC,OAAO;EACPC,KAAK;EACLC,OAAO,GAAG,CAAC,CAAC,EAAE,SAAS,CAAC;EACxBC,KAAK;EACLC,SAAS,GAAG,IAAI;EAChBC,aAAa;EACbC,QAAQ;EACRC,gBAAgB;EAChBC,cAAc;EACdC,KAAK,GAAG,KAAK;EACbC,4BAA4B,GAAG,KAAK;EACpCC,UAAU;EACVC;AACgB,CAAC,KAAK;EACtB,MAAM;IAAEC,MAAM,EAAEC;EAAa,CAAC,GAAG1B,gBAAgB,CAAC,CAAC;EACnD,MAAM2B,MAAM,GAAG1B,iBAAiB,CAAC,CAAC;EAClC,MAAM2B,SAAS,GAAGF,YAAY,GAAGC,MAAM,CAACE,GAAG;EAC3C,MAAMC,aAAa,GAAGhB,OAAO,CAACiB,GAAG,CAAEC,MAAM,IAAK;IAC5C,MAAMvB,YAAY,GAAGwB,oBAAoB,CAACD,MAAM,CAAC;IACjD,MAAME,KAAK,GAAGC,kBAAkB,CAACH,MAAM,CA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A,CACG;IAAC,CACT;EAAC,CACH,CACP;EAED,IAAI/B,KAAK,EAAE;IACT,oBAAOf,IAAA,CAACF,MAAM;MAAAO,QAAA,EAAEuC;IAAK,CAAS,CAAC;EACjC;EAEA,OAAOA,KAAK;AACd,CAAC;AAED,SAASjB,oBAAoBA,CAACD,MAAc,EAAW;EACrD,IAAI,OAAOA,MAAM,KAAK,QAAQ,IAAIA,MAAM,KAAK,IAAI,EAAE;IACjD,OAAOA,MAAM,CAACvB,YAAY,KAAK,IAAI;EACrC;EACA,OAAO,KAAK;AACd;AAEA,SAAS0B,kBAAkBA,CAACH,MAAc,EAAE;EAC1C,IAAI,OAAOA,MAAM,KAAK,QAAQ,IAAIA,MAAM,KAAK,IAAI,EAAE;IACjD,OAAOA,MAAM,CAACE,KAAK;EACrB;EACA,OAAOF,MAAM;AACf","ignoreList":[]}
|
|
@@ -27,7 +27,7 @@ export interface NativeProps extends ViewProps {
|
|
|
27
27
|
Readonly<{ index: CodegenTypes.Int32 }>
|
|
28
28
|
>;
|
|
29
29
|
onPositionChange?: CodegenTypes.DirectEventHandler<
|
|
30
|
-
Readonly<{ position: CodegenTypes.Double }>
|
|
30
|
+
Readonly<{ position: CodegenTypes.Double; index: CodegenTypes.Double }>
|
|
31
31
|
>;
|
|
32
32
|
}
|
|
33
33
|
|
|
@@ -11,6 +11,13 @@ export { programmatic } from './bottomSheetUtils';
|
|
|
11
11
|
export type PositionChangeEventData = Readonly<{
|
|
12
12
|
/** Sheet position, in points from the bottom. */
|
|
13
13
|
position: number;
|
|
14
|
+
/**
|
|
15
|
+
* Fractional detent index in `0..(detents.length - 1)`: `0` at the shortest
|
|
16
|
+
* detent, `1` at the next, and so on, interpolated as the sheet moves between
|
|
17
|
+
* them. The continuous counterpart of `onIndexChange`, so a backdrop or
|
|
18
|
+
* per-detent animation can be driven without knowing the sheet's height.
|
|
19
|
+
*/
|
|
20
|
+
index: number;
|
|
14
21
|
}>;
|
|
15
22
|
/**
|
|
16
23
|
* Props for the inline bottom-sheet component.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BottomSheet.d.ts","sourceRoot":"","sources":["../../../src/BottomSheet.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,aAAa,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACrE,OAAO,KAAK,EAAE,oBAAoB,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"BottomSheet.d.ts","sourceRoot":"","sources":["../../../src/BottomSheet.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,aAAa,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACrE,OAAO,KAAK,EAAE,oBAAoB,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAO/E,OAA8B,EAC5B,KAAK,WAAW,EACjB,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD;;;GAGG;AACH,MAAM,MAAM,uBAAuB,GAAG,QAAQ,CAAC;IAC7C,iDAAiD;IACjD,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,KAAK,EAAE,MAAM,CAAC;CACf,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,wDAAwD;IACxD,QAAQ,EAAE,SAAS,CAAC;IACpB;;;;;;;;;;OAUG;IACH,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB,8DAA8D;IAC9D,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B,+DAA+D;IAC/D,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,uCAAuC;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,2DAA2D;IAC3D,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,4EAA4E;IAC5E,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,CACjB,KAAK,EAAE,oBAAoB,CAAC,uBAAuB,CAAC,KACjD,IAAI,CAAC;IACV;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,EAAE,CACf,SAAS,EAAE,aAAa,CAAC,WAAW,CAAC,KAClC,aAAa,CAAC,WAAW,CAAC,CAAC;IAChC,gDAAgD;IAChD,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;;;OAIG;IACH,4BAA4B,CAAC,EAAE,OAAO,CAAC;IACvC,8CAA8C;IAC9C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;;;;;;;;;OAYG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED,gFAAgF;AAChF,eAAO,MAAM,WAAW,GAAI,sLAezB,gBAAgB,4CAgHlB,CAAC"}
|
|
@@ -21,6 +21,7 @@ export interface NativeProps extends ViewProps {
|
|
|
21
21
|
}>>;
|
|
22
22
|
onPositionChange?: CodegenTypes.DirectEventHandler<Readonly<{
|
|
23
23
|
position: CodegenTypes.Double;
|
|
24
|
+
index: CodegenTypes.Double;
|
|
24
25
|
}>>;
|
|
25
26
|
}
|
|
26
27
|
declare const _default: import("react-native/types_generated/Libraries/Utilities/codegenNativeComponent").NativeComponentType<NativeProps>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BottomSheetNativeComponent.d.ts","sourceRoot":"","sources":["../../../src/BottomSheetNativeComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,SAAS,EACf,MA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AAC,MAAM,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,OAAO,CAAC;CACvB,CAAC,CAAC;AAEH,MAAM,WAAW,WAAY,SAAQ,SAAS;IAC5C,OAAO,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;IACrC,eAAe,EAAE,YAAY,CAAC,MAAM,CAAC;IACrC,KAAK,EAAE,YAAY,CAAC,KAAK,CAAC;IAC1B,SAAS,CAAC,EAAE,YAAY,CAAC,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACpD,KAAK,EAAE,OAAO,CAAC;IACf,4BAA4B,CAAC,EAAE,OAAO,CAAC;IACvC,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,cAAc,CAAC,EAAE,aAAa,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IACpD,aAAa,CAAC,EAAE,YAAY,CAAC,kBAAkB,CAC7C,QAAQ,CAAC;QAAE,KAAK,EAAE,YAAY,CAAC,KAAK,CAAA;KAAE,CAAC,CACxC,CAAC;IACF,QAAQ,CAAC,EAAE,YAAY,CAAC,kBAAkB,CACxC,QAAQ,CAAC;QAAE,KAAK,EAAE,YAAY,CAAC,KAAK,CAAA;KAAE,CAAC,CACxC,CAAC;IACF,gBAAgB,CAAC,EAAE,YAAY,CAAC,kBAAkB,CAChD,QAAQ,CAAC;QAAE,QAAQ,EAAE,YAAY,CAAC,MAAM,CAAC;QAAC,KAAK,EAAE,YAAY,CAAC,MAAM,CAAA;KAAE,CAAC,CACxE,CAAC;CACH;;AAED,wBAAsE"}
|
package/package.json
CHANGED
package/src/BottomSheet.tsx
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { useState, type ComponentType, type ReactNode } from 'react';
|
|
2
2
|
import type { NativeSyntheticEvent, StyleProp, ViewStyle } from 'react-native';
|
|
3
|
-
import { StyleSheet, View
|
|
4
|
-
import {
|
|
3
|
+
import { StyleSheet, View } from 'react-native';
|
|
4
|
+
import {
|
|
5
|
+
useSafeAreaFrame,
|
|
6
|
+
useSafeAreaInsets,
|
|
7
|
+
} from 'react-native-safe-area-context';
|
|
5
8
|
|
|
6
9
|
import BottomSheetNativeView, {
|
|
7
10
|
type NativeProps,
|
|
@@ -19,6 +22,13 @@ export { programmatic } from './bottomSheetUtils';
|
|
|
19
22
|
export type PositionChangeEventData = Readonly<{
|
|
20
23
|
/** Sheet position, in points from the bottom. */
|
|
21
24
|
position: number;
|
|
25
|
+
/**
|
|
26
|
+
* Fractional detent index in `0..(detents.length - 1)`: `0` at the shortest
|
|
27
|
+
* detent, `1` at the next, and so on, interpolated as the sheet moves between
|
|
28
|
+
* them. The continuous counterpart of `onIndexChange`, so a backdrop or
|
|
29
|
+
* per-detent animation can be driven without knowing the sheet's height.
|
|
30
|
+
*/
|
|
31
|
+
index: number;
|
|
22
32
|
}>;
|
|
23
33
|
|
|
24
34
|
/**
|
|
@@ -122,7 +132,7 @@ export const BottomSheet = ({
|
|
|
122
132
|
scrimColor,
|
|
123
133
|
scrimOpacities,
|
|
124
134
|
}: BottomSheetProps) => {
|
|
125
|
-
const { height: windowHeight } =
|
|
135
|
+
const { height: windowHeight } = useSafeAreaFrame();
|
|
126
136
|
const insets = useSafeAreaInsets();
|
|
127
137
|
const maxHeight = windowHeight - insets.top;
|
|
128
138
|
const nativeDetents = detents.map((detent) => {
|
|
@@ -27,7 +27,7 @@ export interface NativeProps extends ViewProps {
|
|
|
27
27
|
Readonly<{ index: CodegenTypes.Int32 }>
|
|
28
28
|
>;
|
|
29
29
|
onPositionChange?: CodegenTypes.DirectEventHandler<
|
|
30
|
-
Readonly<{ position: CodegenTypes.Double }>
|
|
30
|
+
Readonly<{ position: CodegenTypes.Double; index: CodegenTypes.Double }>
|
|
31
31
|
>;
|
|
32
32
|
}
|
|
33
33
|
|