react-native-quick-preview 1.0.5 → 2.0.0
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/LICENSE +21 -21
- package/README.md +288 -188
- package/dist/index.d.mts +244 -35
- package/dist/index.d.ts +244 -35
- package/dist/index.js +419 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +407 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +103 -98
- package/src/QuickPreviewAPI.ts +70 -0
- package/src/addons/QuickPreviewPressable.tsx +115 -0
- package/src/context.tsx +91 -0
- package/src/headless/QuickPreview.tsx +56 -0
- package/src/index.ts +24 -2
- package/src/internal/QuickPreviewRoot.tsx +73 -0
- package/src/internal/components/Backdrop.tsx +36 -0
- package/src/internal/components/PopoverContainer.tsx +58 -0
- package/src/internal/components/QuickPreviewScrollView.tsx +21 -0
- package/src/internal/components/SheetContainer.tsx +84 -0
- package/src/internal/resolveSize.ts +17 -0
- package/src/types.ts +93 -0
- package/src/useQuickPreview.ts +28 -0
- package/src/QuickPreview.tsx +0 -222
- package/src/QuickPreviewProperties.ts +0 -46
package/dist/index.d.mts
CHANGED
|
@@ -1,40 +1,249 @@
|
|
|
1
|
-
import React
|
|
2
|
-
import {
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { AccessibilityRole, ScrollViewProps, StyleProp, ViewStyle } from 'react-native';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
/**
|
|
5
|
+
* How the preview is presented.
|
|
6
|
+
* - `'popover'` — a centered card that scales in.
|
|
7
|
+
* - `'sheet'` — a panel that slides up from the bottom and can be swiped down to dismiss.
|
|
8
|
+
*
|
|
9
|
+
* @defaultValue `'popover'`
|
|
10
|
+
*/
|
|
11
|
+
type QuickPreviewVariant = 'popover' | 'sheet';
|
|
12
|
+
/**
|
|
13
|
+
* Constrains the preview container's size.
|
|
14
|
+
* - `'auto'` — size to the content (default).
|
|
15
|
+
* - `number` — a maximum height in points.
|
|
16
|
+
* - `{ maxHeight, maxWidth }` — explicit maximum dimensions in points.
|
|
17
|
+
*
|
|
18
|
+
* @defaultValue `'auto'`
|
|
19
|
+
*/
|
|
20
|
+
type QuickPreviewSize = 'auto' | number | {
|
|
21
|
+
maxHeight?: number;
|
|
22
|
+
maxWidth?: number;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Options for a single presentation, passed to {@link QuickPreviewController.present}
|
|
26
|
+
* (or `QuickPreview.present`, or as `previewOptions` on `QuickPreviewPressable`).
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```tsx
|
|
30
|
+
* present(<Card />, {
|
|
31
|
+
* variant: 'sheet',
|
|
32
|
+
* size: { maxHeight: 480 },
|
|
33
|
+
* dismissOnPanDown: true,
|
|
34
|
+
* })
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
type QuickPreviewOptions = {
|
|
38
|
+
/**
|
|
39
|
+
* Centered `'popover'` or bottom `'sheet'`.
|
|
40
|
+
* @defaultValue `'popover'`
|
|
41
|
+
*/
|
|
42
|
+
variant?: QuickPreviewVariant;
|
|
43
|
+
/**
|
|
44
|
+
* Constrain the container size. A number caps the height; an object caps
|
|
45
|
+
* `maxHeight`/`maxWidth`; `'auto'` sizes to the content.
|
|
46
|
+
* @defaultValue `'auto'`
|
|
47
|
+
*/
|
|
48
|
+
size?: QuickPreviewSize;
|
|
49
|
+
/**
|
|
50
|
+
* Close the preview when the backdrop (the area outside it) is tapped.
|
|
51
|
+
* @defaultValue `true`
|
|
52
|
+
*/
|
|
53
|
+
dismissOnBackdropPress?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Close the preview when it is swiped down. Applies to the `'sheet'` variant only.
|
|
56
|
+
* @defaultValue `true`
|
|
57
|
+
*/
|
|
58
|
+
dismissOnPanDown?: boolean;
|
|
59
|
+
/** Accessibility label announced for the preview container. */
|
|
60
|
+
accessibilityLabel?: string;
|
|
61
|
+
/** Accessibility role for the preview container. */
|
|
62
|
+
accessibilityRole?: AccessibilityRole;
|
|
63
|
+
/** Called on the JS thread when the open animation starts. */
|
|
64
|
+
onOpenStart?: () => void;
|
|
65
|
+
/** Called when the open animation finishes. */
|
|
66
|
+
onOpenEnd?: () => void;
|
|
67
|
+
/** Called when the close animation starts. */
|
|
68
|
+
onCloseStart?: () => void;
|
|
69
|
+
/** Called when the close animation finishes and the preview is unmounted. */
|
|
70
|
+
onCloseEnd?: () => void;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* The imperative controller returned by {@link useQuickPreview} and exposed as the
|
|
74
|
+
* static `QuickPreview` handle. Use it to open, update, and close previews.
|
|
75
|
+
*/
|
|
76
|
+
type QuickPreviewController = {
|
|
77
|
+
/**
|
|
78
|
+
* Present `node` as the preview. Calling this while a preview is already open
|
|
79
|
+
* replaces its content and options.
|
|
80
|
+
* @param node - the React element to show inside the preview.
|
|
81
|
+
* @param opts - presentation options ({@link QuickPreviewOptions}).
|
|
82
|
+
*/
|
|
83
|
+
present: (node: React.ReactNode, opts?: Partial<QuickPreviewOptions>) => void;
|
|
84
|
+
/** Dismiss the current preview. No-op if nothing is open. */
|
|
85
|
+
close: () => void;
|
|
86
|
+
/** Merge new options into the currently open preview (e.g. switch `variant`). */
|
|
87
|
+
update: (opts: Partial<QuickPreviewOptions>) => void;
|
|
88
|
+
/** Whether a preview is currently open. */
|
|
89
|
+
isOpen: () => boolean;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Hosts the preview layer and registers the controller. Mount this once, near the
|
|
94
|
+
* root of your app, inside a `<GestureHandlerRootView>`. After it's mounted you can
|
|
95
|
+
* present previews via {@link useQuickPreview} or the static `QuickPreview` handle.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```tsx
|
|
99
|
+
* <GestureHandlerRootView style={{ flex: 1 }}>
|
|
100
|
+
* <PreviewProvider>
|
|
101
|
+
* <YourApp />
|
|
102
|
+
* </PreviewProvider>
|
|
103
|
+
* </GestureHandlerRootView>
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
declare function PreviewProvider({ children }: {
|
|
107
|
+
children: React.ReactNode;
|
|
108
|
+
}): React.JSX.Element;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Access the {@link QuickPreviewController} to open, update, and close previews
|
|
112
|
+
* from inside a React component. Must be called under a mounted `<PreviewProvider>`.
|
|
113
|
+
*
|
|
114
|
+
* @throws if used outside of a `<PreviewProvider>`.
|
|
115
|
+
* @returns the controller: `{ present, close, update, isOpen }`.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```tsx
|
|
119
|
+
* function ProductCard({ product }) {
|
|
120
|
+
* const { present } = useQuickPreview()
|
|
121
|
+
* return (
|
|
122
|
+
* <Pressable onLongPress={() => present(<ProductPreview product={product} />, { variant: 'sheet' })}>
|
|
123
|
+
* <Thumbnail source={product.image} />
|
|
124
|
+
* </Pressable>
|
|
125
|
+
* )
|
|
126
|
+
* }
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
declare function useQuickPreview(): QuickPreviewController;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* A static handle to the same controller as {@link useQuickPreview} — callable
|
|
133
|
+
* from anywhere, including outside React (services, store actions, event handlers).
|
|
134
|
+
* Before `<PreviewProvider>` mounts it is a safe no-op (with a dev warning).
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* import { QuickPreview } from 'react-native-quick-preview'
|
|
139
|
+
*
|
|
140
|
+
* QuickPreview.present(<Card />, { variant: 'sheet' })
|
|
141
|
+
* QuickPreview.update({ size: { maxHeight: 480 } })
|
|
142
|
+
* QuickPreview.close()
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
declare const QuickPreview$1: {
|
|
146
|
+
/** @internal Registered by `<PreviewProvider />`. Not part of the public API. */
|
|
147
|
+
readonly _set: (c: QuickPreviewController | null) => void;
|
|
148
|
+
/**
|
|
149
|
+
* Present `node` as the preview. Replaces the content if one is already open.
|
|
150
|
+
* @param node - the React element to show inside the preview.
|
|
151
|
+
* @param opts - presentation options ({@link QuickPreviewOptions}).
|
|
152
|
+
*/
|
|
153
|
+
readonly present: (node: React.ReactNode, opts?: Partial<QuickPreviewOptions>) => void;
|
|
154
|
+
/** Dismiss the current preview. No-op if nothing is open. */
|
|
155
|
+
readonly close: () => void;
|
|
156
|
+
/** Merge new options into the currently open preview. */
|
|
157
|
+
readonly update: (opts: Partial<QuickPreviewOptions>) => void;
|
|
158
|
+
/** Whether a preview is currently open. */
|
|
159
|
+
readonly isOpen: () => boolean;
|
|
160
|
+
/** @internal Dev/test convenience — don't use in app code. */
|
|
161
|
+
readonly __unsafe_getController: () => QuickPreviewController | null;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Props for the controlled, headless `QuickPreviewComponent`. Extends
|
|
166
|
+
* {@link QuickPreviewOptions} (so `variant`, `size`, `dismissOn*`, and the
|
|
167
|
+
* lifecycle callbacks are all accepted).
|
|
168
|
+
*/
|
|
169
|
+
type HeadlessQuickPreviewProps = {
|
|
170
|
+
/** Whether the preview is shown. You own this state. */
|
|
7
171
|
visible: boolean;
|
|
172
|
+
/** Called when the preview requests to close (backdrop press, swipe, back button). */
|
|
8
173
|
onClose: () => void;
|
|
9
|
-
/**
|
|
10
|
-
|
|
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
|
-
|
|
174
|
+
/**
|
|
175
|
+
* Render into a portal above the app. Disable only if you're providing your
|
|
176
|
+
* own host/overlay.
|
|
177
|
+
* @defaultValue `true`
|
|
178
|
+
*/
|
|
179
|
+
portal?: boolean;
|
|
180
|
+
} & Partial<QuickPreviewOptions> & {
|
|
181
|
+
/** The preview content. */
|
|
182
|
+
children: React.ReactNode;
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* A controlled, headless preview component — you own the `visible` state. Useful
|
|
186
|
+
* when you prefer a declarative component over the imperative
|
|
187
|
+
* {@link useQuickPreview} hook or the static `QuickPreview` handle.
|
|
188
|
+
*
|
|
189
|
+
* Exported as `QuickPreviewComponent`.
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* ```tsx
|
|
193
|
+
* const [visible, setVisible] = useState(false)
|
|
194
|
+
* <QuickPreviewComponent visible={visible} onClose={() => setVisible(false)} variant="sheet">
|
|
195
|
+
* <Card />
|
|
196
|
+
* </QuickPreviewComponent>
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
declare function QuickPreview({ visible, onClose, portal, children, ...opts }: HeadlessQuickPreviewProps): React.JSX.Element | null;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* A gesture-aware `ScrollView` for use inside preview content. Use it instead of
|
|
203
|
+
* a plain `ScrollView` so that scrolling the content and the swipe-to-dismiss
|
|
204
|
+
* gesture don't fight each other. Accepts all `ScrollViewProps`.
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```tsx
|
|
208
|
+
* present(
|
|
209
|
+
* <QuickPreviewScrollView>
|
|
210
|
+
* <LongArticle />
|
|
211
|
+
* </QuickPreviewScrollView>,
|
|
212
|
+
* { variant: 'sheet', size: { maxHeight: 520 } }
|
|
213
|
+
* )
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
216
|
+
declare function QuickPreviewScrollView(props: ScrollViewProps): React.JSX.Element;
|
|
37
217
|
|
|
38
|
-
|
|
218
|
+
type QuickPreviewPressableProps = {
|
|
219
|
+
children: React.ReactNode;
|
|
220
|
+
/** Called for a normal tap (e.g., navigate) */
|
|
221
|
+
onPress?: () => void;
|
|
222
|
+
/** Return the preview node to present */
|
|
223
|
+
renderPreview: () => React.ReactNode;
|
|
224
|
+
/** Options forwarded to QuickPreview.present */
|
|
225
|
+
previewOptions?: Partial<QuickPreviewOptions>;
|
|
226
|
+
/** Long-press delay (ms). Default 350 */
|
|
227
|
+
delay?: number;
|
|
228
|
+
/** Press-down scale. Default 0.98 */
|
|
229
|
+
scale?: number;
|
|
230
|
+
/**
|
|
231
|
+
* Called on the JS thread when the long press activates, right before the
|
|
232
|
+
* preview opens. Wire up haptics here, e.g.:
|
|
233
|
+
* onLongPressStart={() => Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Medium)}
|
|
234
|
+
* The library deliberately does not import expo-haptics itself: an optional
|
|
235
|
+
* require would break Metro bundling for apps that don't have it installed.
|
|
236
|
+
*/
|
|
237
|
+
onLongPressStart?: () => void;
|
|
238
|
+
/** Disable all interactions */
|
|
239
|
+
disabled?: boolean;
|
|
240
|
+
/** Style applied to the animated wrapper (the thing that scales) */
|
|
241
|
+
style?: StyleProp<ViewStyle>;
|
|
242
|
+
/** Accessibility */
|
|
243
|
+
accessible?: boolean;
|
|
244
|
+
accessibilityLabel?: string;
|
|
245
|
+
testID?: string;
|
|
246
|
+
};
|
|
247
|
+
declare function QuickPreviewPressable({ children, onPress, renderPreview, previewOptions, delay, scale, onLongPressStart, disabled, style, accessible, accessibilityLabel, testID, }: QuickPreviewPressableProps): React.JSX.Element;
|
|
39
248
|
|
|
40
|
-
export {
|
|
249
|
+
export { PreviewProvider, QuickPreview$1 as QuickPreview, QuickPreview as QuickPreviewComponent, type QuickPreviewController, type QuickPreviewOptions, QuickPreviewPressable, QuickPreviewScrollView, type QuickPreviewSize, type QuickPreviewVariant, useQuickPreview };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,40 +1,249 @@
|
|
|
1
|
-
import React
|
|
2
|
-
import {
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { AccessibilityRole, ScrollViewProps, StyleProp, ViewStyle } from 'react-native';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
/**
|
|
5
|
+
* How the preview is presented.
|
|
6
|
+
* - `'popover'` — a centered card that scales in.
|
|
7
|
+
* - `'sheet'` — a panel that slides up from the bottom and can be swiped down to dismiss.
|
|
8
|
+
*
|
|
9
|
+
* @defaultValue `'popover'`
|
|
10
|
+
*/
|
|
11
|
+
type QuickPreviewVariant = 'popover' | 'sheet';
|
|
12
|
+
/**
|
|
13
|
+
* Constrains the preview container's size.
|
|
14
|
+
* - `'auto'` — size to the content (default).
|
|
15
|
+
* - `number` — a maximum height in points.
|
|
16
|
+
* - `{ maxHeight, maxWidth }` — explicit maximum dimensions in points.
|
|
17
|
+
*
|
|
18
|
+
* @defaultValue `'auto'`
|
|
19
|
+
*/
|
|
20
|
+
type QuickPreviewSize = 'auto' | number | {
|
|
21
|
+
maxHeight?: number;
|
|
22
|
+
maxWidth?: number;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Options for a single presentation, passed to {@link QuickPreviewController.present}
|
|
26
|
+
* (or `QuickPreview.present`, or as `previewOptions` on `QuickPreviewPressable`).
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```tsx
|
|
30
|
+
* present(<Card />, {
|
|
31
|
+
* variant: 'sheet',
|
|
32
|
+
* size: { maxHeight: 480 },
|
|
33
|
+
* dismissOnPanDown: true,
|
|
34
|
+
* })
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
type QuickPreviewOptions = {
|
|
38
|
+
/**
|
|
39
|
+
* Centered `'popover'` or bottom `'sheet'`.
|
|
40
|
+
* @defaultValue `'popover'`
|
|
41
|
+
*/
|
|
42
|
+
variant?: QuickPreviewVariant;
|
|
43
|
+
/**
|
|
44
|
+
* Constrain the container size. A number caps the height; an object caps
|
|
45
|
+
* `maxHeight`/`maxWidth`; `'auto'` sizes to the content.
|
|
46
|
+
* @defaultValue `'auto'`
|
|
47
|
+
*/
|
|
48
|
+
size?: QuickPreviewSize;
|
|
49
|
+
/**
|
|
50
|
+
* Close the preview when the backdrop (the area outside it) is tapped.
|
|
51
|
+
* @defaultValue `true`
|
|
52
|
+
*/
|
|
53
|
+
dismissOnBackdropPress?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Close the preview when it is swiped down. Applies to the `'sheet'` variant only.
|
|
56
|
+
* @defaultValue `true`
|
|
57
|
+
*/
|
|
58
|
+
dismissOnPanDown?: boolean;
|
|
59
|
+
/** Accessibility label announced for the preview container. */
|
|
60
|
+
accessibilityLabel?: string;
|
|
61
|
+
/** Accessibility role for the preview container. */
|
|
62
|
+
accessibilityRole?: AccessibilityRole;
|
|
63
|
+
/** Called on the JS thread when the open animation starts. */
|
|
64
|
+
onOpenStart?: () => void;
|
|
65
|
+
/** Called when the open animation finishes. */
|
|
66
|
+
onOpenEnd?: () => void;
|
|
67
|
+
/** Called when the close animation starts. */
|
|
68
|
+
onCloseStart?: () => void;
|
|
69
|
+
/** Called when the close animation finishes and the preview is unmounted. */
|
|
70
|
+
onCloseEnd?: () => void;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* The imperative controller returned by {@link useQuickPreview} and exposed as the
|
|
74
|
+
* static `QuickPreview` handle. Use it to open, update, and close previews.
|
|
75
|
+
*/
|
|
76
|
+
type QuickPreviewController = {
|
|
77
|
+
/**
|
|
78
|
+
* Present `node` as the preview. Calling this while a preview is already open
|
|
79
|
+
* replaces its content and options.
|
|
80
|
+
* @param node - the React element to show inside the preview.
|
|
81
|
+
* @param opts - presentation options ({@link QuickPreviewOptions}).
|
|
82
|
+
*/
|
|
83
|
+
present: (node: React.ReactNode, opts?: Partial<QuickPreviewOptions>) => void;
|
|
84
|
+
/** Dismiss the current preview. No-op if nothing is open. */
|
|
85
|
+
close: () => void;
|
|
86
|
+
/** Merge new options into the currently open preview (e.g. switch `variant`). */
|
|
87
|
+
update: (opts: Partial<QuickPreviewOptions>) => void;
|
|
88
|
+
/** Whether a preview is currently open. */
|
|
89
|
+
isOpen: () => boolean;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Hosts the preview layer and registers the controller. Mount this once, near the
|
|
94
|
+
* root of your app, inside a `<GestureHandlerRootView>`. After it's mounted you can
|
|
95
|
+
* present previews via {@link useQuickPreview} or the static `QuickPreview` handle.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```tsx
|
|
99
|
+
* <GestureHandlerRootView style={{ flex: 1 }}>
|
|
100
|
+
* <PreviewProvider>
|
|
101
|
+
* <YourApp />
|
|
102
|
+
* </PreviewProvider>
|
|
103
|
+
* </GestureHandlerRootView>
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
declare function PreviewProvider({ children }: {
|
|
107
|
+
children: React.ReactNode;
|
|
108
|
+
}): React.JSX.Element;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Access the {@link QuickPreviewController} to open, update, and close previews
|
|
112
|
+
* from inside a React component. Must be called under a mounted `<PreviewProvider>`.
|
|
113
|
+
*
|
|
114
|
+
* @throws if used outside of a `<PreviewProvider>`.
|
|
115
|
+
* @returns the controller: `{ present, close, update, isOpen }`.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```tsx
|
|
119
|
+
* function ProductCard({ product }) {
|
|
120
|
+
* const { present } = useQuickPreview()
|
|
121
|
+
* return (
|
|
122
|
+
* <Pressable onLongPress={() => present(<ProductPreview product={product} />, { variant: 'sheet' })}>
|
|
123
|
+
* <Thumbnail source={product.image} />
|
|
124
|
+
* </Pressable>
|
|
125
|
+
* )
|
|
126
|
+
* }
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
declare function useQuickPreview(): QuickPreviewController;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* A static handle to the same controller as {@link useQuickPreview} — callable
|
|
133
|
+
* from anywhere, including outside React (services, store actions, event handlers).
|
|
134
|
+
* Before `<PreviewProvider>` mounts it is a safe no-op (with a dev warning).
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* import { QuickPreview } from 'react-native-quick-preview'
|
|
139
|
+
*
|
|
140
|
+
* QuickPreview.present(<Card />, { variant: 'sheet' })
|
|
141
|
+
* QuickPreview.update({ size: { maxHeight: 480 } })
|
|
142
|
+
* QuickPreview.close()
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
declare const QuickPreview$1: {
|
|
146
|
+
/** @internal Registered by `<PreviewProvider />`. Not part of the public API. */
|
|
147
|
+
readonly _set: (c: QuickPreviewController | null) => void;
|
|
148
|
+
/**
|
|
149
|
+
* Present `node` as the preview. Replaces the content if one is already open.
|
|
150
|
+
* @param node - the React element to show inside the preview.
|
|
151
|
+
* @param opts - presentation options ({@link QuickPreviewOptions}).
|
|
152
|
+
*/
|
|
153
|
+
readonly present: (node: React.ReactNode, opts?: Partial<QuickPreviewOptions>) => void;
|
|
154
|
+
/** Dismiss the current preview. No-op if nothing is open. */
|
|
155
|
+
readonly close: () => void;
|
|
156
|
+
/** Merge new options into the currently open preview. */
|
|
157
|
+
readonly update: (opts: Partial<QuickPreviewOptions>) => void;
|
|
158
|
+
/** Whether a preview is currently open. */
|
|
159
|
+
readonly isOpen: () => boolean;
|
|
160
|
+
/** @internal Dev/test convenience — don't use in app code. */
|
|
161
|
+
readonly __unsafe_getController: () => QuickPreviewController | null;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Props for the controlled, headless `QuickPreviewComponent`. Extends
|
|
166
|
+
* {@link QuickPreviewOptions} (so `variant`, `size`, `dismissOn*`, and the
|
|
167
|
+
* lifecycle callbacks are all accepted).
|
|
168
|
+
*/
|
|
169
|
+
type HeadlessQuickPreviewProps = {
|
|
170
|
+
/** Whether the preview is shown. You own this state. */
|
|
7
171
|
visible: boolean;
|
|
172
|
+
/** Called when the preview requests to close (backdrop press, swipe, back button). */
|
|
8
173
|
onClose: () => void;
|
|
9
|
-
/**
|
|
10
|
-
|
|
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
|
-
|
|
174
|
+
/**
|
|
175
|
+
* Render into a portal above the app. Disable only if you're providing your
|
|
176
|
+
* own host/overlay.
|
|
177
|
+
* @defaultValue `true`
|
|
178
|
+
*/
|
|
179
|
+
portal?: boolean;
|
|
180
|
+
} & Partial<QuickPreviewOptions> & {
|
|
181
|
+
/** The preview content. */
|
|
182
|
+
children: React.ReactNode;
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* A controlled, headless preview component — you own the `visible` state. Useful
|
|
186
|
+
* when you prefer a declarative component over the imperative
|
|
187
|
+
* {@link useQuickPreview} hook or the static `QuickPreview` handle.
|
|
188
|
+
*
|
|
189
|
+
* Exported as `QuickPreviewComponent`.
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* ```tsx
|
|
193
|
+
* const [visible, setVisible] = useState(false)
|
|
194
|
+
* <QuickPreviewComponent visible={visible} onClose={() => setVisible(false)} variant="sheet">
|
|
195
|
+
* <Card />
|
|
196
|
+
* </QuickPreviewComponent>
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
declare function QuickPreview({ visible, onClose, portal, children, ...opts }: HeadlessQuickPreviewProps): React.JSX.Element | null;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* A gesture-aware `ScrollView` for use inside preview content. Use it instead of
|
|
203
|
+
* a plain `ScrollView` so that scrolling the content and the swipe-to-dismiss
|
|
204
|
+
* gesture don't fight each other. Accepts all `ScrollViewProps`.
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```tsx
|
|
208
|
+
* present(
|
|
209
|
+
* <QuickPreviewScrollView>
|
|
210
|
+
* <LongArticle />
|
|
211
|
+
* </QuickPreviewScrollView>,
|
|
212
|
+
* { variant: 'sheet', size: { maxHeight: 520 } }
|
|
213
|
+
* )
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
216
|
+
declare function QuickPreviewScrollView(props: ScrollViewProps): React.JSX.Element;
|
|
37
217
|
|
|
38
|
-
|
|
218
|
+
type QuickPreviewPressableProps = {
|
|
219
|
+
children: React.ReactNode;
|
|
220
|
+
/** Called for a normal tap (e.g., navigate) */
|
|
221
|
+
onPress?: () => void;
|
|
222
|
+
/** Return the preview node to present */
|
|
223
|
+
renderPreview: () => React.ReactNode;
|
|
224
|
+
/** Options forwarded to QuickPreview.present */
|
|
225
|
+
previewOptions?: Partial<QuickPreviewOptions>;
|
|
226
|
+
/** Long-press delay (ms). Default 350 */
|
|
227
|
+
delay?: number;
|
|
228
|
+
/** Press-down scale. Default 0.98 */
|
|
229
|
+
scale?: number;
|
|
230
|
+
/**
|
|
231
|
+
* Called on the JS thread when the long press activates, right before the
|
|
232
|
+
* preview opens. Wire up haptics here, e.g.:
|
|
233
|
+
* onLongPressStart={() => Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Medium)}
|
|
234
|
+
* The library deliberately does not import expo-haptics itself: an optional
|
|
235
|
+
* require would break Metro bundling for apps that don't have it installed.
|
|
236
|
+
*/
|
|
237
|
+
onLongPressStart?: () => void;
|
|
238
|
+
/** Disable all interactions */
|
|
239
|
+
disabled?: boolean;
|
|
240
|
+
/** Style applied to the animated wrapper (the thing that scales) */
|
|
241
|
+
style?: StyleProp<ViewStyle>;
|
|
242
|
+
/** Accessibility */
|
|
243
|
+
accessible?: boolean;
|
|
244
|
+
accessibilityLabel?: string;
|
|
245
|
+
testID?: string;
|
|
246
|
+
};
|
|
247
|
+
declare function QuickPreviewPressable({ children, onPress, renderPreview, previewOptions, delay, scale, onLongPressStart, disabled, style, accessible, accessibilityLabel, testID, }: QuickPreviewPressableProps): React.JSX.Element;
|
|
39
248
|
|
|
40
|
-
export {
|
|
249
|
+
export { PreviewProvider, QuickPreview$1 as QuickPreview, QuickPreview as QuickPreviewComponent, type QuickPreviewController, type QuickPreviewOptions, QuickPreviewPressable, QuickPreviewScrollView, type QuickPreviewSize, type QuickPreviewVariant, useQuickPreview };
|