@vvedantb/native-ui 0.25.1 → 0.25.3

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/src/SheetRow.tsx CHANGED
@@ -7,6 +7,7 @@ import { palette } from "./palette";
7
7
  import { useLargerText } from "./theme";
8
8
  import { tokens } from "./tokens";
9
9
  import { useScheme } from "./useScheme";
10
+ import { usePressed } from "./usePressed";
10
11
 
11
12
  export type SheetRowProps = {
12
13
  /** A Tabler icon at the start. */
@@ -55,6 +56,7 @@ export function SheetRow({
55
56
  onPress,
56
57
  testID,
57
58
  }: SheetRowProps) {
59
+ const press = usePressed();
58
60
  const scheme = useScheme();
59
61
  const largerText = useLargerText();
60
62
  const color = danger
@@ -79,10 +81,12 @@ export function SheetRow({
79
81
  largerText ? "min-h-16" : "min-h-14",
80
82
  disabled && "opacity-50",
81
83
  )}
82
- style={({ pressed }) => ({
84
+ onPressIn={press.onPressIn}
85
+ onPressOut={press.onPressOut}
86
+ style={{
83
87
  borderRadius: tokens.radius.sm,
84
- backgroundColor: pressed && !disabled ? palette.default[scheme] : "transparent",
85
- })}
88
+ backgroundColor: press.pressed && !disabled ? palette.default[scheme] : "transparent",
89
+ }}
86
90
  >
87
91
  {leading ?? (Icon ? <Icon size={iconSize} color={color} /> : null)}
88
92
  <View className="min-w-0 flex-1">
@@ -0,0 +1,56 @@
1
+ import { createContext, useContext, type RefObject } from "react";
2
+ import type { NativeScrollEvent } from "react-native";
3
+
4
+ // The `Conversation` context on its own, so a message can reach it without the
5
+ // thread's components (`message.tsx` sets `overlay`).
6
+
7
+ /**
8
+ * What the thread scrolls with: the `ScrollView` of `ConversationContent` or
9
+ * the `FlatList` of `ConversationList`. `scrollToEnd` goes to the newest
10
+ * message, which is offset 0 in an inverted list. `scrollTo` goes to an
11
+ * offset; only the `ScrollView` has it, so call it as `scrollTo?.(...)`.
12
+ */
13
+ export type ConversationScroller = {
14
+ scrollToEnd: (options?: { animated?: boolean }) => void;
15
+ scrollTo?: (options: { y: number; animated?: boolean }) => void;
16
+ };
17
+
18
+ export type ConversationContextValue = {
19
+ isAtBottom: boolean;
20
+ scrollToBottom: () => void;
21
+ scrollRef: RefObject<ConversationScroller | null>;
22
+ /** `bottomInset` and `inverted`, as `isScrolledToBottom`. */
23
+ onScroll: (event: NativeScrollEvent, bottomInset?: number, inverted?: boolean) => void;
24
+ onUserScroll: () => void;
25
+ followContent: () => void;
26
+ /** The height of the `ConversationDock` under the thread, 0 without one. */
27
+ dockHeight: number;
28
+ setDockHeight: (height: number) => void;
29
+ /**
30
+ * A message's hold menu over the thread. Its window takes the focus on
31
+ * Android, as it opens and again as it closes, and the keyboard handler of
32
+ * `ConversationList` would scroll the thread to its end each time. The list
33
+ * ignores the keyboard from `openOverlay` until the close has settled:
34
+ * `closeOverlay` marks it `closing`, and `settleOverlay` ends that on the
35
+ * close's last keyboard event (Android), the menu's dismiss (iOS) or the
36
+ * reader's next drag. Android gives no dismiss callback for a `Modal`.
37
+ */
38
+ overlay: "none" | "open" | "closing";
39
+ openOverlay: () => void;
40
+ closeOverlay: () => void;
41
+ settleOverlay: () => void;
42
+ };
43
+
44
+ export const ConversationContext = createContext<ConversationContextValue | null>(null);
45
+
46
+ /** `isAtBottom` and `scrollToBottom` of the enclosing `Conversation`, for a custom scroll button. */
47
+ export function useConversation() {
48
+ const context = useContext(ConversationContext);
49
+ if (!context) throw new Error("Conversation parts must be used within Conversation");
50
+ return context;
51
+ }
52
+
53
+ /** The enclosing `Conversation`, or null for a message drawn outside one. */
54
+ export function useOptionalConversation() {
55
+ return useContext(ConversationContext);
56
+ }
@@ -1,13 +1,4 @@
1
- import {
2
- createContext,
3
- isValidElement,
4
- useContext,
5
- useRef,
6
- useState,
7
- type ComponentType,
8
- type ReactNode,
9
- type RefObject,
10
- } from "react";
1
+ import { isValidElement, useRef, useState, type ComponentType, type ReactNode } from "react";
11
2
  import {
12
3
  FlatList,
13
4
  Platform,
@@ -38,6 +29,7 @@ import { tokens } from "../tokens";
38
29
  import { useReduceMotion } from "../useReduceMotion";
39
30
  import { useScheme } from "../useScheme";
40
31
  import { chatTextSize } from "./chat-text";
32
+ import { ConversationContext, useConversation, type ConversationContextValue, type ConversationScroller } from "./conversation-context";
41
33
 
42
34
  /** Within this many points of the end, the thread counts as at the bottom and keeps following new content. */
43
35
  export const AT_BOTTOM_THRESHOLD = 70;
@@ -59,38 +51,7 @@ export function isScrolledToBottom(
59
51
  return contentSize.height + bottomInset - layoutMeasurement.height - contentOffset.y <= AT_BOTTOM_THRESHOLD;
60
52
  }
61
53
 
62
- /**
63
- * What the thread scrolls with: the `ScrollView` of `ConversationContent` or
64
- * the `FlatList` of `ConversationList`. `scrollToEnd` goes to the newest
65
- * message, which is offset 0 in an inverted list. `scrollTo` goes to an
66
- * offset; only the `ScrollView` has it, so call it as `scrollTo?.(...)`.
67
- */
68
- export type ConversationScroller = {
69
- scrollToEnd: (options?: { animated?: boolean }) => void;
70
- scrollTo?: (options: { y: number; animated?: boolean }) => void;
71
- };
72
-
73
- type ConversationContextValue = {
74
- isAtBottom: boolean;
75
- scrollToBottom: () => void;
76
- scrollRef: RefObject<ConversationScroller | null>;
77
- /** `bottomInset` and `inverted`, as `isScrolledToBottom`. */
78
- onScroll: (event: NativeScrollEvent, bottomInset?: number, inverted?: boolean) => void;
79
- onUserScroll: () => void;
80
- followContent: () => void;
81
- /** The height of the `ConversationDock` under the thread, 0 without one. */
82
- dockHeight: number;
83
- setDockHeight: (height: number) => void;
84
- };
85
-
86
- const ConversationContext = createContext<ConversationContextValue | null>(null);
87
-
88
- /** `isAtBottom` and `scrollToBottom` of the enclosing `Conversation`, for a custom scroll button. */
89
- export function useConversation() {
90
- const context = useContext(ConversationContext);
91
- if (!context) throw new Error("Conversation parts must be used within Conversation");
92
- return context;
93
- }
54
+ export { useConversation, useOptionalConversation, type ConversationScroller } from "./conversation-context";
94
55
 
95
56
  export type ConversationProps = ViewProps & { className?: string };
96
57
 
@@ -108,6 +69,7 @@ export function Conversation({ className, ...props }: ConversationProps) {
108
69
  const autoScrolling = useRef(false);
109
70
  const [isAtBottom, setIsAtBottom] = useState(true);
110
71
  const [dockHeight, setDockHeight] = useState(0);
72
+ const [overlay, setOverlay] = useState<ConversationContextValue["overlay"]>("none");
111
73
 
112
74
  const update = (next: boolean) => {
113
75
  atBottom.current = next;
@@ -137,6 +99,10 @@ export function Conversation({ className, ...props }: ConversationProps) {
137
99
  },
138
100
  dockHeight,
139
101
  setDockHeight,
102
+ overlay,
103
+ openOverlay: () => setOverlay("open"),
104
+ closeOverlay: () => setOverlay("closing"),
105
+ settleOverlay: () => setOverlay((current) => (current === "closing" ? "none" : current)),
140
106
  };
141
107
 
142
108
  return (
@@ -201,6 +167,7 @@ function useConversationScroll<P extends ConversationScrollHandlers>(
201
167
  },
202
168
  onScrollBeginDrag: (event: NativeSyntheticEvent<NativeScrollEvent>) => {
203
169
  conversation.onUserScroll();
170
+ conversation.settleOverlay();
204
171
  onScrollBeginDrag?.(event);
205
172
  },
206
173
  // The app's handler first, so a scroller that measures itself (`ConversationList`) has the new size to follow.
@@ -346,6 +313,7 @@ export function ConversationList<T>({
346
313
  <keyboard.ChatScrollView
347
314
  {...scrollProps}
348
315
  inverted={inverted}
316
+ freeze={conversation.overlay !== "none"}
349
317
  // The composer pads the bottom inset, which the keyboard covers: the content rises by the rest.
350
318
  bottomOffset={insets.bottom}
351
319
  onInsetChange={(inset) => {
@@ -353,6 +321,8 @@ export function ConversationList<T>({
353
321
  }}
354
322
  onKeyboardMove={(moving) => {
355
323
  size.current.keyboardMoving = moving;
324
+ // The closing menu's window hands the focus back with a keyboard event: frozen until it ends.
325
+ if (!moving) conversation.settleOverlay();
356
326
  }}
357
327
  />
358
328
  )
@@ -10,6 +10,7 @@ import { useReduceMotion } from "../useReduceMotion";
10
10
  import { useScheme } from "../useScheme";
11
11
  import { chatTextSize } from "./chat-text";
12
12
  import { MESSAGE_MENU, messageContextMenuLayout, type MessageMenu, type MessageMenuRect } from "./message-menu-layout";
13
+ import { usePressed } from "../usePressed";
13
14
 
14
15
  /**
15
16
  * The iMessage hold menu for a chat message: the chat fades under a frosted
@@ -23,6 +24,7 @@ import { MESSAGE_MENU, messageContextMenuLayout, type MessageMenu, type MessageM
23
24
  export function MessageContextMenu({
24
25
  open,
25
26
  onClose,
27
+ onDismissed,
26
28
  anchor,
27
29
  align,
28
30
  preview,
@@ -31,6 +33,8 @@ export function MessageContextMenu({
31
33
  }: {
32
34
  open: boolean;
33
35
  onClose: () => void;
36
+ /** After the menu has gone from the screen (iOS; Android gives no such callback for a `Modal`). */
37
+ onDismissed?: () => void;
34
38
  /** The held message's box; the menu stays shut without one. */
35
39
  anchor: MessageMenuRect | null;
36
40
  /** Which side the pill and the card line up with: the message's (`end` for the user's). */
@@ -71,7 +75,7 @@ export function MessageContextMenu({
71
75
 
72
76
  return (
73
77
  // The Modal's own fade: Reanimated entering animations do not run inside a Modal on Android.
74
- <Modal visible transparent animationType={reduceMotion ? "none" : "fade"} statusBarTranslucent onRequestClose={onClose}>
78
+ <Modal visible transparent animationType={reduceMotion ? "none" : "fade"} statusBarTranslucent onRequestClose={onClose} onDismiss={onDismissed}>
75
79
  <View style={{ flex: 1 }} testID={testID} accessibilityViewIsModal onAccessibilityEscape={onClose}>
76
80
  <View style={StyleSheet.absoluteFill}>
77
81
  <Pressable
@@ -149,38 +153,79 @@ export function MessageContextMenu({
149
153
  ...shadow,
150
154
  }}
151
155
  >
152
- {menu.actions.map((action, index) => {
153
- const Icon = action.icon;
154
- const color = action.destructive ? palette.danger[scheme] : tokens.color.foreground[scheme];
155
- return (
156
- <Pressable
157
- key={action.key}
158
- testID={`${testID}-action-${action.key}`}
159
- accessibilityRole="menuitem"
160
- accessibilityLabel={action.label}
161
- accessibilityState={{ disabled: action.disabled === true }}
162
- disabled={action.disabled === true}
163
- onPress={() => run(action.onPress)}
164
- // A static style: with a `className`, NativeWind drops a style function.
165
- className="flex-row items-center gap-3 px-4 active:opacity-70"
166
- style={[
167
- { minHeight: rowHeight, opacity: action.disabled ? 0.5 : 1 },
168
- index > 0 && { borderTopWidth: StyleSheet.hairlineWidth, borderTopColor: tokens.color.separator[scheme] },
169
- ]}
170
- >
171
- <Text
172
- numberOfLines={1}
173
- className={cn(body, "min-w-0 flex-1 font-instrument-sans")}
174
- style={[sizeStyle(body), typeStyle("medium"), { color }]}
175
- >
176
- {action.label}
177
- </Text>
178
- {Icon ? <Icon size={largerText ? 22 : 20} color={color} /> : null}
179
- </Pressable>
180
- );
181
- })}
156
+ {menu.actions.map((action, index) => (
157
+ <MenuCardRow
158
+ key={action.key}
159
+ testID={`${testID}-action-${action.key}`}
160
+ action={action}
161
+ first={index === 0}
162
+ rowHeight={rowHeight}
163
+ body={body}
164
+ iconSize={largerText ? 22 : 20}
165
+ onPress={() => run(action.onPress)}
166
+ />
167
+ ))}
182
168
  </View>
183
169
  </View>
184
170
  </Modal>
185
171
  );
186
172
  }
173
+
174
+ /**
175
+ * One card row: label first, icon last. While pressed it takes the
176
+ * `SheetRow` pressed fill, so the finger sees which row it is on.
177
+ */
178
+ function MenuCardRow({
179
+ testID,
180
+ action,
181
+ first,
182
+ rowHeight,
183
+ body,
184
+ iconSize,
185
+ onPress,
186
+ }: {
187
+ testID: string;
188
+ action: MessageMenu["actions"][number];
189
+ first: boolean;
190
+ rowHeight: number;
191
+ body: ReturnType<typeof chatTextSize>;
192
+ iconSize: number;
193
+ onPress: () => void;
194
+ }) {
195
+ const scheme = useScheme();
196
+ // A state, not a style function: with a `className`, NativeWind drops a style function.
197
+ const press = usePressed();
198
+ const disabled = action.disabled === true;
199
+ const Icon = action.icon;
200
+ const color = action.destructive ? palette.danger[scheme] : tokens.color.foreground[scheme];
201
+ return (
202
+ <Pressable
203
+ testID={testID}
204
+ accessibilityRole="menuitem"
205
+ accessibilityLabel={action.label}
206
+ accessibilityState={{ disabled }}
207
+ disabled={disabled}
208
+ onPress={onPress}
209
+ onPressIn={press.onPressIn}
210
+ onPressOut={press.onPressOut}
211
+ className="flex-row items-center gap-3 px-4"
212
+ style={[
213
+ {
214
+ minHeight: rowHeight,
215
+ opacity: disabled ? 0.5 : 1,
216
+ backgroundColor: press.pressed && !disabled ? palette.default[scheme] : "transparent",
217
+ },
218
+ !first && { borderTopWidth: StyleSheet.hairlineWidth, borderTopColor: tokens.color.separator[scheme] },
219
+ ]}
220
+ >
221
+ <Text
222
+ numberOfLines={1}
223
+ className={cn(body, "min-w-0 flex-1 font-instrument-sans")}
224
+ style={[sizeStyle(body), typeStyle("medium"), { color }]}
225
+ >
226
+ {action.label}
227
+ </Text>
228
+ {Icon ? <Icon size={iconSize} color={color} /> : null}
229
+ </Pressable>
230
+ );
231
+ }
@@ -20,9 +20,11 @@ import { useScheme } from "../useScheme";
20
20
  import { META_TEXT_STYLE, chatTextSize } from "./chat-text";
21
21
  import { ChatIconButton, type ChatIconButtonSize } from "./icon-button";
22
22
  import { MESSAGE_ACTIONS_TITLE, MessageActionSheet, type MessageSheetAction } from "./message-action-sheet";
23
+ import { useOptionalConversation } from "./conversation-context";
23
24
  import { MessageContextMenu } from "./message-context-menu";
24
25
  import type { MessageMenu, MessageMenuRect } from "./message-menu-layout";
25
26
  import { ChatTextColorContext, ResponseText } from "./response-text";
27
+ import { usePressed } from "../usePressed";
26
28
 
27
29
  export type MessageRole = "user" | "assistant" | "system";
28
30
 
@@ -137,22 +139,29 @@ export function Message({
137
139
  }: MessageProps) {
138
140
  const user = from === "user";
139
141
  const [sheetOpen, setSheetOpen] = useState(false);
140
- const [pressing, setPressing] = useState(false);
142
+ const press = usePressed();
141
143
  // The open context menu: where the message was and what it offers, read at the hold.
142
144
  const [held, setHeld] = useState<{ anchor: MessageMenuRect; menu: MessageMenu } | null>(null);
143
145
  // Measured at the hold: the menu draws the message again where it is on screen.
144
146
  const pressable = useRef<View>(null);
145
147
  const hasActions = actions != null && actions.length > 0;
146
148
  const longPressable = onLongPress != null || hasActions || menu != null;
149
+ // In a thread, the menu freezes the list's keyboard handling until its close settles (see `overlay`).
150
+ const conversation = useOptionalConversation();
147
151
  const longPress = () => {
148
152
  // A medium tap on a hold, as iMessage; the sheet adds its own selection tick.
149
153
  impactHaptic("medium");
150
154
  onLongPress?.();
151
155
  if (menu) {
152
156
  const built = menu();
157
+ conversation?.openOverlay();
153
158
  pressable.current?.measureInWindow((x, y, width, height) => setHeld({ anchor: { x, y, width, height }, menu: built }));
154
159
  } else if (hasActions) setSheetOpen(true);
155
160
  };
161
+ const closeMenu = () => {
162
+ setHeld(null);
163
+ conversation?.closeOverlay();
164
+ };
156
165
  const layout: ViewProps["style"] = [
157
166
  { alignSelf: user ? "flex-end" : "flex-start", alignItems: user ? "flex-end" : "stretch" },
158
167
  style,
@@ -175,9 +184,9 @@ export function Message({
175
184
  className={merged}
176
185
  // While held it dims a little: the feedback before the menu opens. A state, not a
177
186
  // style function: with a `className`, NativeWind drops a style function, layout and all.
178
- style={[layout, pressing ? HELD_STYLE : null]}
179
- onPressIn={() => setPressing(true)}
180
- onPressOut={() => setPressing(false)}
187
+ style={[layout, press.pressed ? HELD_STYLE : null]}
188
+ onPressIn={press.onPressIn}
189
+ onPressOut={press.onPressOut}
181
190
  onLongPress={longPress}
182
191
  delayLongPress={HOLD_DELAY_MS}
183
192
  // TalkBack's actions menu reaches the same sheet as a long press.
@@ -192,7 +201,8 @@ export function Message({
192
201
  {menu ? (
193
202
  <MessageContextMenu
194
203
  open={held !== null}
195
- onClose={() => setHeld(null)}
204
+ onClose={closeMenu}
205
+ onDismissed={conversation?.settleOverlay}
196
206
  anchor={held?.anchor ?? null}
197
207
  align={user ? "end" : "start"}
198
208
  preview={
@@ -15,6 +15,7 @@ import {
15
15
  type CollapsibleTriggerProps,
16
16
  } from "./collapsible";
17
17
  import { ResponseText } from "./response-text";
18
+ import { usePressed } from "../usePressed";
18
19
 
19
20
  /** The sources a reply used, folded (default closed). */
20
21
  export function Sources({ className, ...props }: CollapsibleProps) {
@@ -75,6 +76,7 @@ const ROW_HEIGHT = 36;
75
76
  * Pressed, it takes the web hover fill (`bg-surface-secondary`).
76
77
  */
77
78
  export function Source({ href, title, onPress, testID }: SourceProps) {
79
+ const press = usePressed();
78
80
  const scheme = useScheme();
79
81
  const largerText = useLargerText();
80
82
  const label = title ?? href;
@@ -85,11 +87,13 @@ export function Source({ href, title, onPress, testID }: SourceProps) {
85
87
  accessibilityLabel={label}
86
88
  hitSlop={touchSlop(MIN_TOUCH_TARGET, ROW_HEIGHT)}
87
89
  onPress={() => (onPress ? onPress(href) : void Linking.openURL(href))}
90
+ onPressIn={press.onPressIn}
91
+ onPressOut={press.onPressOut}
88
92
  className="flex-row items-center justify-between gap-2 px-3 py-2"
89
- style={({ pressed }) => ({
93
+ style={{
90
94
  borderRadius: tokens.radius.md,
91
- backgroundColor: pressed ? tokens.color.surfaceSecondary[scheme] : "transparent",
92
- })}
95
+ backgroundColor: press.pressed ? tokens.color.surfaceSecondary[scheme] : "transparent",
96
+ }}
93
97
  >
94
98
  <ResponseText size="small" tone="muted" selectable={false} numberOfLines={1} className="shrink">
95
99
  {label}
@@ -7,6 +7,7 @@ import { useLargerText } from "../theme";
7
7
  import { tokens } from "../tokens";
8
8
  import { useScheme } from "../useScheme";
9
9
  import { chatTextSize } from "./chat-text";
10
+ import { usePressed } from "../usePressed";
10
11
 
11
12
  export type SuggestionsProps = {
12
13
  /** `horizontal` (default) scrolls one row of chips; `vertical` stacks them full width. */
@@ -61,6 +62,7 @@ const CHIP_HEIGHT = 32;
61
62
  * it takes the web hover (`bg-surface-tertiary text-foreground`).
62
63
  */
63
64
  export function Suggestion({ suggestion, onPress, children, disabled, testID }: SuggestionProps) {
65
+ const press = usePressed();
64
66
  const scheme = useScheme();
65
67
  const largerText = useLargerText();
66
68
  const size = chatTextSize("small", largerText);
@@ -74,11 +76,13 @@ export function Suggestion({ suggestion, onPress, children, disabled, testID }:
74
76
  hitSlop={touchSlop(MIN_TOUCH_TARGET, CHIP_HEIGHT)}
75
77
  onPress={() => onPress?.(suggestion)}
76
78
  className={cn("justify-center border", largerText ? "min-h-12 px-4 py-2" : "min-h-8 px-3 py-1.5", disabled && "opacity-45")}
77
- style={({ pressed }) => ({
79
+ onPressIn={press.onPressIn}
80
+ onPressOut={press.onPressOut}
81
+ style={{
78
82
  borderRadius: tokens.radius.pill,
79
83
  borderColor: tokens.color.border[scheme],
80
- backgroundColor: pressed ? palette.surfaceTertiary[scheme] : tokens.color.surfaceSecondary[scheme],
81
- })}
84
+ backgroundColor: press.pressed ? palette.surfaceTertiary[scheme] : tokens.color.surfaceSecondary[scheme],
85
+ }}
82
86
  >
83
87
  {({ pressed }) => (
84
88
  <Text
@@ -43,6 +43,7 @@ function StickyView({ bottomOffset, ...props }: ComponentProps<KeyboardParts["St
43
43
  function ChatScrollView({
44
44
  bottomOffset,
45
45
  inverted = false,
46
+ freeze = false,
46
47
  onInsetChange,
47
48
  onKeyboardMove,
48
49
  ...props
@@ -64,6 +65,8 @@ function ChatScrollView({
64
65
  <KeyboardChatScrollView
65
66
  {...props}
66
67
  inverted={inverted}
68
+ // An overlay window (a hold menu) takes the focus on Android: its keyboard events must not scroll the list.
69
+ freeze={freeze}
67
70
  offset={bottomOffset}
68
71
  keyboardLiftBehavior="always"
69
72
  onContentInsetChange={(insets) =>
@@ -31,12 +31,14 @@ export type KeyboardParts = {
31
31
  * gets that extra space as the scroll offset sees it, which `onScroll` does
32
32
  * not report: past the content's end, or when `inverted` before offset 0.
33
33
  * `onKeyboardMove` is true from the start to the end of each keyboard
34
- * move, while the keyboard, not the reader, scrolls the list.
34
+ * move, while the keyboard, not the reader, scrolls the list. With
35
+ * `freeze`, keyboard events change nothing (an overlay window is open).
35
36
  */
36
37
  ChatScrollView: ComponentType<
37
38
  ScrollViewProps & {
38
39
  bottomOffset: number;
39
40
  inverted?: boolean;
41
+ freeze?: boolean;
40
42
  onInsetChange: (inset: number) => void;
41
43
  onKeyboardMove: (moving: boolean) => void;
42
44
  }
@@ -0,0 +1,13 @@
1
+ import { useState } from "react";
2
+
3
+ /**
4
+ * Whether a `Pressable` is held down, as state, for a pressed look. With a
5
+ * `className`, NativeWind drops a `Pressable` style function (`({ pressed })
6
+ * => ...`), and with it the radius, border and fill it sets; so a pressable
7
+ * with classes reads `pressed` from here and passes a plain style. Spread
8
+ * `onPressIn` and `onPressOut` on the `Pressable`.
9
+ */
10
+ export function usePressed() {
11
+ const [pressed, setPressed] = useState(false);
12
+ return { pressed, onPressIn: () => setPressed(true), onPressOut: () => setPressed(false) };
13
+ }