@oxyhq/bloom 0.3.6 → 0.3.8
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 +4 -3
- package/lib/commonjs/bottom-sheet/index.js.map +1 -1
- package/lib/commonjs/dialog/Dialog.js +23 -60
- package/lib/commonjs/dialog/Dialog.js.map +1 -1
- package/lib/commonjs/dialog/index.web.js.map +1 -1
- package/lib/commonjs/fonts/FontLoader.native.js +6 -6
- package/lib/commonjs/fonts/FontLoader.native.js.map +1 -1
- package/lib/commonjs/fonts/tokens.js +1 -1
- package/lib/commonjs/fonts/tokens.js.map +1 -1
- package/lib/commonjs/typography/index.js +6 -4
- package/lib/commonjs/typography/index.js.map +1 -1
- package/lib/module/bottom-sheet/index.js +4 -3
- package/lib/module/bottom-sheet/index.js.map +1 -1
- package/lib/module/dialog/Dialog.js +23 -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/module/fonts/FontLoader.native.js +6 -6
- package/lib/module/fonts/FontLoader.native.js.map +1 -1
- package/lib/module/fonts/tokens.js +1 -1
- package/lib/module/fonts/tokens.js.map +1 -1
- package/lib/module/typography/index.js +6 -4
- package/lib/module/typography/index.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/commonjs/fonts/FontLoader.native.d.ts +2 -2
- package/lib/typescript/commonjs/fonts/tokens.d.ts +1 -1
- package/lib/typescript/commonjs/typography/index.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/lib/typescript/module/fonts/FontLoader.native.d.ts +2 -2
- package/lib/typescript/module/fonts/tokens.d.ts +1 -1
- package/lib/typescript/module/typography/index.d.ts.map +1 -1
- package/package.json +1 -6
- package/src/__tests__/FontLoader.native.test.tsx +7 -7
- package/src/bottom-sheet/index.tsx +15 -2
- package/src/dialog/Dialog.tsx +28 -112
- package/src/dialog/index.web.ts +3 -4
- package/src/fonts/FontLoader.native.tsx +6 -6
- package/src/fonts/tokens.ts +1 -1
- package/src/typography/index.tsx +6 -2
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,39 @@ 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
|
+
showHandle={false}
|
|
88
|
+
style={sheetStyle}
|
|
173
89
|
>
|
|
174
90
|
<Context.Provider value={context}>
|
|
175
|
-
<
|
|
91
|
+
<View
|
|
176
92
|
testID={testID}
|
|
177
93
|
style={{ backgroundColor: theme.colors.background }}
|
|
178
94
|
>
|
|
179
95
|
{children}
|
|
180
|
-
</
|
|
96
|
+
</View>
|
|
181
97
|
</Context.Provider>
|
|
182
|
-
</
|
|
98
|
+
</BottomSheet>
|
|
183
99
|
);
|
|
184
100
|
}
|
|
185
101
|
|
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
|
|
@@ -27,9 +27,9 @@ type TextWithDefaults = typeof Text & {
|
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* Mutates `Text.defaultProps.style` so every native `<Text>` in the consuming
|
|
30
|
-
* app inherits Bloom's
|
|
31
|
-
* to any existing default style so caller-provided `style`
|
|
32
|
-
* applies AFTER `defaultProps.style`) still wins for overrides.
|
|
30
|
+
* app inherits Bloom's default font (BlomusModernus). The Bloom family name
|
|
31
|
+
* is prepended to any existing default style so caller-provided `style`
|
|
32
|
+
* (which React applies AFTER `defaultProps.style`) still wins for overrides.
|
|
33
33
|
*
|
|
34
34
|
* Idempotent: re-invoking it after the first apply is a no-op because the
|
|
35
35
|
* first style entry will already be the Bloom default we added.
|
|
@@ -37,7 +37,7 @@ type TextWithDefaults = typeof Text & {
|
|
|
37
37
|
function applyDefaultTextFont(): void {
|
|
38
38
|
const TextWithDefaults = Text as TextWithDefaults;
|
|
39
39
|
const existing = TextWithDefaults.defaultProps?.style;
|
|
40
|
-
const bloomDefault: TextStyle = { fontFamily: '
|
|
40
|
+
const bloomDefault: TextStyle = { fontFamily: 'BlomusModernus' };
|
|
41
41
|
|
|
42
42
|
// Detect whether we've already prepended ourselves. `existing` may be an
|
|
43
43
|
// array (multiple style fragments), a single object, a registered style
|
|
@@ -79,8 +79,8 @@ function applyDefaultTextFont(): void {
|
|
|
79
79
|
* provider tree ever flips `fonts` back on.
|
|
80
80
|
*
|
|
81
81
|
* Once the bundled fonts report `loaded === true`, this component also
|
|
82
|
-
* mutates `Text.defaultProps.style` to prepend `{ fontFamily: '
|
|
83
|
-
* so every native `<Text>` in the consuming app inherits Bloom's
|
|
82
|
+
* mutates `Text.defaultProps.style` to prepend `{ fontFamily: 'BlomusModernus' }`
|
|
83
|
+
* so every native `<Text>` in the consuming app inherits Bloom's default
|
|
84
84
|
* family without callers needing to import `<Text>` from `@oxyhq/bloom`.
|
|
85
85
|
* The mutation is gated by a `useRef` so it runs at most once per
|
|
86
86
|
* FontLoader instance, and the underlying apply is idempotent — the
|
package/src/fonts/tokens.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
export const fontFamilies = {
|
|
12
12
|
display: 'BlomusModernus, Georgia, "Times New Roman", serif',
|
|
13
|
-
sans: '
|
|
13
|
+
sans: 'BlomusModernus, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
|
|
14
14
|
mono: '"Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace',
|
|
15
15
|
} as const;
|
|
16
16
|
|
package/src/typography/index.tsx
CHANGED
|
@@ -24,9 +24,13 @@ function fontFamilyStyle(
|
|
|
24
24
|
if (Platform.OS === 'web') {
|
|
25
25
|
return { fontFamily: `var(--bloom-font-${kind})` };
|
|
26
26
|
}
|
|
27
|
-
if (kind === 'display') return { fontFamily: 'BlomusModernus' };
|
|
28
27
|
if (kind === 'mono') return { fontFamily: 'Geist Mono' };
|
|
29
|
-
|
|
28
|
+
// `display` and `sans` both resolve to BlomusModernus on native — Bloom's
|
|
29
|
+
// default body font. The CSS stack in `tokens.ts` differs (display vs sans
|
|
30
|
+
// have different fallback chains for web), but on RN the literal family
|
|
31
|
+
// name is the only thing that matters; the .ttf is registered via
|
|
32
|
+
// `useFonts(FONT_ASSETS)` in `FontLoader.native.tsx`.
|
|
33
|
+
return { fontFamily: 'BlomusModernus' };
|
|
30
34
|
}
|
|
31
35
|
|
|
32
36
|
const SANS_FONT_FAMILY = fontFamilyStyle('sans');
|