@oxy.so/bloom 4.24.1 → 4.25.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/docs/adoption-matrix.mdx +6 -6
- package/docs/ai-chat.mdx +1 -1
- package/docs/context-menu.mdx +2 -0
- package/lib/commonjs/ai-chat/AiChatContainer.js +60 -7
- package/lib/commonjs/ai-chat/AiChatContainer.js.map +1 -1
- package/lib/commonjs/ai-chat/use-panel-interaction.js +6 -1
- package/lib/commonjs/ai-chat/use-panel-interaction.js.map +1 -1
- package/lib/commonjs/bottom-sheet/BottomSheetBase.js +6 -2
- package/lib/commonjs/bottom-sheet/BottomSheetBase.js.map +1 -1
- package/lib/commonjs/bottom-sheet/context.js +29 -0
- package/lib/commonjs/bottom-sheet/context.js.map +1 -0
- package/lib/commonjs/composer-panel/ComposerPanelBase.js +32 -11
- package/lib/commonjs/composer-panel/ComposerPanelBase.js.map +1 -1
- package/lib/commonjs/composer-panel/ComposerPopover.js +13 -5
- package/lib/commonjs/composer-panel/ComposerPopover.js.map +1 -1
- package/lib/commonjs/composer-panel/ModelPickerBase.js +13 -2
- package/lib/commonjs/composer-panel/ModelPickerBase.js.map +1 -1
- package/lib/commonjs/context-menu/ContextMenu.js +10 -2
- package/lib/commonjs/context-menu/ContextMenu.js.map +1 -1
- package/lib/commonjs/dialog/DialogBottomSheet.js +27 -6
- package/lib/commonjs/dialog/DialogBottomSheet.js.map +1 -1
- package/lib/commonjs/floating/LongPressArea.js +107 -0
- package/lib/commonjs/floating/LongPressArea.js.map +1 -0
- package/lib/commonjs/settings-modal/SettingsModal.js +8 -1
- package/lib/commonjs/settings-modal/SettingsModal.js.map +1 -1
- package/lib/commonjs/settings-modal/use-keyboard-reveal.js +76 -0
- package/lib/commonjs/settings-modal/use-keyboard-reveal.js.map +1 -0
- package/lib/commonjs/sidebar/SidebarItem.js +5 -1
- package/lib/commonjs/sidebar/SidebarItem.js.map +1 -1
- package/lib/module/ai-chat/AiChatContainer.js +60 -7
- package/lib/module/ai-chat/AiChatContainer.js.map +1 -1
- package/lib/module/ai-chat/use-panel-interaction.js +7 -2
- package/lib/module/ai-chat/use-panel-interaction.js.map +1 -1
- package/lib/module/bottom-sheet/BottomSheetBase.js +6 -2
- package/lib/module/bottom-sheet/BottomSheetBase.js.map +1 -1
- package/lib/module/bottom-sheet/context.js +25 -0
- package/lib/module/bottom-sheet/context.js.map +1 -0
- package/lib/module/composer-panel/ComposerPanelBase.js +33 -12
- package/lib/module/composer-panel/ComposerPanelBase.js.map +1 -1
- package/lib/module/composer-panel/ComposerPopover.js +13 -5
- package/lib/module/composer-panel/ComposerPopover.js.map +1 -1
- package/lib/module/composer-panel/ModelPickerBase.js +13 -2
- package/lib/module/composer-panel/ModelPickerBase.js.map +1 -1
- package/lib/module/context-menu/ContextMenu.js +10 -2
- package/lib/module/context-menu/ContextMenu.js.map +1 -1
- package/lib/module/dialog/DialogBottomSheet.js +25 -4
- package/lib/module/dialog/DialogBottomSheet.js.map +1 -1
- package/lib/module/floating/LongPressArea.js +100 -0
- package/lib/module/floating/LongPressArea.js.map +1 -0
- package/lib/module/settings-modal/SettingsModal.js +8 -1
- package/lib/module/settings-modal/SettingsModal.js.map +1 -1
- package/lib/module/settings-modal/use-keyboard-reveal.js +72 -0
- package/lib/module/settings-modal/use-keyboard-reveal.js.map +1 -0
- package/lib/module/sidebar/SidebarItem.js +5 -1
- package/lib/module/sidebar/SidebarItem.js.map +1 -1
- package/lib/typescript/commonjs/ai-chat/use-panel-interaction.d.ts +5 -1
- package/lib/typescript/commonjs/ai-chat/use-panel-interaction.d.ts.map +1 -1
- package/lib/typescript/commonjs/bottom-sheet/BottomSheetBase.d.ts.map +1 -1
- package/lib/typescript/commonjs/bottom-sheet/context.d.ts +5 -0
- package/lib/typescript/commonjs/bottom-sheet/context.d.ts.map +1 -0
- package/lib/typescript/commonjs/composer-panel/ComposerPanelBase.d.ts.map +1 -1
- package/lib/typescript/commonjs/composer-panel/ComposerPopover.d.ts.map +1 -1
- package/lib/typescript/commonjs/composer-panel/ModelPickerBase.d.ts.map +1 -1
- package/lib/typescript/commonjs/context-menu/ContextMenu.d.ts.map +1 -1
- package/lib/typescript/commonjs/dialog/DialogBottomSheet.d.ts.map +1 -1
- package/lib/typescript/commonjs/floating/LongPressArea.d.ts +34 -0
- package/lib/typescript/commonjs/floating/LongPressArea.d.ts.map +1 -0
- package/lib/typescript/commonjs/settings-modal/SettingsModal.d.ts.map +1 -1
- package/lib/typescript/commonjs/settings-modal/use-keyboard-reveal.d.ts +21 -0
- package/lib/typescript/commonjs/settings-modal/use-keyboard-reveal.d.ts.map +1 -0
- package/lib/typescript/commonjs/sidebar/SidebarItem.d.ts.map +1 -1
- package/lib/typescript/module/ai-chat/use-panel-interaction.d.ts +5 -1
- package/lib/typescript/module/ai-chat/use-panel-interaction.d.ts.map +1 -1
- package/lib/typescript/module/bottom-sheet/BottomSheetBase.d.ts.map +1 -1
- package/lib/typescript/module/bottom-sheet/context.d.ts +5 -0
- package/lib/typescript/module/bottom-sheet/context.d.ts.map +1 -0
- package/lib/typescript/module/composer-panel/ComposerPanelBase.d.ts.map +1 -1
- package/lib/typescript/module/composer-panel/ComposerPopover.d.ts.map +1 -1
- package/lib/typescript/module/composer-panel/ModelPickerBase.d.ts.map +1 -1
- package/lib/typescript/module/context-menu/ContextMenu.d.ts.map +1 -1
- package/lib/typescript/module/dialog/DialogBottomSheet.d.ts.map +1 -1
- package/lib/typescript/module/floating/LongPressArea.d.ts +34 -0
- package/lib/typescript/module/floating/LongPressArea.d.ts.map +1 -0
- package/lib/typescript/module/settings-modal/SettingsModal.d.ts.map +1 -1
- package/lib/typescript/module/settings-modal/use-keyboard-reveal.d.ts +21 -0
- package/lib/typescript/module/settings-modal/use-keyboard-reveal.d.ts.map +1 -0
- package/lib/typescript/module/sidebar/SidebarItem.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/ai-chat/AiChatContainer.tsx +44 -5
- package/src/ai-chat/use-panel-interaction.ts +7 -2
- package/src/bottom-sheet/BottomSheetBase.tsx +4 -1
- package/src/bottom-sheet/context.ts +23 -0
- package/src/composer-panel/ComposerPanelBase.tsx +38 -13
- package/src/composer-panel/ComposerPopover.tsx +13 -5
- package/src/composer-panel/ModelPickerBase.tsx +11 -3
- package/src/context-menu/ContextMenu.tsx +7 -2
- package/src/dialog/DialogBottomSheet.tsx +16 -4
- package/src/floating/LongPressArea.tsx +114 -0
- package/src/settings-modal/SettingsModal.tsx +9 -2
- package/src/settings-modal/use-keyboard-reveal.ts +62 -0
- package/src/sidebar/SidebarItem.tsx +5 -1
|
@@ -537,6 +537,16 @@ const ScrollThread = forwardRef<AiChatThreadHandle, AiChatThreadProps>(function
|
|
|
537
537
|
const contentHeight = useRef(0);
|
|
538
538
|
const offset = useRef(0);
|
|
539
539
|
const viewport = useRef(0);
|
|
540
|
+
/**
|
|
541
|
+
* A scroll to the end is on its way and has not landed. `offset` is only
|
|
542
|
+
* what the LAST scroll event said, so two growths between a `scrollToEnd`
|
|
543
|
+
* and the event it causes measured the reader against the old offset, read
|
|
544
|
+
* them as far from the bottom and dropped the follow for good (Android,
|
|
545
|
+
* streaming). While this holds, growth follows whatever `offset` says; it
|
|
546
|
+
* clears when a scroll event lands at the end or moves UP — only a reader
|
|
547
|
+
* (or a host) scrolls up, the follow never does.
|
|
548
|
+
*/
|
|
549
|
+
const following = useRef(false);
|
|
540
550
|
/** An `onStartReached` is out and its page has not landed yet. */
|
|
541
551
|
const pageOut = useRef(false);
|
|
542
552
|
/** The reader has left the top zone, so the next approach may fire again. */
|
|
@@ -560,7 +570,10 @@ const ScrollThread = forwardRef<AiChatThreadHandle, AiChatThreadProps>(function
|
|
|
560
570
|
useImperativeHandle(
|
|
561
571
|
ref,
|
|
562
572
|
(): AiChatThreadHandle => ({
|
|
563
|
-
scrollToEnd: (options) =>
|
|
573
|
+
scrollToEnd: (options) => {
|
|
574
|
+
following.current = true;
|
|
575
|
+
scrollRef.current?.scrollToEnd({ animated: options?.animated ?? true });
|
|
576
|
+
},
|
|
564
577
|
scrollToOffset: ({ offset: y, animated = false }) => scrollRef.current?.scrollTo({ y, animated }),
|
|
565
578
|
getScrollView: () => scrollRef.current,
|
|
566
579
|
}),
|
|
@@ -577,9 +590,13 @@ const ScrollThread = forwardRef<AiChatThreadHandle, AiChatThreadProps>(function
|
|
|
577
590
|
const handleScroll = useCallback(
|
|
578
591
|
(event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
|
579
592
|
const { contentOffset, layoutMeasurement, contentSize } = event.nativeEvent;
|
|
593
|
+
const movedUp = contentOffset.y < offset.current - 0.5;
|
|
580
594
|
offset.current = contentOffset.y;
|
|
581
595
|
viewport.current = layoutMeasurement.height;
|
|
582
596
|
if (contentSize?.height) contentHeight.current = contentSize.height;
|
|
597
|
+
if (movedUp || contentHeight.current - contentOffset.y - layoutMeasurement.height <= EDGE_THRESHOLD) {
|
|
598
|
+
following.current = false;
|
|
599
|
+
}
|
|
583
600
|
report();
|
|
584
601
|
if (onStartReached) {
|
|
585
602
|
if (contentOffset.y <= onStartReachedThreshold) {
|
|
@@ -624,7 +641,8 @@ const ScrollThread = forwardRef<AiChatThreadHandle, AiChatThreadProps>(function
|
|
|
624
641
|
const chromeShift = shift.top + shift.bottom;
|
|
625
642
|
if (chromeShift !== 0 && Math.abs(height - previous - chromeShift) < 1) {
|
|
626
643
|
const fromBottom = previous - offset.current - viewport.current;
|
|
627
|
-
if (fromBottom <= EDGE_THRESHOLD) {
|
|
644
|
+
if (following.current || fromBottom <= EDGE_THRESHOLD) {
|
|
645
|
+
following.current = true;
|
|
628
646
|
scrollRef.current?.scrollToEnd({ animated: false });
|
|
629
647
|
} else if (offset.current > 0 && shift.top !== 0) {
|
|
630
648
|
scrollRef.current?.scrollTo({ y: offset.current + shift.top, animated: false });
|
|
@@ -642,15 +660,23 @@ const ScrollThread = forwardRef<AiChatThreadHandle, AiChatThreadProps>(function
|
|
|
642
660
|
pageOut.current = false;
|
|
643
661
|
|
|
644
662
|
if (!autoFollow) return;
|
|
645
|
-
if (followThreshold !== undefined) {
|
|
663
|
+
if (followThreshold !== undefined && !following.current) {
|
|
646
664
|
// Measured against the height BEFORE the growth: was the reader near
|
|
647
665
|
// the bottom when this arrived?
|
|
648
666
|
const fromBottom = previous - offset.current - viewport.current;
|
|
649
|
-
if (fromBottom > followThreshold)
|
|
667
|
+
if (fromBottom > followThreshold) {
|
|
668
|
+
// Staying put moves no scroll, so a host tracking the distance to
|
|
669
|
+
// the end from `onScroll` (a jump-to-latest button) would not hear
|
|
670
|
+
// that the end moved away. Tell it, as `DocumentThread` does on every
|
|
671
|
+
// growth.
|
|
672
|
+
onScroll?.(syntheticScroll(offset.current, viewport.current, height));
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
650
675
|
}
|
|
676
|
+
following.current = true;
|
|
651
677
|
scrollRef.current?.scrollToEnd({ animated: followAnimated });
|
|
652
678
|
},
|
|
653
|
-
[autoFollow, followAnimated, followThreshold, maintainStartPosition],
|
|
679
|
+
[autoFollow, followAnimated, followThreshold, maintainStartPosition, onScroll],
|
|
654
680
|
);
|
|
655
681
|
|
|
656
682
|
return (
|
|
@@ -682,6 +708,19 @@ const ScrollThread = forwardRef<AiChatThreadHandle, AiChatThreadProps>(function
|
|
|
682
708
|
);
|
|
683
709
|
});
|
|
684
710
|
|
|
711
|
+
/** A scroll event for a position that did not change while the content did. */
|
|
712
|
+
function syntheticScroll(offset: number, viewport: number, content: number): NativeSyntheticEvent<NativeScrollEvent> {
|
|
713
|
+
return {
|
|
714
|
+
nativeEvent: {
|
|
715
|
+
contentOffset: { x: 0, y: offset },
|
|
716
|
+
layoutMeasurement: { width: 0, height: viewport },
|
|
717
|
+
contentSize: { width: 0, height: content },
|
|
718
|
+
contentInset: { top: 0, left: 0, bottom: 0, right: 0 },
|
|
719
|
+
zoomScale: 1,
|
|
720
|
+
},
|
|
721
|
+
} as NativeSyntheticEvent<NativeScrollEvent>;
|
|
722
|
+
}
|
|
723
|
+
|
|
685
724
|
/** The window's scroll position and extent, px. */
|
|
686
725
|
function readWindow() {
|
|
687
726
|
const page = document.scrollingElement ?? document.documentElement;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEffect, useRef } from 'react';
|
|
2
|
-
import { BackHandler, Platform, type View } from 'react-native';
|
|
2
|
+
import { BackHandler, Keyboard, Platform, type View } from 'react-native';
|
|
3
3
|
import { useAccessibilityFocus } from '../hooks/use-accessibility-focus';
|
|
4
4
|
import { listenForEscape, tabbablesWithin, wrapTab } from '../overlay/modal-keyboard';
|
|
5
5
|
import { hasActiveOverlays } from '../overlay/stack';
|
|
@@ -10,7 +10,11 @@ import { hasActiveOverlays } from '../overlay/stack';
|
|
|
10
10
|
*
|
|
11
11
|
* open Escape (web) and back (Android) close it
|
|
12
12
|
* modal it covers the workspace: focus moves in on open, Tab is kept
|
|
13
|
-
* inside, and focus goes back to the opener on close
|
|
13
|
+
* inside, and focus goes back to the opener on close (web); on
|
|
14
|
+
* native the keyboard goes down as it opens — a composer that had
|
|
15
|
+
* the focus (say, regained after a sheet closed) otherwise kept the
|
|
16
|
+
* keyboard up under the drawer (Android 16). Nothing refocuses the
|
|
17
|
+
* composer on close.
|
|
14
18
|
*
|
|
15
19
|
* Any portaled overlay above (a dialog, a menu) takes all of it first.
|
|
16
20
|
*/
|
|
@@ -22,6 +26,7 @@ export function usePanelInteraction(open: boolean, modal: boolean, close: () =>
|
|
|
22
26
|
useEffect(() => {
|
|
23
27
|
if (!open) return;
|
|
24
28
|
if (Platform.OS !== 'web') {
|
|
29
|
+
if (modal) Keyboard?.dismiss?.();
|
|
25
30
|
const subscription = BackHandler?.addEventListener('hardwareBackPress', () => {
|
|
26
31
|
if (hasActiveOverlays()) return false;
|
|
27
32
|
closeRef.current();
|
|
@@ -34,6 +34,7 @@ import { EDGE_GAP, windowEdgeGap } from '../layout/edge';
|
|
|
34
34
|
import { Backdrop, BACKDROP_DIM_OPACITY } from '../overlay';
|
|
35
35
|
import { ModalKeyboard } from '../overlay/ModalKeyboard';
|
|
36
36
|
import { useTheme } from '../theme/use-theme';
|
|
37
|
+
import { SheetKeyboardProvider } from './context';
|
|
37
38
|
import type { BottomSheetRef, BottomSheetProps, BottomSheetShellProps, BottomSheetBaseProps } from './types';
|
|
38
39
|
|
|
39
40
|
/** Hook that returns current screen dimensions and updates on rotation/resize. */
|
|
@@ -659,7 +660,9 @@ export const BottomSheetBase = forwardRef((props: BottomSheetBaseProps, ref: Rea
|
|
|
659
660
|
// (`layout/screen-scope.tsx`).
|
|
660
661
|
const surfaceChildren = (
|
|
661
662
|
<SurfaceLevelProvider level={0} fill={colors.background}>
|
|
662
|
-
<
|
|
663
|
+
<SheetKeyboardProvider value={keyboardHeight}>
|
|
664
|
+
<ScreenScope>{children}</ScreenScope>
|
|
665
|
+
</SheetKeyboardProvider>
|
|
663
666
|
</SurfaceLevelProvider>
|
|
664
667
|
);
|
|
665
668
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
import { useSharedValue, type SharedValue } from 'react-native-reanimated';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The open keyboard's height under a `BottomSheet`, for content that owns a
|
|
6
|
+
* bottom inset of its own. Native only: the sheet's shell writes it, web leaves
|
|
7
|
+
* it at 0 (the browser owns keyboard layout).
|
|
8
|
+
*
|
|
9
|
+
* `DialogBottomSheet` reads it to fold its safe-area spacer while the keyboard
|
|
10
|
+
* is up: the keyboard covers the gesture bar the spacer clears, so keeping it
|
|
11
|
+
* floated the sheet's buttons a bar's height above the keyboard (Android 16).
|
|
12
|
+
*
|
|
13
|
+
* Internal: not in the family barrel.
|
|
14
|
+
*/
|
|
15
|
+
const SheetKeyboardContext = createContext<SharedValue<number> | null>(null);
|
|
16
|
+
|
|
17
|
+
export const SheetKeyboardProvider = SheetKeyboardContext.Provider;
|
|
18
|
+
|
|
19
|
+
/** The sheet's keyboard height, or a constant 0 outside a sheet. */
|
|
20
|
+
export function useSheetKeyboardHeight(): SharedValue<number> {
|
|
21
|
+
const none = useSharedValue(0);
|
|
22
|
+
return useContext(SheetKeyboardContext) ?? none;
|
|
23
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
2
|
import {
|
|
3
|
+
Text as RNText,
|
|
3
4
|
TextInput,
|
|
4
5
|
View,
|
|
5
6
|
type LayoutChangeEvent,
|
|
6
7
|
type NativeSyntheticEvent,
|
|
7
|
-
type TextInputContentSizeChangeEventData,
|
|
8
8
|
type TextInputKeyPressEventData,
|
|
9
9
|
} from 'react-native';
|
|
10
10
|
import Animated, {
|
|
@@ -177,7 +177,11 @@ export function ComposerPanelBase({
|
|
|
177
177
|
|
|
178
178
|
// The prompt grows with its text, one 20px line at a time, up to 200 before it
|
|
179
179
|
// scrolls. Web measures the textarea, collapsing it only when the draft may
|
|
180
|
-
// have got shorter (`useTextareaAutosize`)
|
|
180
|
+
// have got shorter (`useTextareaAutosize`). Native lays the same text out in
|
|
181
|
+
// an invisible twin and takes ITS height: the field's own
|
|
182
|
+
// `onContentSizeChange` does not fire for a value set from outside until the
|
|
183
|
+
// field is focused (Android 16), so a question loaded to edit showed one line
|
|
184
|
+
// and a cancelled edit kept four.
|
|
181
185
|
const [height, setHeight] = useState(PROMPT_LINE);
|
|
182
186
|
useTextareaAutosize(fieldRef, text, {
|
|
183
187
|
enabled: IS_WEB,
|
|
@@ -185,13 +189,9 @@ export function ComposerPanelBase({
|
|
|
185
189
|
minHeight: PROMPT_LINE,
|
|
186
190
|
onMeasure: (content) => setHeight(Math.min(PROMPT_MAX_HEIGHT, Math.max(PROMPT_LINE, content))),
|
|
187
191
|
});
|
|
188
|
-
const
|
|
189
|
-
(event
|
|
190
|
-
|
|
191
|
-
setHeight(Math.min(PROMPT_MAX_HEIGHT, Math.max(PROMPT_LINE, event.nativeEvent.contentSize.height)));
|
|
192
|
-
},
|
|
193
|
-
[],
|
|
194
|
-
);
|
|
192
|
+
const onTwinLayout = useCallback((event: LayoutChangeEvent) => {
|
|
193
|
+
setHeight(Math.min(PROMPT_MAX_HEIGHT, Math.max(PROMPT_LINE, event.nativeEvent.layout.height)));
|
|
194
|
+
}, []);
|
|
195
195
|
|
|
196
196
|
const submit = useCallback(() => {
|
|
197
197
|
if (disabled || busy) return;
|
|
@@ -253,7 +253,6 @@ export function ComposerPanelBase({
|
|
|
253
253
|
value={text}
|
|
254
254
|
onChangeText={setText}
|
|
255
255
|
onKeyPress={onKeyPress}
|
|
256
|
-
onContentSizeChange={onContentSizeChange}
|
|
257
256
|
placeholder={placeholder}
|
|
258
257
|
placeholderTextColor={palette.textTertiary}
|
|
259
258
|
selectionColor={palette.accent500}
|
|
@@ -273,10 +272,36 @@ export function ComposerPanelBase({
|
|
|
273
272
|
...(IS_WEB ? { caretColor: palette.accent500 } : null),
|
|
274
273
|
}}
|
|
275
274
|
/>
|
|
275
|
+
{IS_WEB ? null : (
|
|
276
|
+
<RNText
|
|
277
|
+
aria-hidden
|
|
278
|
+
accessibilityElementsHidden
|
|
279
|
+
importantForAccessibility="no-hide-descendants"
|
|
280
|
+
pointerEvents="none"
|
|
281
|
+
testID={testID ? `${testID}-input-twin` : undefined}
|
|
282
|
+
onLayout={onTwinLayout}
|
|
283
|
+
style={{
|
|
284
|
+
position: 'absolute',
|
|
285
|
+
top: 0,
|
|
286
|
+
left: 6,
|
|
287
|
+
right: 6,
|
|
288
|
+
opacity: 0,
|
|
289
|
+
...TYPE_SCALE['body-regular'],
|
|
290
|
+
fontFamily: 'Inter',
|
|
291
|
+
}}>
|
|
292
|
+
{/* A trailing newline is a line of its own in the field; a
|
|
293
|
+
Text drops it unless something follows. */}
|
|
294
|
+
{text.endsWith('\n') || text === '' ? `${text} ` : text}
|
|
295
|
+
</RNText>
|
|
296
|
+
)}
|
|
276
297
|
</View>
|
|
277
298
|
|
|
278
299
|
<View style={{ flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', gap: 8 }}>
|
|
279
|
-
|
|
300
|
+
{/* The actions never give way: + and the permission chip on the
|
|
301
|
+
left, voice and send on the right keep their size, and the
|
|
302
|
+
model chip between them is what truncates (a long model name
|
|
303
|
+
once covered + and pushed voice off the card). */}
|
|
304
|
+
<View style={{ flexShrink: 0, flexDirection: 'row', alignItems: 'center', gap: 8 }}>
|
|
280
305
|
{addMenu.length > 0 ? (
|
|
281
306
|
<AddMenu
|
|
282
307
|
palette={palette}
|
|
@@ -299,7 +324,7 @@ export function ComposerPanelBase({
|
|
|
299
324
|
/>
|
|
300
325
|
) : null}
|
|
301
326
|
</View>
|
|
302
|
-
<View style={{
|
|
327
|
+
<View style={{ minWidth: 0, flexShrink: 1, flexDirection: 'row', alignItems: 'center', justifyContent: 'flex-end', gap: 16 }}>
|
|
303
328
|
{providers && providers.length > 0 ? (
|
|
304
329
|
<ModelPickerBase
|
|
305
330
|
providers={providers}
|
|
@@ -314,7 +339,7 @@ export function ComposerPanelBase({
|
|
|
314
339
|
testID={testID ? `${testID}-model` : undefined}
|
|
315
340
|
/>
|
|
316
341
|
) : null}
|
|
317
|
-
<View style={{ flexDirection: 'row', alignItems: 'center', gap: 8 }}>
|
|
342
|
+
<View style={{ flexShrink: 0, flexDirection: 'row', alignItems: 'center', gap: 8 }}>
|
|
318
343
|
<MicButton
|
|
319
344
|
listening={isListening}
|
|
320
345
|
onToggle={() => setListening(!isListening)}
|
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
* sheet is not something `BottomSheet` stacks. So each panel is a transparent
|
|
8
8
|
* `Modal` holding a dismiss layer and the panel, placed against the trigger's
|
|
9
9
|
* `measureInWindow` box: on the requested side when it fits, flipped when it
|
|
10
|
-
* does not, clamped 8px inside the window.
|
|
10
|
+
* does not, clamped 8px inside the window's SAFE area. The Modal draws edge to
|
|
11
|
+
* edge, so a clamp to the bare window put the effort panel under Android's
|
|
12
|
+
* gesture bar (Pixel 8a, Android 16). Nested `Modal`s stack on both
|
|
11
13
|
* platforms, so the effort panel opens above the picker.
|
|
12
14
|
*
|
|
13
15
|
* Motion is the popover entry without the blur (no filter on native):
|
|
@@ -30,6 +32,7 @@ import Animated, {
|
|
|
30
32
|
useSharedValue,
|
|
31
33
|
withTiming,
|
|
32
34
|
} from 'react-native-reanimated';
|
|
35
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
33
36
|
|
|
34
37
|
import { TRANSITION_MS } from './shared';
|
|
35
38
|
import type { ComposerPopoverProps } from './types';
|
|
@@ -56,6 +59,7 @@ export function ComposerPopover({
|
|
|
56
59
|
children,
|
|
57
60
|
}: ComposerPopoverProps) {
|
|
58
61
|
const window = useWindowDimensions();
|
|
62
|
+
const insets = useSafeAreaInsets();
|
|
59
63
|
const reducedMotion = useReducedMotion();
|
|
60
64
|
const [mounted, setMounted] = useState(open);
|
|
61
65
|
const [anchor, setAnchor] = useState<Box | null>(null);
|
|
@@ -112,14 +116,18 @@ export function ComposerPopover({
|
|
|
112
116
|
let left = GUTTER;
|
|
113
117
|
let top = GUTTER;
|
|
114
118
|
if (anchor && size) {
|
|
115
|
-
|
|
119
|
+
const minLeft = insets.left + GUTTER;
|
|
120
|
+
const maxRight = window.width - insets.right - GUTTER;
|
|
121
|
+
const minTop = insets.top + GUTTER;
|
|
122
|
+
const maxBottom = window.height - insets.bottom - GUTTER;
|
|
123
|
+
left = Math.max(minLeft, Math.min(anchor.x, maxRight - size.width));
|
|
116
124
|
const above = anchor.y - sideOffset - size.height;
|
|
117
125
|
const below = anchor.y + anchor.height + sideOffset;
|
|
118
|
-
const fitsAbove = above >=
|
|
119
|
-
const fitsBelow = below + size.height <=
|
|
126
|
+
const fitsAbove = above >= minTop;
|
|
127
|
+
const fitsBelow = below + size.height <= maxBottom;
|
|
120
128
|
const preferAbove = side === 'top' ? fitsAbove || !fitsBelow : !fitsBelow && fitsAbove;
|
|
121
129
|
top = preferAbove ? above : below;
|
|
122
|
-
top = Math.
|
|
130
|
+
top = Math.max(minTop, Math.min(top, maxBottom - size.height));
|
|
123
131
|
}
|
|
124
132
|
|
|
125
133
|
return (
|
|
@@ -48,6 +48,8 @@ const RAIL_PADDING = 3;
|
|
|
48
48
|
const MARK_HEIGHT = 30;
|
|
49
49
|
const MARK_GAP = 6;
|
|
50
50
|
const ROW_HEIGHT = 36;
|
|
51
|
+
/** The model chip's widest: past this a name truncates even with room to spare. */
|
|
52
|
+
const MODEL_TRIGGER_MAX_WIDTH = 240;
|
|
51
53
|
|
|
52
54
|
const DEFAULT_LABELS: Required<ModelPickerLabels> = {
|
|
53
55
|
models: 'Models',
|
|
@@ -546,8 +548,14 @@ export function ModelPickerBase({
|
|
|
546
548
|
const rows: Match[] = results ?? (activeProvider ? activeProvider.models.map((model) => ({ provider: activeProvider, model })) : []);
|
|
547
549
|
|
|
548
550
|
const triggerStyle: WebCssStyle = {
|
|
549
|
-
|
|
550
|
-
|
|
551
|
+
// At least 32, never exactly: at the largest system font the name is taller
|
|
552
|
+
// than 32 and a fixed height clipped it. It shrinks (with an ellipsis) to
|
|
553
|
+
// leave the composer's own buttons their room, and stops at a width that
|
|
554
|
+
// still reads as a chip.
|
|
555
|
+
minHeight: 32,
|
|
556
|
+
minWidth: 0,
|
|
557
|
+
maxWidth: MODEL_TRIGGER_MAX_WIDTH,
|
|
558
|
+
flexShrink: 1,
|
|
551
559
|
flexDirection: 'row',
|
|
552
560
|
alignItems: 'center',
|
|
553
561
|
justifyContent: 'center',
|
|
@@ -590,7 +598,7 @@ export function ModelPickerBase({
|
|
|
590
598
|
onHoverIn={() => setHovered(true)}
|
|
591
599
|
onHoverOut={() => setHovered(false)}
|
|
592
600
|
style={[triggerStyle, style]}>
|
|
593
|
-
<Text variant="body-medium" numberOfLines={1} style={{ paddingLeft: 2, paddingRight: 2, color: palette.textSecondary }}>
|
|
601
|
+
<Text variant="body-medium" numberOfLines={1} ellipsizeMode="tail" style={{ flexShrink: 1, minWidth: 0, paddingLeft: 2, paddingRight: 2, color: palette.textSecondary }}>
|
|
594
602
|
{selected?.model.name ?? ''}
|
|
595
603
|
</Text>
|
|
596
604
|
<TurningChevron degrees={open ? 180 : 0} color={palette.iconSecondary} />
|
|
@@ -14,6 +14,7 @@ import { MENU_TRIGGER_POPUP } from '../floating/constants';
|
|
|
14
14
|
import { MenuSurfaceProvider, type MenuSurfaceContextValue } from '../floating/context';
|
|
15
15
|
import { createMenuRows } from '../floating/menu-rows';
|
|
16
16
|
import { createInlineMenuSub } from '../floating/menu-sub-inline';
|
|
17
|
+
import { LongPressArea } from '../floating/LongPressArea';
|
|
17
18
|
import { TriggerSlot } from '../floating/TriggerSlot';
|
|
18
19
|
import { useSheetOpenBridge } from '../floating/use-sheet-open-bridge';
|
|
19
20
|
import { ContextMenuProvider, useContextMenu } from './context';
|
|
@@ -57,9 +58,13 @@ export function ContextMenuTrigger({
|
|
|
57
58
|
}: ContextMenuTriggerProps) {
|
|
58
59
|
const menu = useContextMenu();
|
|
59
60
|
|
|
61
|
+
// Without `asChild` the trigger is Bloom's own, and it is a `LongPressArea`
|
|
62
|
+
// rather than TriggerSlot's `Pressable`: a Pressable holds the touch
|
|
63
|
+
// responder, which on Android keeps a horizontal ScrollView inside the
|
|
64
|
+
// trigger (a code block in a chat turn) from ever scrolling.
|
|
60
65
|
return (
|
|
61
66
|
<TriggerSlot
|
|
62
|
-
asChild
|
|
67
|
+
asChild
|
|
63
68
|
className={className}
|
|
64
69
|
style={style}
|
|
65
70
|
testID={testID}
|
|
@@ -76,7 +81,7 @@ export function ContextMenuTrigger({
|
|
|
76
81
|
'aria-haspopup': MENU_TRIGGER_POPUP,
|
|
77
82
|
'aria-expanded': menu.open,
|
|
78
83
|
}}>
|
|
79
|
-
{children}
|
|
84
|
+
{asChild ? children : <LongPressArea>{children}</LongPressArea>}
|
|
80
85
|
</TriggerSlot>
|
|
81
86
|
);
|
|
82
87
|
}
|
|
@@ -12,10 +12,11 @@ import {
|
|
|
12
12
|
type StyleProp,
|
|
13
13
|
type ViewStyle,
|
|
14
14
|
} from 'react-native';
|
|
15
|
-
import { type AnimatedStyle } from 'react-native-reanimated';
|
|
15
|
+
import Animated, { useAnimatedStyle, type AnimatedStyle } from 'react-native-reanimated';
|
|
16
16
|
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
17
17
|
|
|
18
18
|
import { BottomSheet, type BottomSheetRef } from '../bottom-sheet';
|
|
19
|
+
import { useSheetKeyboardHeight } from '../bottom-sheet/context';
|
|
19
20
|
import { useTheme } from '../theme/use-theme';
|
|
20
21
|
import { StyledView } from '../styles/styled-primitives';
|
|
21
22
|
import { Context } from './context';
|
|
@@ -345,9 +346,7 @@ export function DialogBottomSheet({
|
|
|
345
346
|
rather than a padding: the content box keeps the caller's
|
|
346
347
|
`padding`/`contentPadding` untouched on both platforms, and the
|
|
347
348
|
morph layer above still measures the content alone. */}
|
|
348
|
-
{bottomInset > 0 ?
|
|
349
|
-
<View testID={SAFE_AREA_SPACER_TESTID} style={{ height: bottomInset }} />
|
|
350
|
-
) : null}
|
|
349
|
+
{bottomInset > 0 ? <SafeAreaSpacer testID={SAFE_AREA_SPACER_TESTID} inset={bottomInset} /> : null}
|
|
351
350
|
</StyledView>
|
|
352
351
|
</Context.Provider>
|
|
353
352
|
</BottomSheet>
|
|
@@ -357,6 +356,19 @@ export function DialogBottomSheet({
|
|
|
357
356
|
/** Test handle for the bottom safe-area spacer. */
|
|
358
357
|
const SAFE_AREA_SPACER_TESTID = 'dialog-sheet-safe-area';
|
|
359
358
|
|
|
359
|
+
/**
|
|
360
|
+
* The gesture bar's height under the content — folded while the keyboard is
|
|
361
|
+
* up, because the keyboard covers the bar: the sheet already rides on top of
|
|
362
|
+
* the keyboard, and a spacer left standing floated its buttons a bar's height
|
|
363
|
+
* above it (Pixel 8a, Android 16). A child of the sheet, so it reads the
|
|
364
|
+
* sheet's own keyboard value.
|
|
365
|
+
*/
|
|
366
|
+
function SafeAreaSpacer({ inset, testID }: { inset: number; testID: string }) {
|
|
367
|
+
const keyboard = useSheetKeyboardHeight();
|
|
368
|
+
const style = useAnimatedStyle(() => ({ height: keyboard.value > 0 ? 0 : inset }), [keyboard, inset]);
|
|
369
|
+
return <Animated.View testID={testID} style={style} />;
|
|
370
|
+
}
|
|
371
|
+
|
|
360
372
|
/** Passes a bounded height down to a `scrollable={false}` body. */
|
|
361
373
|
const FILL_BOUNDED = { flex: 1, minHeight: 0 } as const;
|
|
362
374
|
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A long-press target that never becomes the touch RESPONDER — native only,
|
|
3
|
+
* the trigger `ContextMenuTrigger` renders around content it does not own.
|
|
4
|
+
*
|
|
5
|
+
* ── WHY NOT A `Pressable` ───────────────────────────────────────────────────
|
|
6
|
+
*
|
|
7
|
+
* On Android the view holding the JS responder intercepts every later MOVE of
|
|
8
|
+
* that touch natively (`JSResponderHandler.onInterceptTouchEvent` returns true
|
|
9
|
+
* for the responder's own id). A `Pressable` claims the responder on touch
|
|
10
|
+
* start, so a horizontal `ScrollView` INSIDE it never sees the drag: a turn
|
|
11
|
+
* wrapped in the context menu's trigger could not scroll its code block
|
|
12
|
+
* sideways (Pixel 8a, Android 16; the same block scrolled without the wrapper).
|
|
13
|
+
* A vertical scroller ABOVE the trigger kept working, because a parent
|
|
14
|
+
* intercepts before its child — which is why only the inner one broke.
|
|
15
|
+
*
|
|
16
|
+
* So the hold is timed off the RAW touch events, which every ancestor receives
|
|
17
|
+
* without claiming anything: a scroller that takes the drag cancels the touch,
|
|
18
|
+
* and a finger that travels past the slop or lifts early cancels the timer.
|
|
19
|
+
* Taps keep going to whatever the content itself makes pressable.
|
|
20
|
+
*
|
|
21
|
+
* Assistive tech reaches the menu through the `longpress` accessibility action
|
|
22
|
+
* (TalkBack's double-tap-and-hold, VoiceOver's actions rotor).
|
|
23
|
+
*/
|
|
24
|
+
import React, { useCallback, useEffect, useRef } from 'react';
|
|
25
|
+
import {
|
|
26
|
+
View,
|
|
27
|
+
type AccessibilityActionEvent,
|
|
28
|
+
type GestureResponderEvent,
|
|
29
|
+
} from 'react-native';
|
|
30
|
+
|
|
31
|
+
import type { TriggerHandleProps } from './types';
|
|
32
|
+
|
|
33
|
+
/** `Pressable`'s own default, so a context menu opens on the platform's usual hold. */
|
|
34
|
+
export const LONG_PRESS_MS = 500;
|
|
35
|
+
/** How far the finger may drift and still be holding, in dp (`Pressability`'s deactivation distance). */
|
|
36
|
+
export const LONG_PRESS_SLOP = 10;
|
|
37
|
+
|
|
38
|
+
export type LongPressAreaProps = Partial<TriggerHandleProps> & {
|
|
39
|
+
children?: React.ReactNode;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export function LongPressArea({
|
|
43
|
+
children,
|
|
44
|
+
onLongPress,
|
|
45
|
+
// A press is the content's own business: the area never claims one.
|
|
46
|
+
onPress: _onPress,
|
|
47
|
+
disabled,
|
|
48
|
+
accessibilityLabel,
|
|
49
|
+
accessibilityRole,
|
|
50
|
+
...aria
|
|
51
|
+
}: LongPressAreaProps) {
|
|
52
|
+
const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
53
|
+
const origin = useRef<{ x: number; y: number } | null>(null);
|
|
54
|
+
const onLongPressRef = useRef(onLongPress);
|
|
55
|
+
onLongPressRef.current = onLongPress;
|
|
56
|
+
|
|
57
|
+
const cancel = useCallback(() => {
|
|
58
|
+
if (timer.current !== null) clearTimeout(timer.current);
|
|
59
|
+
timer.current = null;
|
|
60
|
+
origin.current = null;
|
|
61
|
+
}, []);
|
|
62
|
+
useEffect(() => cancel, [cancel]);
|
|
63
|
+
|
|
64
|
+
const onTouchStart = useCallback(
|
|
65
|
+
(event: GestureResponderEvent) => {
|
|
66
|
+
cancel();
|
|
67
|
+
// A second finger is a pinch or a scroll, not a hold.
|
|
68
|
+
if (disabled || !onLongPressRef.current || event.nativeEvent.touches?.length > 1) return;
|
|
69
|
+
origin.current = { x: event.nativeEvent.pageX, y: event.nativeEvent.pageY };
|
|
70
|
+
timer.current = setTimeout(() => {
|
|
71
|
+
timer.current = null;
|
|
72
|
+
origin.current = null;
|
|
73
|
+
onLongPressRef.current?.(event);
|
|
74
|
+
}, LONG_PRESS_MS);
|
|
75
|
+
},
|
|
76
|
+
[cancel, disabled],
|
|
77
|
+
);
|
|
78
|
+
const onTouchMove = useCallback(
|
|
79
|
+
(event: GestureResponderEvent) => {
|
|
80
|
+
const start = origin.current;
|
|
81
|
+
if (!start) return;
|
|
82
|
+
const dx = event.nativeEvent.pageX - start.x;
|
|
83
|
+
const dy = event.nativeEvent.pageY - start.y;
|
|
84
|
+
if (dx * dx + dy * dy > LONG_PRESS_SLOP * LONG_PRESS_SLOP) cancel();
|
|
85
|
+
},
|
|
86
|
+
[cancel],
|
|
87
|
+
);
|
|
88
|
+
const onAccessibilityAction = useCallback(
|
|
89
|
+
(event: AccessibilityActionEvent) => {
|
|
90
|
+
if (event.nativeEvent.actionName === 'longpress' && !disabled) {
|
|
91
|
+
onLongPressRef.current?.(event as unknown as GestureResponderEvent);
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
[disabled],
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<View
|
|
99
|
+
{...aria}
|
|
100
|
+
// One node, as the `Pressable` it replaces was: the hold is its action.
|
|
101
|
+
accessible
|
|
102
|
+
accessibilityLabel={accessibilityLabel}
|
|
103
|
+
accessibilityRole={accessibilityRole}
|
|
104
|
+
accessibilityState={{ disabled: !!disabled }}
|
|
105
|
+
accessibilityActions={disabled ? undefined : [{ name: 'longpress', label: accessibilityLabel }]}
|
|
106
|
+
onAccessibilityAction={onAccessibilityAction}
|
|
107
|
+
onTouchStart={onTouchStart}
|
|
108
|
+
onTouchMove={onTouchMove}
|
|
109
|
+
onTouchEnd={cancel}
|
|
110
|
+
onTouchCancel={cancel}>
|
|
111
|
+
{children}
|
|
112
|
+
</View>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
@@ -6,7 +6,7 @@ import React, {
|
|
|
6
6
|
useRef,
|
|
7
7
|
useState,
|
|
8
8
|
} from 'react';
|
|
9
|
-
import { Pressable, StyleSheet, View, useWindowDimensions } from 'react-native';
|
|
9
|
+
import { Pressable, StyleSheet, View, useWindowDimensions, type ScrollView } from 'react-native';
|
|
10
10
|
import Animated, {
|
|
11
11
|
Easing,
|
|
12
12
|
useAnimatedStyle,
|
|
@@ -37,6 +37,7 @@ import {
|
|
|
37
37
|
import { ModalPortal } from './modal-portal';
|
|
38
38
|
import type { SettingsPalette } from './palette';
|
|
39
39
|
import type { SettingsModalProps, SettingsNavGroup, SettingsNavItem } from './types';
|
|
40
|
+
import { useKeyboardReveal } from './use-keyboard-reveal';
|
|
40
41
|
import { IS_WEB, useSettingsWebCss } from './web-css';
|
|
41
42
|
|
|
42
43
|
/**
|
|
@@ -722,9 +723,15 @@ function PageScroller({
|
|
|
722
723
|
const onScroll = useAnimatedScrollHandler((event) => {
|
|
723
724
|
scrollY.value = Math.max(0, event.contentOffset.y);
|
|
724
725
|
}, [scrollY]);
|
|
726
|
+
const scrollRef = useRef<ScrollView>(null);
|
|
727
|
+
// The keyboard slides over an edge-to-edge modal: pad by it, and bring the
|
|
728
|
+
// focused field up above it.
|
|
729
|
+
const keyboardHeight = useKeyboardReveal(scrollRef, scrollY, !IS_WEB);
|
|
725
730
|
return (
|
|
726
731
|
<Animated.ScrollView
|
|
732
|
+
ref={scrollRef}
|
|
727
733
|
style={styles.scroll}
|
|
734
|
+
keyboardShouldPersistTaps="handled"
|
|
728
735
|
stickyHeaderIndices={IS_WEB ? undefined : [0]}
|
|
729
736
|
onScroll={onScroll}
|
|
730
737
|
scrollEventThrottle={16}
|
|
@@ -737,7 +744,7 @@ function PageScroller({
|
|
|
737
744
|
style={{
|
|
738
745
|
paddingLeft: inset,
|
|
739
746
|
paddingRight: inset,
|
|
740
|
-
paddingBottom: inset,
|
|
747
|
+
paddingBottom: inset + keyboardHeight,
|
|
741
748
|
paddingTop: insetTop,
|
|
742
749
|
}}
|
|
743
750
|
>
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { useEffect, useRef, useState, type RefObject } from 'react';
|
|
2
|
+
import { Keyboard, Platform, TextInput, type KeyboardEvent, type ScrollView } from 'react-native';
|
|
3
|
+
|
|
4
|
+
/** Clearance kept between the focused field and the keyboard's top, px. */
|
|
5
|
+
export const KEYBOARD_REVEAL_MARGIN = 16;
|
|
6
|
+
|
|
7
|
+
type Measurable = { measureInWindow?: (cb: (x: number, y: number, width: number, height: number) => void) => void };
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Keep a settings page's focused field above the software keyboard — native
|
|
11
|
+
* only; on web the browser scrolls a focused field into view itself.
|
|
12
|
+
*
|
|
13
|
+
* The settings modal draws edge to edge, so the keyboard slides OVER it rather
|
|
14
|
+
* than resizing it: a field low on a page (Personalization's last input, a
|
|
15
|
+
* Pixel 8a at Android 16) stayed behind the keyboard with nothing to scroll it
|
|
16
|
+
* out. This returns the keyboard's height for the page to pad its content by —
|
|
17
|
+
* so there is room to scroll — and, when the keyboard shows, scrolls the page
|
|
18
|
+
* by exactly what the focused field sits below the keyboard's top.
|
|
19
|
+
*
|
|
20
|
+
* `offset` is the page's current scroll offset (its scroll handler keeps it).
|
|
21
|
+
*/
|
|
22
|
+
export function useKeyboardReveal(
|
|
23
|
+
scrollRef: RefObject<ScrollView | null>,
|
|
24
|
+
offset: { value: number },
|
|
25
|
+
enabled: boolean,
|
|
26
|
+
): number {
|
|
27
|
+
const [keyboard, setKeyboard] = useState<{ height: number; overlap: number }>({ height: 0, overlap: 0 });
|
|
28
|
+
const offsetRef = useRef(offset);
|
|
29
|
+
offsetRef.current = offset;
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (!enabled || typeof Keyboard?.addListener !== 'function') return;
|
|
33
|
+
const reveal = (event: KeyboardEvent) => {
|
|
34
|
+
const { height, screenY } = event.endCoordinates;
|
|
35
|
+
const field = TextInput.State?.currentlyFocusedInput?.() as Measurable | null | undefined;
|
|
36
|
+
if (!field || typeof field.measureInWindow !== 'function') {
|
|
37
|
+
setKeyboard({ height, overlap: 0 });
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
field.measureInWindow((_x, y, _width, fieldHeight) => {
|
|
41
|
+
setKeyboard({ height, overlap: Math.max(0, y + fieldHeight + KEYBOARD_REVEAL_MARGIN - screenY) });
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
// iOS announces the keyboard before it moves; Android only once it is up.
|
|
45
|
+
const show = Keyboard.addListener(Platform.OS === 'ios' ? 'keyboardWillShow' : 'keyboardDidShow', reveal);
|
|
46
|
+
const hide = Keyboard.addListener(Platform.OS === 'ios' ? 'keyboardWillHide' : 'keyboardDidHide', () =>
|
|
47
|
+
setKeyboard({ height: 0, overlap: 0 }),
|
|
48
|
+
);
|
|
49
|
+
return () => {
|
|
50
|
+
show.remove();
|
|
51
|
+
hide.remove();
|
|
52
|
+
};
|
|
53
|
+
}, [enabled]);
|
|
54
|
+
|
|
55
|
+
// After the commit that pads the page by the keyboard: before it, the scroll
|
|
56
|
+
// range ends where the keyboard begins and the scroll would be clamped short.
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
if (keyboard.overlap > 0) scrollRef.current?.scrollTo({ y: offsetRef.current.value + keyboard.overlap, animated: true });
|
|
59
|
+
}, [keyboard, scrollRef]);
|
|
60
|
+
|
|
61
|
+
return enabled ? keyboard.height : 0;
|
|
62
|
+
}
|