@knitui/components 1.0.0 → 1.2.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/lib/commonjs/ActionIcon/ActionIcon.js +1 -1
- package/lib/commonjs/ActionIcon/ActionIcon.js.map +1 -1
- package/lib/commonjs/Affix/Affix.js +1 -1
- package/lib/commonjs/Affix/Affix.js.map +1 -1
- package/lib/commonjs/Alert/Alert.js +1 -1
- package/lib/commonjs/Alert/Alert.js.map +1 -1
- package/lib/commonjs/Avatar/Avatar.js +1 -1
- package/lib/commonjs/Avatar/Avatar.js.map +1 -1
- package/lib/commonjs/Badge/Badge.js +1 -1
- package/lib/commonjs/Badge/Badge.js.map +1 -1
- package/lib/commonjs/Button/Button.js +1 -1
- package/lib/commonjs/Button/Button.js.map +1 -1
- package/lib/commonjs/CloseButton/CloseButton.js +1 -1
- package/lib/commonjs/CloseButton/CloseButton.js.map +1 -1
- package/lib/commonjs/Image/Image.js +108 -27
- package/lib/commonjs/Image/Image.js.map +1 -1
- package/lib/commonjs/Image/createImage.js +26 -0
- package/lib/commonjs/Image/createImage.js.map +1 -1
- package/lib/commonjs/Image/shared.js +8 -1
- package/lib/commonjs/Image/shared.js.map +1 -1
- package/lib/commonjs/Input/Input.native.js +15 -6
- package/lib/commonjs/Input/Input.native.js.map +1 -1
- package/lib/commonjs/KeyboardAwareScrollView/KeyboardAwareScrollView.native.js.map +1 -1
- package/lib/commonjs/Modal/drag/DragDismissHost.js +4 -1
- package/lib/commonjs/Modal/drag/DragDismissHost.js.map +1 -1
- package/lib/commonjs/Modal/drag/DragDismissOverlay.js +4 -1
- package/lib/commonjs/Modal/drag/DragDismissOverlay.js.map +1 -1
- package/lib/commonjs/Modal/drag/useDragDismiss.js +83 -67
- package/lib/commonjs/Modal/drag/useDragDismiss.js.map +1 -1
- package/lib/commonjs/Modal/modal-base.js +2 -2
- package/lib/commonjs/Modal/modal-base.js.map +1 -1
- package/lib/commonjs/Pill/Pill.js +1 -1
- package/lib/commonjs/Pill/Pill.js.map +1 -1
- package/lib/commonjs/Popover/Popover.shared.js +1 -1
- package/lib/commonjs/Popover/Popover.shared.js.map +1 -1
- package/lib/commonjs/Portal/OverlayHost.js.map +1 -1
- package/lib/commonjs/Portal/OverlayPortal.js +33 -0
- package/lib/commonjs/Portal/OverlayPortal.js.map +1 -0
- package/lib/commonjs/Portal/index.js +7 -0
- package/lib/commonjs/Portal/index.js.map +1 -1
- package/lib/commonjs/ScrollArea/ScrollArea.native.js +25 -15
- package/lib/commonjs/ScrollArea/ScrollArea.native.js.map +1 -1
- package/lib/commonjs/ThemeIcon/ThemeIcon.js +1 -1
- package/lib/commonjs/ThemeIcon/ThemeIcon.js.map +1 -1
- package/lib/commonjs/Tooltip/Tooltip.js +1 -1
- package/lib/commonjs/Tooltip/Tooltip.js.map +1 -1
- package/lib/commonjs/index.js +6 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/internal/gradient-shared.js +11 -1
- package/lib/commonjs/internal/gradient-shared.js.map +1 -1
- package/lib/commonjs/internal/gradient.js +6 -0
- package/lib/commonjs/internal/gradient.js.map +1 -1
- package/lib/commonjs/internal/gradient.native.js +6 -0
- package/lib/commonjs/internal/gradient.native.js.map +1 -1
- package/lib/commonjs/internal/use-looping-animation.native.js +1 -1
- package/lib/commonjs/internal/use-looping-animation.native.js.map +1 -1
- package/lib/module/ActionIcon/ActionIcon.js +2 -2
- package/lib/module/ActionIcon/ActionIcon.js.map +1 -1
- package/lib/module/Affix/Affix.js +2 -2
- package/lib/module/Affix/Affix.js.map +1 -1
- package/lib/module/Alert/Alert.js +2 -2
- package/lib/module/Alert/Alert.js.map +1 -1
- package/lib/module/Avatar/Avatar.js +2 -2
- package/lib/module/Avatar/Avatar.js.map +1 -1
- package/lib/module/Badge/Badge.js +2 -2
- package/lib/module/Badge/Badge.js.map +1 -1
- package/lib/module/Button/Button.js +2 -2
- package/lib/module/Button/Button.js.map +1 -1
- package/lib/module/CloseButton/CloseButton.js +2 -2
- package/lib/module/CloseButton/CloseButton.js.map +1 -1
- package/lib/module/Image/Image.js +108 -27
- package/lib/module/Image/Image.js.map +1 -1
- package/lib/module/Image/createImage.js +26 -1
- package/lib/module/Image/createImage.js.map +1 -1
- package/lib/module/Image/shared.js +7 -0
- package/lib/module/Image/shared.js.map +1 -1
- package/lib/module/Input/Input.native.js +15 -6
- package/lib/module/Input/Input.native.js.map +1 -1
- package/lib/module/KeyboardAwareScrollView/KeyboardAwareScrollView.native.js.map +1 -1
- package/lib/module/Modal/drag/DragDismissHost.js +4 -1
- package/lib/module/Modal/drag/DragDismissHost.js.map +1 -1
- package/lib/module/Modal/drag/DragDismissOverlay.js +4 -1
- package/lib/module/Modal/drag/DragDismissOverlay.js.map +1 -1
- package/lib/module/Modal/drag/useDragDismiss.js +84 -68
- package/lib/module/Modal/drag/useDragDismiss.js.map +1 -1
- package/lib/module/Modal/modal-base.js +3 -3
- package/lib/module/Modal/modal-base.js.map +1 -1
- package/lib/module/Pill/Pill.js +2 -2
- package/lib/module/Pill/Pill.js.map +1 -1
- package/lib/module/Popover/Popover.shared.js +2 -2
- package/lib/module/Popover/Popover.shared.js.map +1 -1
- package/lib/module/Portal/OverlayHost.js.map +1 -1
- package/lib/module/Portal/OverlayPortal.js +28 -0
- package/lib/module/Portal/OverlayPortal.js.map +1 -0
- package/lib/module/Portal/index.js +4 -0
- package/lib/module/Portal/index.js.map +1 -1
- package/lib/module/ScrollArea/ScrollArea.native.js +26 -16
- package/lib/module/ScrollArea/ScrollArea.native.js.map +1 -1
- package/lib/module/ThemeIcon/ThemeIcon.js +2 -2
- package/lib/module/ThemeIcon/ThemeIcon.js.map +1 -1
- package/lib/module/Tooltip/Tooltip.js +2 -2
- package/lib/module/Tooltip/Tooltip.js.map +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/internal/gradient-shared.js +9 -0
- package/lib/module/internal/gradient-shared.js.map +1 -1
- package/lib/module/internal/gradient.js +2 -0
- package/lib/module/internal/gradient.js.map +1 -1
- package/lib/module/internal/gradient.native.js +2 -0
- package/lib/module/internal/gradient.native.js.map +1 -1
- package/lib/module/internal/use-looping-animation.native.js +1 -1
- package/lib/module/internal/use-looping-animation.native.js.map +1 -1
- package/lib/typescript/ActionIcon/ActionIcon.d.ts.map +1 -1
- package/lib/typescript/Alert/Alert.d.ts.map +1 -1
- package/lib/typescript/Avatar/Avatar.d.ts +14 -14
- package/lib/typescript/Avatar/Avatar.d.ts.map +1 -1
- package/lib/typescript/Badge/Badge.d.ts.map +1 -1
- package/lib/typescript/Button/Button.d.ts.map +1 -1
- package/lib/typescript/CloseButton/CloseButton.d.ts.map +1 -1
- package/lib/typescript/Image/Image.d.ts +14 -14
- package/lib/typescript/Image/Image.d.ts.map +1 -1
- package/lib/typescript/Image/Image.native.d.ts +14 -14
- package/lib/typescript/Image/createImage.d.ts +25 -18
- package/lib/typescript/Image/createImage.d.ts.map +1 -1
- package/lib/typescript/Image/index.d.ts +1 -1
- package/lib/typescript/Image/index.d.ts.map +1 -1
- package/lib/typescript/Image/shared.d.ts +6 -0
- package/lib/typescript/Image/shared.d.ts.map +1 -1
- package/lib/typescript/Image/types.d.ts +54 -0
- package/lib/typescript/Image/types.d.ts.map +1 -1
- package/lib/typescript/Input/Input.native.d.ts +21 -21
- package/lib/typescript/Input/Input.native.d.ts.map +1 -1
- package/lib/typescript/KeyboardAvoidingView/KeyboardAvoidingView.native.d.ts +2 -2
- package/lib/typescript/KeyboardAwareScrollView/KeyboardAwareScrollView.native.d.ts +12 -18
- package/lib/typescript/KeyboardAwareScrollView/KeyboardAwareScrollView.native.d.ts.map +1 -1
- package/lib/typescript/Modal/drag/DragDismissHost.d.ts.map +1 -1
- package/lib/typescript/Modal/drag/DragDismissOverlay.d.ts.map +1 -1
- package/lib/typescript/Modal/drag/useDragDismiss.d.ts +2 -2
- package/lib/typescript/Modal/drag/useDragDismiss.d.ts.map +1 -1
- package/lib/typescript/Modal/modal-base-inner.native.d.ts +2 -2
- package/lib/typescript/Modal/modal-base-inner.native.d.ts.map +1 -1
- package/lib/typescript/Pill/Pill.d.ts.map +1 -1
- package/lib/typescript/Portal/OverlayHost.d.ts +2 -2
- package/lib/typescript/Portal/OverlayHost.d.ts.map +1 -1
- package/lib/typescript/Portal/OverlayPortal.d.ts +19 -0
- package/lib/typescript/Portal/OverlayPortal.d.ts.map +1 -0
- package/lib/typescript/Portal/index.d.ts +4 -0
- package/lib/typescript/Portal/index.d.ts.map +1 -1
- package/lib/typescript/ScrollArea/ScrollArea.native.d.ts.map +1 -1
- package/lib/typescript/ThemeIcon/ThemeIcon.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +2 -2
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/internal/gradient-shared.d.ts +1 -0
- package/lib/typescript/internal/gradient-shared.d.ts.map +1 -1
- package/lib/typescript/internal/gradient.d.ts +1 -0
- package/lib/typescript/internal/gradient.d.ts.map +1 -1
- package/lib/typescript/internal/gradient.native.d.ts +1 -0
- package/lib/typescript/internal/gradient.native.d.ts.map +1 -1
- package/lib/typescript/internal/use-looping-animation.native.d.ts +2 -2
- package/lib/typescript/internal/use-looping-animation.native.d.ts.map +1 -1
- package/package.json +12 -12
- package/src/ActionIcon/ActionIcon.tsx +2 -2
- package/src/Affix/Affix.tsx +2 -2
- package/src/Alert/Alert.tsx +2 -2
- package/src/Avatar/Avatar.tsx +2 -2
- package/src/Badge/Badge.tsx +2 -2
- package/src/Button/Button.tsx +2 -2
- package/src/CloseButton/CloseButton.tsx +2 -2
- package/src/Image/Image.tsx +109 -23
- package/src/Image/createImage.tsx +26 -0
- package/src/Image/index.ts +1 -1
- package/src/Image/shared.ts +14 -0
- package/src/Image/types.ts +57 -1
- package/src/Input/Input.native.tsx +22 -7
- package/src/KeyboardAwareScrollView/KeyboardAwareScrollView.native.tsx +33 -32
- package/src/Modal/drag/DragDismissHost.tsx +10 -5
- package/src/Modal/drag/DragDismissOverlay.tsx +9 -5
- package/src/Modal/drag/useDragDismiss.ts +29 -21
- package/src/Modal/modal-base.tsx +4 -4
- package/src/Pill/Pill.tsx +2 -2
- package/src/Popover/Popover.shared.tsx +3 -3
- package/src/Portal/OverlayHost.tsx +4 -4
- package/src/Portal/OverlayPortal.tsx +26 -0
- package/src/Portal/index.ts +4 -0
- package/src/ScrollArea/ScrollArea.native.tsx +39 -33
- package/src/ThemeIcon/ThemeIcon.tsx +2 -2
- package/src/Tooltip/Tooltip.tsx +3 -3
- package/src/index.ts +11 -1
- package/src/internal/gradient-shared.ts +13 -0
- package/src/internal/gradient.native.tsx +1 -0
- package/src/internal/gradient.tsx +1 -0
- package/src/internal/use-looping-animation.native.tsx +2 -2
|
@@ -17,6 +17,7 @@ import { slotStyles, type SlotStyles } from "../internal/styles";
|
|
|
17
17
|
import { themeColorToCssVar } from "../internal/theme-color-web";
|
|
18
18
|
import {
|
|
19
19
|
attachImageStatics,
|
|
20
|
+
IMAGE_WEB_PROP_KEYS,
|
|
20
21
|
normalizeContentPosition,
|
|
21
22
|
objectFitToResizeMode,
|
|
22
23
|
resizeModeToObjectFit,
|
|
@@ -96,6 +97,9 @@ const DEFAULT_INLINE_PROPS = new Set([
|
|
|
96
97
|
"onProgress",
|
|
97
98
|
"onLoadEnd",
|
|
98
99
|
"onDisplay",
|
|
100
|
+
// The web `<img>`'s own attributes (`srcSet`, `sizes`, `decoding`,
|
|
101
|
+
// `fetchPriority`, `loading`) and its `<picture>`'s `sources`: never styles, so Tamagui must not read them.
|
|
102
|
+
...IMAGE_WEB_PROP_KEYS,
|
|
99
103
|
// Identity/test hooks: forwarded untouched so the backend (e.g. expo-image's
|
|
100
104
|
// outer view → `data-testid` on web) keeps them queryable rather than letting
|
|
101
105
|
// Tamagui consume them onto a host element it does not render here.
|
|
@@ -226,6 +230,17 @@ function liftWebColors(rest: Record<string, unknown>): Record<string, string> |
|
|
|
226
230
|
return lifted;
|
|
227
231
|
}
|
|
228
232
|
|
|
233
|
+
/**
|
|
234
|
+
* Native: drop the web `<img>` attributes (`srcSet`, `sizes`, `decoding`,
|
|
235
|
+
* `fetchPriority`, `loading`) and the `<picture>`'s `sources` from the backend's props, in place — they mean nothing to
|
|
236
|
+
* expo-image (it picks from a `source` list itself), so no unknown prop reaches
|
|
237
|
+
* it. The web keeps them. Exported for the native-path test.
|
|
238
|
+
*/
|
|
239
|
+
export function withoutWebOnlyProps<T extends Record<string, unknown>>(props: T): T {
|
|
240
|
+
if (!isWeb) for (const key of IMAGE_WEB_PROP_KEYS) delete props[key];
|
|
241
|
+
return props;
|
|
242
|
+
}
|
|
243
|
+
|
|
229
244
|
/** Frames `useWebCachedImageLoad` waits for the backend to put its `<img>` in the DOM. */
|
|
230
245
|
const CACHED_LOAD_MAX_FRAMES = 10;
|
|
231
246
|
|
|
@@ -414,6 +429,7 @@ export function createImage<C extends ComponentType<Record<string, unknown>>>(
|
|
|
414
429
|
Record<string, unknown>
|
|
415
430
|
>(function ImageBackendAdapter(backendProps, backendRef) {
|
|
416
431
|
const { [TRANSITION_INLINE_ALIAS]: transitionValue, ...backendRest } = backendProps;
|
|
432
|
+
withoutWebOnlyProps(backendRest);
|
|
417
433
|
const { ref, onLoad } = useWebCachedImageLoad(
|
|
418
434
|
backendRef,
|
|
419
435
|
backendRest.onLoad as ((...args: unknown[]) => void) | undefined,
|
|
@@ -562,6 +578,16 @@ export function createImage<C extends ComponentType<Record<string, unknown>>>(
|
|
|
562
578
|
onError?.(errorEvent);
|
|
563
579
|
}, [markErrored, onError]);
|
|
564
580
|
|
|
581
|
+
// The fallback is one URL: the primary's web candidates (`srcSet`,
|
|
582
|
+
// `sizes`, `<picture>` `sources`) go with it, or the browser would keep
|
|
583
|
+
// picking the variant that just failed over the `fallbackSrc`.
|
|
584
|
+
if (errored && fallbackSrc) {
|
|
585
|
+
const restProps = rest as Record<string, unknown>;
|
|
586
|
+
delete restProps.srcSet;
|
|
587
|
+
delete restProps.sizes;
|
|
588
|
+
delete restProps.sources;
|
|
589
|
+
}
|
|
590
|
+
|
|
565
591
|
const finalProps: Record<string, unknown> = {
|
|
566
592
|
...rest,
|
|
567
593
|
source: finalSource,
|
package/src/Image/index.ts
CHANGED
package/src/Image/shared.ts
CHANGED
|
@@ -15,6 +15,20 @@ import type {
|
|
|
15
15
|
ImageType,
|
|
16
16
|
} from "./types";
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* The web-only `<img>` / `<picture>` props (`ImageWebProps`): forwarded
|
|
20
|
+
* untouched to the web `<img>` (and `sources` to its `<picture>`), dropped
|
|
21
|
+
* before native expo-image sees them.
|
|
22
|
+
*/
|
|
23
|
+
export const IMAGE_WEB_PROP_KEYS = [
|
|
24
|
+
"srcSet",
|
|
25
|
+
"sizes",
|
|
26
|
+
"decoding",
|
|
27
|
+
"fetchPriority",
|
|
28
|
+
"loading",
|
|
29
|
+
"sources",
|
|
30
|
+
] as const;
|
|
31
|
+
|
|
18
32
|
/**
|
|
19
33
|
* Pull a usable `src` value (URL string, `require()` number, or `{ uri }`
|
|
20
34
|
* object) out of either the `src` or deprecated `source` prop. Returns
|
package/src/Image/types.ts
CHANGED
|
@@ -121,7 +121,63 @@ export type ImageProps = Omit<ViewProps, "transition"> &
|
|
|
121
121
|
objectPosition?: ImageObjectPosition;
|
|
122
122
|
onLoad?: (event: ImageLoadEvent) => void;
|
|
123
123
|
onError?: (event: ImageErrorEvent) => void;
|
|
124
|
-
};
|
|
124
|
+
} & ImageWebProps;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Web-only `<img>` attributes, written on the real `<img>` (never its wrapper)
|
|
128
|
+
* and in the server HTML, so the browser's preload scanner sees them before
|
|
129
|
+
* hydration. Native drops them without a warning: expo-image picks from a
|
|
130
|
+
* `source` list by its own measured size.
|
|
131
|
+
*
|
|
132
|
+
* The intrinsic size is the SOURCE's: a source object's `width` / `height`
|
|
133
|
+
* (`src={{ uri, width: 1600, height: 900 }}`, or numeric `width` / `height`
|
|
134
|
+
* props, which the unified API turns into one) become the `<img>`'s `width` /
|
|
135
|
+
* `height` attributes, so the browser knows the picture's aspect ratio before
|
|
136
|
+
* a byte arrives.
|
|
137
|
+
*/
|
|
138
|
+
export type ImageWebProps = {
|
|
139
|
+
/** The `<img srcset>` candidates (`"a.avif 256w, b.avif 512w"`), web only. */
|
|
140
|
+
srcSet?: string;
|
|
141
|
+
/** The `<img sizes>` the browser picks a `srcSet` candidate by, web only. */
|
|
142
|
+
sizes?: string;
|
|
143
|
+
/** The `<img decoding>` hint: `"async"` off the main thread, `"sync"` for the one hero. Web only. */
|
|
144
|
+
decoding?: "async" | "sync" | "auto";
|
|
145
|
+
/**
|
|
146
|
+
* The `<img fetchpriority>`, web only. Wins over `priority` there (which maps
|
|
147
|
+
* `"high"` / `"low"` to it too).
|
|
148
|
+
*/
|
|
149
|
+
fetchPriority?: "high" | "low" | "auto";
|
|
150
|
+
/**
|
|
151
|
+
* The `<img loading>`, web only. Default `"lazy"` (the browser fetches an
|
|
152
|
+
* image as it nears the viewport); `"eager"` for the one above-the-fold
|
|
153
|
+
* (LCP) image, with `fetchPriority="high"`.
|
|
154
|
+
*/
|
|
155
|
+
loading?: "lazy" | "eager";
|
|
156
|
+
/**
|
|
157
|
+
* Format alternatives, web only: given (non-empty), the `<img>` is wrapped
|
|
158
|
+
* in a `<picture>` with one `<source>` per entry, in order, before it. The
|
|
159
|
+
* browser takes the first source whose `type` it decodes (and whose `media`
|
|
160
|
+
* matches); none does → the `<img>`'s own `src` / `srcSet`. So
|
|
161
|
+
* `sources={[{ type: "image/avif", srcSet: avif, sizes }]}` with a WebP
|
|
162
|
+
* `src` / `srcSet` downloads only the AVIF where it is supported and only
|
|
163
|
+
* the WebP elsewhere. The `<picture>` is `display: contents` (no box of its
|
|
164
|
+
* own), and the `<img>` stays the element that loads, errors and fills the
|
|
165
|
+
* box. Native ignores them: expo-image picks its own format.
|
|
166
|
+
*/
|
|
167
|
+
sources?: readonly ImageWebSource[];
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
/** One `<picture><source>` of {@link ImageWebProps.sources}, web only. */
|
|
171
|
+
export type ImageWebSource = {
|
|
172
|
+
/** The `<source srcset>` candidates (`"a.avif 256w, b.avif 512w"`, or one URL). */
|
|
173
|
+
srcSet: string;
|
|
174
|
+
/** The MIME type (`"image/avif"`): a browser that can't decode it skips the source. */
|
|
175
|
+
type: string;
|
|
176
|
+
/** The `<source sizes>`; omitted, the browser assumes `100vw`. */
|
|
177
|
+
sizes?: string;
|
|
178
|
+
/** The `<source media>` query the source applies under. */
|
|
179
|
+
media?: string;
|
|
180
|
+
};
|
|
125
181
|
|
|
126
182
|
export type { ImageErrorEventData };
|
|
127
183
|
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
registerFocusable,
|
|
8
8
|
styleable,
|
|
9
9
|
styled,
|
|
10
|
+
type TamaguiElement,
|
|
10
11
|
useNativeInputRef,
|
|
11
12
|
withStaticProperties,
|
|
12
13
|
} from "@knitui/core";
|
|
@@ -44,11 +45,23 @@ import type {
|
|
|
44
45
|
// (`INPUT_HOST_CONFIG`). `isInput` makes `placeholderTextColor` / `selectionColor`
|
|
45
46
|
// / `cursorColor` theme-resolved colour props, and the underlying RN TextInput
|
|
46
47
|
// identity stays stable across renders, so the controlled input is state-safe.
|
|
47
|
-
|
|
48
|
+
// RN 0.88's TextInput type names a private instance class (`_TextInputInstance`)
|
|
49
|
+
// that declaration emit can't reference, so the host is typed with a portable ref.
|
|
50
|
+
const TextInputHost = TextInput as React.ComponentType<
|
|
51
|
+
RNTextInputProps & React.RefAttributes<TamaguiElement>
|
|
52
|
+
>;
|
|
53
|
+
const InputHostStyle = styled(TextInputHost, INPUT_HOST_CONFIG, INPUT_HOST_STATIC);
|
|
48
54
|
|
|
49
55
|
const FILL_HEIGHT = { height: "100%" } as const;
|
|
50
56
|
const NO_FONT_PADDING = { includeFontPadding: false } as const;
|
|
51
57
|
const NO_POINTER_EVENTS = { pointerEvents: "none" } as const;
|
|
58
|
+
// RN 0.88 dropped the `verticalAlign` TextInput prop; it survives as our alias.
|
|
59
|
+
const VERTICAL_ALIGN_TO_TEXT_ALIGN_VERTICAL = {
|
|
60
|
+
auto: "auto",
|
|
61
|
+
top: "top",
|
|
62
|
+
bottom: "bottom",
|
|
63
|
+
middle: "center",
|
|
64
|
+
} as const;
|
|
52
65
|
|
|
53
66
|
// Native key payloads have no DOM event to defer to; consumers still call
|
|
54
67
|
// `preventDefault`/`stopPropagation`, so hand them a no-op.
|
|
@@ -500,7 +513,7 @@ const InputComponent = styleable<NativeInputProps>(
|
|
|
500
513
|
caretHidden,
|
|
501
514
|
contextMenuHidden,
|
|
502
515
|
selectTextOnFocus,
|
|
503
|
-
maxFontSizeMultiplier,
|
|
516
|
+
maxFontSizeMultiplier: maxFontSizeMultiplier ?? undefined,
|
|
504
517
|
allowFontScaling,
|
|
505
518
|
autoCapitalize,
|
|
506
519
|
autoCorrect,
|
|
@@ -512,8 +525,8 @@ const InputComponent = styleable<NativeInputProps>(
|
|
|
512
525
|
enablesReturnKeyAutomatically,
|
|
513
526
|
dataDetectorTypes,
|
|
514
527
|
scrollEnabled,
|
|
515
|
-
passwordRules,
|
|
516
|
-
rejectResponderTermination,
|
|
528
|
+
passwordRules: passwordRules ?? undefined,
|
|
529
|
+
rejectResponderTermination: rejectResponderTermination ?? undefined,
|
|
517
530
|
spellCheck,
|
|
518
531
|
lineBreakStrategyIOS,
|
|
519
532
|
lineBreakModeIOS,
|
|
@@ -532,8 +545,10 @@ const InputComponent = styleable<NativeInputProps>(
|
|
|
532
545
|
// Top-align multiline text by default so the explicit vertical padding is
|
|
533
546
|
// measured from the top edge consistently (Android otherwise centers it). A
|
|
534
547
|
// consumer-passed `textAlignVertical` still wins.
|
|
535
|
-
textAlignVertical:
|
|
536
|
-
|
|
548
|
+
textAlignVertical:
|
|
549
|
+
textAlignVertical ??
|
|
550
|
+
(verticalAlign ? VERTICAL_ALIGN_TO_TEXT_ALIGN_VERTICAL[verticalAlign] : undefined) ??
|
|
551
|
+
(multiline ? "top" : undefined),
|
|
537
552
|
showSoftInputOnFocus,
|
|
538
553
|
};
|
|
539
554
|
|
|
@@ -567,7 +582,7 @@ const InputComponent = styleable<NativeInputProps>(
|
|
|
567
582
|
__defaultRightSection={__defaultRightSection}
|
|
568
583
|
>
|
|
569
584
|
<InputHostStyle
|
|
570
|
-
ref={composedRef as React.Ref<
|
|
585
|
+
ref={composedRef as React.Ref<TamaguiElement>}
|
|
571
586
|
flex={1}
|
|
572
587
|
minWidth={0}
|
|
573
588
|
paddingVertical={multiline ? getTextareaPaddingVertical(effectiveSize) : 0}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { Platform, ScrollView } from "react-native";
|
|
2
|
+
import { Platform, ScrollView, type ScrollViewInstance } from "react-native";
|
|
3
3
|
|
|
4
4
|
import { type GetProps, styled } from "@knitui/core";
|
|
5
5
|
import { useKeyboardHeight } from "@knitui/hooks";
|
|
@@ -44,36 +44,37 @@ export type KeyboardAwareScrollViewProps = GetProps<typeof Frame> & {
|
|
|
44
44
|
ScrollViewComponent?: unknown;
|
|
45
45
|
};
|
|
46
46
|
|
|
47
|
-
export const KeyboardAwareScrollView = React.forwardRef<
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
47
|
+
export const KeyboardAwareScrollView = React.forwardRef<
|
|
48
|
+
ScrollViewInstance,
|
|
49
|
+
KeyboardAwareScrollViewProps
|
|
50
|
+
>(function KeyboardAwareScrollView(props, ref) {
|
|
51
|
+
const {
|
|
52
|
+
bottomOffset: _bottomOffset,
|
|
53
|
+
extraKeyboardSpace,
|
|
54
|
+
disableScrollOnKeyboardHide: _disableScrollOnKeyboardHide,
|
|
55
|
+
enabled: _enabled,
|
|
56
|
+
mode: _mode,
|
|
57
|
+
ScrollViewComponent: _ScrollViewComponent,
|
|
58
|
+
keyboardShouldPersistTaps = "handled",
|
|
59
|
+
contentContainerStyle,
|
|
60
|
+
...rest
|
|
61
|
+
} = props;
|
|
60
62
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
const keyboardHeight = useKeyboardHeight();
|
|
64
|
+
// iOS handles the inset itself via `automaticallyAdjustKeyboardInsets`, so only
|
|
65
|
+
// pad on Android to avoid double-spacing.
|
|
66
|
+
const paddingBottom =
|
|
67
|
+
Platform.OS === "android" && keyboardHeight > 0
|
|
68
|
+
? keyboardHeight + (extraKeyboardSpace ?? 0)
|
|
69
|
+
: undefined;
|
|
68
70
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
);
|
|
71
|
+
return (
|
|
72
|
+
<Frame
|
|
73
|
+
ref={ref}
|
|
74
|
+
keyboardShouldPersistTaps={keyboardShouldPersistTaps}
|
|
75
|
+
automaticallyAdjustKeyboardInsets
|
|
76
|
+
contentContainerStyle={[contentContainerStyle, paddingBottom != null && { paddingBottom }]}
|
|
77
|
+
{...rest}
|
|
78
|
+
/>
|
|
79
|
+
);
|
|
80
|
+
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import Animated, { useAnimatedStyle } from "react-native-reanimated";
|
|
3
|
+
import { isWeb } from "@knitui/core";
|
|
3
4
|
|
|
4
5
|
import type { DragDismissHostProps } from "./types";
|
|
5
6
|
|
|
@@ -14,11 +15,15 @@ import type { DragDismissHostProps } from "./types";
|
|
|
14
15
|
*/
|
|
15
16
|
export const DragDismissHost = React.forwardRef<Animated.View, DragDismissHostProps>(
|
|
16
17
|
function DragDismissHost({ offset, axis, sign, style, pointerEvents, children }, ref) {
|
|
17
|
-
const animatedStyle = useAnimatedStyle(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
const animatedStyle = useAnimatedStyle(
|
|
19
|
+
() => {
|
|
20
|
+
"worklet";
|
|
21
|
+
const t = sign * offset.value;
|
|
22
|
+
return { transform: axis === "x" ? [{ translateX: t }] : [{ translateY: t }] };
|
|
23
|
+
},
|
|
24
|
+
// Web-only deps: Reanimated 4.7 ignores them on native and warns when given.
|
|
25
|
+
isWeb ? [axis, sign] : undefined,
|
|
26
|
+
);
|
|
22
27
|
|
|
23
28
|
return (
|
|
24
29
|
<Animated.View ref={ref} style={[style, animatedStyle]} pointerEvents={pointerEvents}>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import Animated, { useAnimatedStyle } from "react-native-reanimated";
|
|
3
3
|
|
|
4
|
-
import type
|
|
4
|
+
import { isWeb, type ViewStyle } from "@knitui/core";
|
|
5
5
|
|
|
6
6
|
import { Overlay } from "../../Overlay";
|
|
7
7
|
import { dragOverlayOpacity } from "./engine";
|
|
@@ -22,10 +22,14 @@ export function DragDismissOverlay({
|
|
|
22
22
|
onPress,
|
|
23
23
|
overlayProps,
|
|
24
24
|
}: DragDismissOverlayProps) {
|
|
25
|
-
const style = useAnimatedStyle(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
const style = useAnimatedStyle(
|
|
26
|
+
() => {
|
|
27
|
+
"worklet";
|
|
28
|
+
return { opacity: dragOverlayOpacity(offset.value, extent, maxOpacity) };
|
|
29
|
+
},
|
|
30
|
+
// Web-only deps: Reanimated 4.7 ignores them on native and warns when given.
|
|
31
|
+
isWeb ? [extent, maxOpacity] : undefined,
|
|
32
|
+
);
|
|
29
33
|
|
|
30
34
|
return (
|
|
31
35
|
<Animated.View style={[FILL, { zIndex: 0 }, style]} pointerEvents="box-none">
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
type PanGesture,
|
|
4
|
+
type PanGestureConfig,
|
|
5
|
+
usePanGesture,
|
|
6
|
+
} from "react-native-gesture-handler";
|
|
3
7
|
import {
|
|
4
8
|
cancelAnimation,
|
|
5
9
|
type SharedValue,
|
|
@@ -61,12 +65,12 @@ export interface DragDismissParams {
|
|
|
61
65
|
}
|
|
62
66
|
|
|
63
67
|
/**
|
|
64
|
-
* A single-axis drag-to-dismiss `
|
|
68
|
+
* A single-axis drag-to-dismiss pan (RNGH 3 `usePanGesture`), shared by `Modal` (axis `y`,
|
|
65
69
|
* sign `-1` — drag up) and `Drawer` (per-edge axis/sign). Tracks the finger toward the
|
|
66
70
|
* dismiss edge into `offset` (rubber-banding the wrong way), and on release runs
|
|
67
71
|
* the pure {@link shouldDismiss} on the UI thread: dismiss → spring off-screen
|
|
68
72
|
* then `onDismiss`; otherwise spring back to rest. Works on web and native (RNGH
|
|
69
|
-
* `
|
|
73
|
+
* `usePanGesture` supports both). Returns the gesture for a `<GestureDetector>`.
|
|
70
74
|
*/
|
|
71
75
|
export function useDragDismiss(params: DragDismissParams): PanGesture {
|
|
72
76
|
const { offset, axis, sign, extent, dismissTravel, enabled, threshold, spring, onDismiss } =
|
|
@@ -75,7 +79,7 @@ export function useDragDismiss(params: DragDismissParams): PanGesture {
|
|
|
75
79
|
// Whether this cycle activated (crossed the threshold into a real drag). A bare
|
|
76
80
|
// tap begins + finalizes without activating, so this stays false.
|
|
77
81
|
const active = useSharedValue(false);
|
|
78
|
-
// Whether `
|
|
82
|
+
// Whether `onDeactivate` already committed a settle, so the `onFinalize` safety net only
|
|
79
83
|
// runs for an activated drag that was cancelled/interrupted before a clean end.
|
|
80
84
|
const settled = useSharedValue(false);
|
|
81
85
|
const config = spring ?? DEFAULT_DISMISS_SPRING;
|
|
@@ -84,25 +88,26 @@ export function useDragDismiss(params: DragDismissParams): PanGesture {
|
|
|
84
88
|
// only the settle target differs (see `dismissTravel`).
|
|
85
89
|
const exitTo = dismissTravel != null && dismissTravel > extent ? dismissTravel : extent;
|
|
86
90
|
|
|
87
|
-
|
|
91
|
+
// Config identity drives RNGH's re-configuration (`usePanGesture` re-sends the
|
|
92
|
+
// config to the native handler whenever the object changes), so memoize it on
|
|
93
|
+
// exactly the inputs the callbacks close over.
|
|
94
|
+
const panConfig = React.useMemo((): PanGestureConfig => {
|
|
88
95
|
// Only claim the touch once it has travelled along the drag axis — taps,
|
|
89
96
|
// control presses, and cross-axis swipes are left to their own handlers.
|
|
90
97
|
const threshold2: [number, number] = [-ACTIVATION_THRESHOLD, ACTIVATION_THRESHOLD];
|
|
91
|
-
const gesture =
|
|
92
|
-
axis === "x"
|
|
93
|
-
? Gesture.Pan().enabled(enabled).activeOffsetX(threshold2)
|
|
94
|
-
: Gesture.Pan().enabled(enabled).activeOffsetY(threshold2);
|
|
95
98
|
|
|
96
|
-
return
|
|
97
|
-
|
|
99
|
+
return {
|
|
100
|
+
enabled,
|
|
101
|
+
...(axis === "x" ? { activeOffsetX: threshold2 } : { activeOffsetY: threshold2 }),
|
|
102
|
+
onBegin: () => {
|
|
98
103
|
"worklet";
|
|
99
104
|
// Touch-down (may still be a tap). Reset the cycle flags but leave any
|
|
100
105
|
// running settle spring alone — cancelling here would freeze a mid-flight
|
|
101
106
|
// panel under a tap that never becomes a drag.
|
|
102
107
|
active.value = false;
|
|
103
108
|
settled.value = false;
|
|
104
|
-
}
|
|
105
|
-
|
|
109
|
+
},
|
|
110
|
+
onActivate: () => {
|
|
106
111
|
"worklet";
|
|
107
112
|
// Activation (a real drag crossed the threshold). Catch the panel wherever
|
|
108
113
|
// its spring currently is and hand it to the finger with no jump — grabbing
|
|
@@ -111,8 +116,8 @@ export function useDragDismiss(params: DragDismissParams): PanGesture {
|
|
|
111
116
|
panStart.value = offset.value;
|
|
112
117
|
cancelAnimation(offset);
|
|
113
118
|
active.value = true;
|
|
114
|
-
}
|
|
115
|
-
|
|
119
|
+
},
|
|
120
|
+
onUpdate: (e) => {
|
|
116
121
|
"worklet";
|
|
117
122
|
const raw = axis === "x" ? e.translationX : e.translationY;
|
|
118
123
|
// Map screen translation into dismiss-direction travel. Hard-clamp the
|
|
@@ -120,8 +125,8 @@ export function useDragDismiss(params: DragDismissParams): PanGesture {
|
|
|
120
125
|
// TOWARD the edge — never further into the screen than its open position.
|
|
121
126
|
const d = panStart.value + raw * sign;
|
|
122
127
|
offset.value = d > 0 ? d : 0;
|
|
123
|
-
}
|
|
124
|
-
|
|
128
|
+
},
|
|
129
|
+
onDeactivate: (e) => {
|
|
125
130
|
"worklet";
|
|
126
131
|
const velocity = (axis === "x" ? e.velocityX : e.velocityY) * sign;
|
|
127
132
|
settled.value = true;
|
|
@@ -140,15 +145,16 @@ export function useDragDismiss(params: DragDismissParams): PanGesture {
|
|
|
140
145
|
} else {
|
|
141
146
|
offset.value = withSpring(0, { ...config, velocity });
|
|
142
147
|
}
|
|
143
|
-
}
|
|
144
|
-
|
|
148
|
+
},
|
|
149
|
+
onFinalize: () => {
|
|
145
150
|
"worklet";
|
|
146
151
|
// Safety net for an activated drag interrupted/cancelled before a clean
|
|
147
|
-
// `
|
|
152
|
+
// `onDeactivate` (e.g. the OS stole the gesture) — spring back to rest. Never
|
|
148
153
|
// dismisses: only a real release may close the panel.
|
|
149
154
|
if (!active.value || settled.value) return;
|
|
150
155
|
offset.value = withSpring(0, config);
|
|
151
|
-
}
|
|
156
|
+
},
|
|
157
|
+
};
|
|
152
158
|
}, [
|
|
153
159
|
offset,
|
|
154
160
|
panStart,
|
|
@@ -163,4 +169,6 @@ export function useDragDismiss(params: DragDismissParams): PanGesture {
|
|
|
163
169
|
config,
|
|
164
170
|
onDismiss,
|
|
165
171
|
]);
|
|
172
|
+
|
|
173
|
+
return usePanGesture(panConfig);
|
|
166
174
|
}
|
package/src/Modal/modal-base.tsx
CHANGED
|
@@ -8,7 +8,7 @@ import type { CloseButtonProps } from "../CloseButton";
|
|
|
8
8
|
import { type MotionPreset, type MotionPresetName, useMotionPreset } from "../internal/motion";
|
|
9
9
|
import { slotStyles, type SlotStyles } from "../internal/styles";
|
|
10
10
|
import { Overlay, type OverlayProps } from "../Overlay";
|
|
11
|
-
import {
|
|
11
|
+
import { OverlayPortal, useOverlayHost } from "../Portal";
|
|
12
12
|
import { ModalBaseInner } from "./modal-base-inner";
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -302,7 +302,7 @@ export function ModalBase(props: ModalBaseProps) {
|
|
|
302
302
|
// `keepMounted` stays in the tree and toggles `display` — entrance animates but
|
|
303
303
|
// there is no exit (the node never leaves), mirroring `Dialog`/`Popover`.
|
|
304
304
|
if (keepMounted) {
|
|
305
|
-
return <
|
|
305
|
+
return <OverlayPortal hostName={withinPortal ? overlayHost : undefined}>{layer}</OverlayPortal>;
|
|
306
306
|
}
|
|
307
307
|
|
|
308
308
|
// Default: `AnimatePresence` holds the whole layer (scrim + content) in the tree
|
|
@@ -314,9 +314,9 @@ export function ModalBase(props: ModalBaseProps) {
|
|
|
314
314
|
return (
|
|
315
315
|
<AnimatePresence>
|
|
316
316
|
{opened ? (
|
|
317
|
-
<
|
|
317
|
+
<OverlayPortal key="modal-layer" hostName={withinPortal ? overlayHost : undefined}>
|
|
318
318
|
{layer}
|
|
319
|
-
</
|
|
319
|
+
</OverlayPortal>
|
|
320
320
|
) : null}
|
|
321
321
|
</AnimatePresence>
|
|
322
322
|
);
|
package/src/Pill/Pill.tsx
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
|
|
11
11
|
import { Box } from "../Box";
|
|
12
12
|
import { CloseButton, type CloseButtonProps } from "../CloseButton";
|
|
13
|
-
import { type GradientValue, useGradient } from "../internal/gradient";
|
|
13
|
+
import { gradientForVariant, type GradientValue, useGradient } from "../internal/gradient";
|
|
14
14
|
import { renderTextChild } from "../internal/render-text-child";
|
|
15
15
|
import {
|
|
16
16
|
controlFontVariant,
|
|
@@ -230,7 +230,7 @@ const PillComponent = styleable<PillProps>(PillFrame, function Pill(props, ref)
|
|
|
230
230
|
|
|
231
231
|
// Gradient fill (only when `variant="gradient"`): web paints a CSS
|
|
232
232
|
// `backgroundImage`; native renders the `layer` (an SVG fill) behind the label.
|
|
233
|
-
const grad = useGradient(variant
|
|
233
|
+
const grad = useGradient(gradientForVariant(variant, gradient));
|
|
234
234
|
const group = React.useContext(PillGroupContext);
|
|
235
235
|
const resolvedSize: PillSize = size ?? group?.size ?? "sm";
|
|
236
236
|
const isDisabled = disabled ?? group?.disabled ?? false;
|
|
@@ -39,7 +39,7 @@ import { useOverlayChrome } from "../internal/overlay-chrome";
|
|
|
39
39
|
import { shadowVariant } from "../internal/style-props";
|
|
40
40
|
import { type SlotStyles } from "../internal/styles";
|
|
41
41
|
import { type OverlayProps } from "../Overlay";
|
|
42
|
-
import {
|
|
42
|
+
import { OverlayPortal, useOverlayHost } from "../Portal";
|
|
43
43
|
import {
|
|
44
44
|
type OverlayTransitionConfig,
|
|
45
45
|
useOverlayTransition,
|
|
@@ -743,7 +743,7 @@ export const PopoverDropdownView = styleable<PopoverDropdownViewProps>(
|
|
|
743
743
|
const transitionStyle = waitingForPosition ? { ...t.style, opacity: 0 } : t.style;
|
|
744
744
|
|
|
745
745
|
return (
|
|
746
|
-
<
|
|
746
|
+
<OverlayPortal hostName={ctx.withinPortal ? overlayHost : undefined}>
|
|
747
747
|
<Theme name={themeName}>
|
|
748
748
|
{/* Keep the scrim and the dropdown frame as direct siblings (rather
|
|
749
749
|
than hoisting the scrim above `<Theme>`) so their z-indices compare
|
|
@@ -800,7 +800,7 @@ export const PopoverDropdownView = styleable<PopoverDropdownViewProps>(
|
|
|
800
800
|
) : null}
|
|
801
801
|
</PopoverDropdownFrame>
|
|
802
802
|
</Theme>
|
|
803
|
-
</
|
|
803
|
+
</OverlayPortal>
|
|
804
804
|
);
|
|
805
805
|
},
|
|
806
806
|
);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { StyleSheet, View } from "react-native";
|
|
2
|
+
import { StyleSheet, View, type ViewInstance } from "react-native";
|
|
3
3
|
import { PortalHost } from "react-native-teleport";
|
|
4
4
|
|
|
5
5
|
import type { OverlayHostProps } from "./types";
|
|
@@ -17,7 +17,7 @@ type OverlayHostContextValue = {
|
|
|
17
17
|
* the host's window origin. `null` for the root host (it sits at the window
|
|
18
18
|
* origin by construction).
|
|
19
19
|
*/
|
|
20
|
-
frameRef: React.RefObject<
|
|
20
|
+
frameRef: React.RefObject<ViewInstance | null> | null;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
const ROOT_VALUE: OverlayHostContextValue = { name: ROOT_OVERLAY_HOST, depth: 0, frameRef: null };
|
|
@@ -87,7 +87,7 @@ function register(name: string, depth: number): () => void {
|
|
|
87
87
|
export function OverlayHost({ name, children }: OverlayHostProps) {
|
|
88
88
|
const parent = React.useContext(OverlayHostContext);
|
|
89
89
|
const depth = parent.depth + 1;
|
|
90
|
-
const frameRef = React.useRef<
|
|
90
|
+
const frameRef = React.useRef<ViewInstance>(null);
|
|
91
91
|
|
|
92
92
|
const value = React.useMemo<OverlayHostContextValue>(
|
|
93
93
|
() => ({ name, depth, frameRef }),
|
|
@@ -136,6 +136,6 @@ export function useTopmostOverlayHost(): string {
|
|
|
136
136
|
* @internal The scoped host's measurable frame (or `null` under the root host),
|
|
137
137
|
* for the native floating engine's container-origin math.
|
|
138
138
|
*/
|
|
139
|
-
export function useOverlayHostFrame(): React.RefObject<
|
|
139
|
+
export function useOverlayHostFrame(): React.RefObject<ViewInstance | null> | null {
|
|
140
140
|
return React.useContext(OverlayHostContext).frameRef;
|
|
141
141
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Portal } from "react-native-teleport";
|
|
3
|
+
|
|
4
|
+
import { useScreenFocused } from "@knitui/core";
|
|
5
|
+
|
|
6
|
+
export interface OverlayPortalProps {
|
|
7
|
+
/** Host to teleport into (usually `useOverlayHost()`); omit to render inline. */
|
|
8
|
+
hostName?: string;
|
|
9
|
+
children?: React.ReactNode;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The portal the kit's overlays render through: a `Portal` that teleports into
|
|
14
|
+
* `hostName` only while the screen it sits in is focused (`<Provider useScreenFocus>`).
|
|
15
|
+
*
|
|
16
|
+
* On a backgrounded stack screen the screen stays mounted, but the shared host it
|
|
17
|
+
* teleports into does not belong to it, so an open popover would draw over the
|
|
18
|
+
* screen in front. Dropping `hostName` while unfocused keeps the overlay inline in
|
|
19
|
+
* its own (now hidden) screen instead. Teleport re-parents rather than remounts, so
|
|
20
|
+
* the overlay keeps its state and is back, still open, when the screen regains focus.
|
|
21
|
+
* Without `useScreenFocus` this is exactly `<Portal hostName={hostName}>`.
|
|
22
|
+
*/
|
|
23
|
+
export function OverlayPortal({ hostName, children }: OverlayPortalProps) {
|
|
24
|
+
const focused = useScreenFocused();
|
|
25
|
+
return <Portal hostName={focused ? hostName : undefined}>{children}</Portal>;
|
|
26
|
+
}
|
package/src/Portal/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ export {
|
|
|
4
4
|
useOverlayHost,
|
|
5
5
|
useTopmostOverlayHost,
|
|
6
6
|
} from "./OverlayHost";
|
|
7
|
+
export { OverlayPortal, type OverlayPortalProps } from "./OverlayPortal";
|
|
7
8
|
export type { OverlayHostProps, PortalHostProps, PortalProps, PortalProviderProps } from "./types";
|
|
8
9
|
/**
|
|
9
10
|
* Portal system — a thin re-export of `react-native-teleport`.
|
|
@@ -24,6 +25,9 @@ export type { OverlayHostProps, PortalHostProps, PortalProps, PortalProviderProp
|
|
|
24
25
|
* kit's overlays inside it teleport into THAT host rather than `"root"` (which
|
|
25
26
|
* lives in the window underneath the modal). They read the host through
|
|
26
27
|
* `useOverlayHost()`; `useTopmostOverlayHost()` serves app-global layers.
|
|
28
|
+
* - The kit's overlays render through `<OverlayPortal>`, which stops teleporting
|
|
29
|
+
* while its screen is unfocused (`<Provider useScreenFocus>`), so a backgrounded
|
|
30
|
+
* stack screen's popovers don't draw over the screen in front of it.
|
|
27
31
|
*
|
|
28
32
|
* @see https://kirillzyusko.github.io/react-native-teleport
|
|
29
33
|
*/
|