@oxyhq/bloom 0.3.7 → 0.3.9
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/lib/commonjs/bottom-sheet/index.js +54 -47
- package/lib/commonjs/bottom-sheet/index.js.map +1 -1
- package/lib/commonjs/dialog/Dialog.js +22 -60
- package/lib/commonjs/dialog/Dialog.js.map +1 -1
- package/lib/commonjs/dialog/index.web.js.map +1 -1
- package/lib/module/bottom-sheet/index.js +55 -48
- package/lib/module/bottom-sheet/index.js.map +1 -1
- package/lib/module/dialog/Dialog.js +22 -61
- package/lib/module/dialog/Dialog.js.map +1 -1
- package/lib/module/dialog/index.web.js +3 -4
- package/lib/module/dialog/index.web.js.map +1 -1
- package/lib/typescript/commonjs/bottom-sheet/index.d.ts +12 -0
- package/lib/typescript/commonjs/bottom-sheet/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/dialog/Dialog.d.ts +1 -1
- package/lib/typescript/commonjs/dialog/Dialog.d.ts.map +1 -1
- package/lib/typescript/commonjs/dialog/index.web.d.ts.map +1 -1
- package/lib/typescript/module/bottom-sheet/index.d.ts +12 -0
- package/lib/typescript/module/bottom-sheet/index.d.ts.map +1 -1
- package/lib/typescript/module/dialog/Dialog.d.ts +1 -1
- package/lib/typescript/module/dialog/Dialog.d.ts.map +1 -1
- package/lib/typescript/module/dialog/index.web.d.ts.map +1 -1
- package/package.json +1 -6
- package/src/bottom-sheet/index.tsx +66 -45
- package/src/dialog/Dialog.tsx +27 -112
- package/src/dialog/index.web.ts +3 -4
package/src/dialog/Dialog.tsx
CHANGED
|
@@ -1,79 +1,15 @@
|
|
|
1
1
|
import React, { useCallback, useImperativeHandle, useMemo, useRef } from 'react';
|
|
2
|
-
import { Pressable, StyleSheet, View
|
|
2
|
+
import { Pressable, StyleSheet, View } from 'react-native';
|
|
3
3
|
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
4
4
|
|
|
5
|
+
import { BottomSheet, type BottomSheetRef } from '../bottom-sheet';
|
|
5
6
|
import { useTheme } from '../theme/use-theme';
|
|
6
|
-
import { lazyRequire } from '../utils/lazy-require';
|
|
7
7
|
import { Context, useDialogContext } from './context';
|
|
8
8
|
import type { DialogControlProps, DialogInnerProps, DialogOuterProps } from './types';
|
|
9
9
|
|
|
10
10
|
export { useDialogContext, useDialogControl } from './context';
|
|
11
11
|
export type { DialogControlProps, DialogOuterProps, DialogInnerProps } from './types';
|
|
12
12
|
|
|
13
|
-
// ---------------------------------------------------------------------------
|
|
14
|
-
// Local types for @gorhom/bottom-sheet — declared here instead of imported so
|
|
15
|
-
// that Bloom type-checks cleanly in downstream projects that do not install
|
|
16
|
-
// this optional peer dependency. The module is still consumed at runtime via
|
|
17
|
-
// `lazyRequire`, which returns `null` if the package is missing. In that case
|
|
18
|
-
// Dialog.Outer renders nothing with a console warning, so consumers on native
|
|
19
|
-
// MUST install @gorhom/bottom-sheet to use Bloom's Dialog on native.
|
|
20
|
-
// ---------------------------------------------------------------------------
|
|
21
|
-
type BottomSheetBackdropProps = {
|
|
22
|
-
animatedIndex: unknown;
|
|
23
|
-
animatedPosition: unknown;
|
|
24
|
-
style?: StyleProp<ViewStyle>;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
type BottomSheetModalRef = {
|
|
28
|
-
present: () => void;
|
|
29
|
-
dismiss: () => void;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
type BottomSheetModalProps = {
|
|
33
|
-
ref?: React.Ref<BottomSheetModalRef>;
|
|
34
|
-
enablePanDownToClose?: boolean;
|
|
35
|
-
enableDismissOnClose?: boolean;
|
|
36
|
-
enableDynamicSizing?: boolean;
|
|
37
|
-
snapPoints?: (string | number)[];
|
|
38
|
-
backgroundStyle?: StyleProp<ViewStyle>;
|
|
39
|
-
handleComponent?: React.ComponentType | (() => React.ReactNode) | null;
|
|
40
|
-
backdropComponent?: React.ComponentType<BottomSheetBackdropProps>;
|
|
41
|
-
onDismiss?: () => void;
|
|
42
|
-
style?: StyleProp<ViewStyle>;
|
|
43
|
-
children?: React.ReactNode;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
type BottomSheetViewProps = {
|
|
47
|
-
testID?: string;
|
|
48
|
-
style?: StyleProp<ViewStyle>;
|
|
49
|
-
children?: React.ReactNode;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
type BottomSheetBackdropComponentProps = BottomSheetBackdropProps & {
|
|
53
|
-
appearsOnIndex?: number;
|
|
54
|
-
disappearsOnIndex?: number;
|
|
55
|
-
pressBehavior?: 'none' | 'close' | 'collapse' | number;
|
|
56
|
-
opacity?: number;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
type BottomSheetModule = {
|
|
60
|
-
BottomSheetModal: React.ComponentType<BottomSheetModalProps>;
|
|
61
|
-
BottomSheetView: React.ComponentType<BottomSheetViewProps>;
|
|
62
|
-
BottomSheetBackdrop: React.ComponentType<BottomSheetBackdropComponentProps>;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const getBottomSheetModule = lazyRequire<BottomSheetModule>('@gorhom/bottom-sheet');
|
|
66
|
-
|
|
67
|
-
let warnedAboutMissingBottomSheet = false;
|
|
68
|
-
function warnMissingBottomSheet(): void {
|
|
69
|
-
if (warnedAboutMissingBottomSheet) return;
|
|
70
|
-
warnedAboutMissingBottomSheet = true;
|
|
71
|
-
console.warn(
|
|
72
|
-
"[bloom] @gorhom/bottom-sheet is not installed. Bloom's native Dialog will not render. " +
|
|
73
|
-
'Install it as a peer dependency to enable Dialog on native, or rely on the web Dialog implementation on web.',
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
13
|
export function Outer({
|
|
78
14
|
children,
|
|
79
15
|
control,
|
|
@@ -82,7 +18,7 @@ export function Outer({
|
|
|
82
18
|
preventExpansion,
|
|
83
19
|
}: React.PropsWithChildren<DialogOuterProps>) {
|
|
84
20
|
const theme = useTheme();
|
|
85
|
-
const ref = useRef<
|
|
21
|
+
const ref = useRef<BottomSheetRef>(null);
|
|
86
22
|
const closeCallbacks = useRef<(() => void)[]>([]);
|
|
87
23
|
|
|
88
24
|
const callQueuedCallbacks = useCallback(() => {
|
|
@@ -107,6 +43,10 @@ export function Outer({
|
|
|
107
43
|
ref.current?.dismiss();
|
|
108
44
|
}, []);
|
|
109
45
|
|
|
46
|
+
// onDismiss fires after the BottomSheet's close animation finishes — this is
|
|
47
|
+
// the integration point for the closeCallbacks queue. Consumers (e.g.
|
|
48
|
+
// Prompt.Action) rely on the queued callback running AFTER the sheet has
|
|
49
|
+
// visually closed so the screen transition feels natural.
|
|
110
50
|
const handleDismiss = useCallback(() => {
|
|
111
51
|
callQueuedCallbacks();
|
|
112
52
|
onClose?.();
|
|
@@ -123,63 +63,38 @@ export function Outer({
|
|
|
123
63
|
[close],
|
|
124
64
|
);
|
|
125
65
|
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
);
|
|
141
|
-
},
|
|
142
|
-
[bottomSheet],
|
|
66
|
+
const sheetStyle = useMemo(
|
|
67
|
+
() => [
|
|
68
|
+
{
|
|
69
|
+
maxWidth: 500,
|
|
70
|
+
backgroundColor: theme.colors.background,
|
|
71
|
+
borderTopLeftRadius: 20,
|
|
72
|
+
borderTopRightRadius: 20,
|
|
73
|
+
},
|
|
74
|
+
// When the dialog should not be expandable to fill the screen, clamp the
|
|
75
|
+
// sheet to a comfortable fixed height. Mirrors the historical gorhom
|
|
76
|
+
// behaviour where `preventExpansion` locked the sheet to a 40% snap point.
|
|
77
|
+
preventExpansion ? { height: '40%' as const } : null,
|
|
78
|
+
],
|
|
79
|
+
[theme.colors.background, preventExpansion],
|
|
143
80
|
);
|
|
144
81
|
|
|
145
|
-
const renderHandle = useCallback(() => null, []);
|
|
146
|
-
|
|
147
|
-
if (!bottomSheet) {
|
|
148
|
-
// Optional peer `@gorhom/bottom-sheet` is not installed.
|
|
149
|
-
// Dialog.Outer is a no-op in this environment; consumers on native must
|
|
150
|
-
// install the peer to use Bloom's native Dialog implementation.
|
|
151
|
-
warnMissingBottomSheet();
|
|
152
|
-
return null;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const { BottomSheetModal, BottomSheetView } = bottomSheet;
|
|
156
|
-
|
|
157
82
|
return (
|
|
158
|
-
<
|
|
83
|
+
<BottomSheet
|
|
159
84
|
ref={ref}
|
|
160
|
-
enablePanDownToClose
|
|
161
|
-
enableDismissOnClose
|
|
162
|
-
enableDynamicSizing={!preventExpansion}
|
|
163
|
-
snapPoints={preventExpansion ? ['40%'] : undefined}
|
|
164
|
-
backgroundStyle={{
|
|
165
|
-
backgroundColor: theme.colors.background,
|
|
166
|
-
borderTopLeftRadius: 20,
|
|
167
|
-
borderTopRightRadius: 20,
|
|
168
|
-
}}
|
|
169
|
-
handleComponent={renderHandle}
|
|
170
|
-
backdropComponent={renderBackdrop}
|
|
171
85
|
onDismiss={handleDismiss}
|
|
172
|
-
|
|
86
|
+
enablePanDownToClose
|
|
87
|
+
style={sheetStyle}
|
|
173
88
|
>
|
|
174
89
|
<Context.Provider value={context}>
|
|
175
|
-
<
|
|
90
|
+
<View
|
|
176
91
|
testID={testID}
|
|
177
92
|
style={{ backgroundColor: theme.colors.background }}
|
|
178
93
|
>
|
|
179
94
|
{children}
|
|
180
|
-
</
|
|
95
|
+
</View>
|
|
181
96
|
</Context.Provider>
|
|
182
|
-
</
|
|
97
|
+
</BottomSheet>
|
|
183
98
|
);
|
|
184
99
|
}
|
|
185
100
|
|
package/src/dialog/index.web.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
// Web variant of the `./dialog` barrel.
|
|
2
2
|
//
|
|
3
3
|
// The default barrel (`./index.ts`) re-exports from `./Dialog`, which on
|
|
4
|
-
// native uses `react-native-safe-area-context` and
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
// and the in-package `Portal`.
|
|
4
|
+
// native uses `react-native-safe-area-context` and Bloom's own `BottomSheet`
|
|
5
|
+
// primitive. The web fork (`./Dialog.web`) is a pure-DOM modal overlay that
|
|
6
|
+
// depends only on `react-remove-scroll-bar` and the in-package `Portal`.
|
|
8
7
|
//
|
|
9
8
|
// Web bundlers select this file via the `"browser"` condition in
|
|
10
9
|
// `package.json`'s `exports['./dialog']`; native bundlers fall through to
|