@storybook/react-native-ui-lite 10.4.1 → 10.4.2-next.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/dist/index.js +33 -45
- package/package.json +3 -3
- package/src/DrawerKeyboardInsetContext.tsx +5 -0
- package/src/MobileMenuDrawer.tsx +29 -48
- package/src/SearchResults.tsx +4 -2
- package/src/Tree.tsx +4 -2
package/dist/index.js
CHANGED
|
@@ -393,6 +393,10 @@ const SelectedNodeProvider = ({ children }) => {
|
|
|
393
393
|
};
|
|
394
394
|
const useSelectedNode = () => (0, react.useContext)(SelectedNodeContext);
|
|
395
395
|
//#endregion
|
|
396
|
+
//#region src/DrawerKeyboardInsetContext.tsx
|
|
397
|
+
const DrawerKeyboardInsetContext = (0, react.createContext)(0);
|
|
398
|
+
const useDrawerKeyboardInset = () => (0, react.useContext)(DrawerKeyboardInsetContext);
|
|
399
|
+
//#endregion
|
|
396
400
|
//#region src/Tree.tsx
|
|
397
401
|
const Node = react.default.memo(function Node({ item, refId, isOrphan: _isOrphan, isDisplayed: _isDisplayed, isSelected, isFullyExpanded, color: _2, setFullyExpanded, isExpanded, setExpanded, onSelectStoryId }) {
|
|
398
402
|
const id = (0, _storybook_react_native_ui_common.createId)(item.id, refId);
|
|
@@ -516,6 +520,7 @@ const Tree = react.default.memo(function Tree({ isMain, refId, data, status, doc
|
|
|
516
520
|
const { registerCallback } = useSelectedNode();
|
|
517
521
|
const [pendingScrollTarget, setPendingScrollTarget] = (0, react.useState)(null);
|
|
518
522
|
const insets = (0, react_native_safe_area_context.useSafeAreaInsets)();
|
|
523
|
+
const drawerKeyboardInset = useDrawerKeyboardInset();
|
|
519
524
|
const listRef = (0, react.useRef)(null);
|
|
520
525
|
const [rootIds, orphanIds, initialExpanded] = (0, react.useMemo)(() => Object.keys(data).reduce((acc, id) => {
|
|
521
526
|
const item = data[id];
|
|
@@ -680,12 +685,13 @@ const Tree = react.default.memo(function Tree({ isMain, refId, data, status, doc
|
|
|
680
685
|
}, [refId]);
|
|
681
686
|
const contentContainerStyle = (0, react.useMemo)(() => ({
|
|
682
687
|
marginTop: isMain && orphanIds.length > 0 ? 20 : 0,
|
|
683
|
-
paddingBottom: insets.bottom + 20,
|
|
688
|
+
paddingBottom: insets.bottom + drawerKeyboardInset + 20,
|
|
684
689
|
paddingLeft: 6
|
|
685
690
|
}), [
|
|
686
691
|
isMain,
|
|
687
692
|
orphanIds.length,
|
|
688
|
-
insets.bottom
|
|
693
|
+
insets.bottom,
|
|
694
|
+
drawerKeyboardInset
|
|
689
695
|
]);
|
|
690
696
|
(0, react.useLayoutEffect)(() => {
|
|
691
697
|
registerCallback(({ id: nextId, animated }) => {
|
|
@@ -1114,6 +1120,7 @@ const Result = react.default.memo(function Result({ item, matches, icon: _icon,
|
|
|
1114
1120
|
const Text$3 = _storybook_react_native_theming.styled.Text(({ theme }) => ({ color: theme.color.defaultText }));
|
|
1115
1121
|
const SearchResults = react.default.memo(function SearchResults({ query, results, closeMenu, getItemProps, highlightedIndex, clearLastViewed }) {
|
|
1116
1122
|
const insets = (0, react_native_safe_area_context.useSafeAreaInsets)();
|
|
1123
|
+
const drawerKeyboardInset = useDrawerKeyboardInset();
|
|
1117
1124
|
const handleClearLastViewed = (0, react.useCallback)(() => {
|
|
1118
1125
|
clearLastViewed();
|
|
1119
1126
|
closeMenu();
|
|
@@ -1121,8 +1128,8 @@ const SearchResults = react.default.memo(function SearchResults({ query, results
|
|
|
1121
1128
|
const contentContainerStyle = (0, react.useMemo)(() => ({
|
|
1122
1129
|
paddingHorizontal: 10,
|
|
1123
1130
|
paddingTop: 8,
|
|
1124
|
-
paddingBottom: insets.bottom + 20
|
|
1125
|
-
}), [insets.bottom]);
|
|
1131
|
+
paddingBottom: insets.bottom + drawerKeyboardInset + 20
|
|
1132
|
+
}), [insets.bottom, drawerKeyboardInset]);
|
|
1126
1133
|
const listData = (0, react.useMemo)(() => {
|
|
1127
1134
|
const items = [];
|
|
1128
1135
|
if (results.length > 0 && !query) items.push({
|
|
@@ -1518,50 +1525,29 @@ const portalContainerStyle = {
|
|
|
1518
1525
|
const useAnimatedModalHeight = () => {
|
|
1519
1526
|
const { height } = (0, react_native.useWindowDimensions)();
|
|
1520
1527
|
const modalHeight = .65 * height;
|
|
1521
|
-
const
|
|
1522
|
-
const [
|
|
1523
|
-
const
|
|
1524
|
-
const
|
|
1525
|
-
|
|
1526
|
-
setSheetHeight(modalHeight);
|
|
1527
|
-
setKeyboardInset(0);
|
|
1528
|
-
setIsKeyboardVisible(false);
|
|
1529
|
-
}, [modalHeight]);
|
|
1528
|
+
const maxKeyboardModalHeight = .75 * height;
|
|
1529
|
+
const [keyboardHeight, setKeyboardHeight] = (0, react.useState)(0);
|
|
1530
|
+
const isKeyboardVisible = keyboardHeight > 0;
|
|
1531
|
+
const sheetHeight = modalHeight + (isKeyboardVisible ? Math.min(keyboardHeight, maxKeyboardModalHeight - modalHeight) : 0);
|
|
1532
|
+
const keyboardInset = isKeyboardVisible ? keyboardHeight : 0;
|
|
1530
1533
|
(0, react.useEffect)(() => {
|
|
1531
1534
|
const expand = (keyboardHeight = 0) => {
|
|
1532
|
-
|
|
1533
|
-
const keyboardAvoidanceOffset = Math.min(keyboardHeight, maxKeyboardOffset);
|
|
1534
|
-
setIsKeyboardVisible(true);
|
|
1535
|
-
setSheetHeight(modalHeight + keyboardAvoidanceOffset);
|
|
1536
|
-
setKeyboardInset(Math.max(keyboardHeight - keyboardAvoidanceOffset, 0));
|
|
1535
|
+
setKeyboardHeight(keyboardHeight);
|
|
1537
1536
|
};
|
|
1538
1537
|
const collapse = () => {
|
|
1539
|
-
|
|
1540
|
-
setKeyboardInset(0);
|
|
1541
|
-
setIsKeyboardVisible(false);
|
|
1542
|
-
};
|
|
1543
|
-
const handleKeyboardWillShow = (e) => {
|
|
1544
|
-
if (react_native.Platform.OS === "ios") expand(e.endCoordinates.height);
|
|
1538
|
+
setKeyboardHeight(0);
|
|
1545
1539
|
};
|
|
1546
|
-
const
|
|
1547
|
-
|
|
1540
|
+
const handleKeyboardShow = (e) => {
|
|
1541
|
+
expand(e.endCoordinates.height);
|
|
1548
1542
|
};
|
|
1549
|
-
const
|
|
1550
|
-
|
|
1551
|
-
};
|
|
1552
|
-
const handleKeyboardDidHide = (e) => {
|
|
1553
|
-
if (react_native.Platform.OS === "android") collapse();
|
|
1543
|
+
const handleKeyboardHide = () => {
|
|
1544
|
+
collapse();
|
|
1554
1545
|
};
|
|
1555
|
-
const subscriptions = [
|
|
1556
|
-
react_native.Keyboard.addListener("keyboardWillShow", handleKeyboardWillShow),
|
|
1557
|
-
react_native.Keyboard.addListener("keyboardDidShow", handleKeyboardDidShow),
|
|
1558
|
-
react_native.Keyboard.addListener("keyboardWillHide", handleKeyboardWillHide),
|
|
1559
|
-
react_native.Keyboard.addListener("keyboardDidHide", handleKeyboardDidHide)
|
|
1560
|
-
];
|
|
1546
|
+
const subscriptions = [react_native.Keyboard.addListener(react_native.Platform.OS === "ios" ? "keyboardWillShow" : "keyboardDidShow", handleKeyboardShow), react_native.Keyboard.addListener(react_native.Platform.OS === "ios" ? "keyboardWillHide" : "keyboardDidHide", handleKeyboardHide)];
|
|
1561
1547
|
return () => {
|
|
1562
1548
|
subscriptions.forEach((subscription) => subscription.remove());
|
|
1563
1549
|
};
|
|
1564
|
-
}, [
|
|
1550
|
+
}, []);
|
|
1565
1551
|
return {
|
|
1566
1552
|
height: sheetHeight,
|
|
1567
1553
|
keyboardInset,
|
|
@@ -1681,9 +1667,8 @@ const MobileMenuDrawer = (0, react.memo)((0, react.forwardRef)(({ children, onVi
|
|
|
1681
1667
|
}), [theme.background.content]);
|
|
1682
1668
|
const childrenWrapperStyle = (0, react.useMemo)(() => ({
|
|
1683
1669
|
flex: 1,
|
|
1684
|
-
backgroundColor: theme.background.content
|
|
1685
|
-
|
|
1686
|
-
}), [keyboardInset, theme.background.content]);
|
|
1670
|
+
backgroundColor: theme.background.content
|
|
1671
|
+
}), [theme.background.content]);
|
|
1687
1672
|
const scrollToSelectedButtonWrapperStyle = (0, react.useMemo)(() => ({
|
|
1688
1673
|
position: "absolute",
|
|
1689
1674
|
right: 16,
|
|
@@ -1726,11 +1711,14 @@ const MobileMenuDrawer = (0, react.memo)((0, react.forwardRef)(({ children, onVi
|
|
|
1726
1711
|
style: dragHandleWrapperStyle,
|
|
1727
1712
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_native.View, { style: handleStyle })
|
|
1728
1713
|
}),
|
|
1729
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(
|
|
1730
|
-
|
|
1731
|
-
children
|
|
1714
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(DrawerKeyboardInsetContext.Provider, {
|
|
1715
|
+
value: keyboardInset,
|
|
1716
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_native.View, {
|
|
1717
|
+
style: childrenWrapperStyle,
|
|
1718
|
+
children
|
|
1719
|
+
})
|
|
1732
1720
|
}),
|
|
1733
|
-
showScrollToSelected ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_native.View, {
|
|
1721
|
+
showScrollToSelected && !isKeyboardVisible ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_native.View, {
|
|
1734
1722
|
style: scrollToSelectedButtonWrapperStyle,
|
|
1735
1723
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_storybook_react_native_ui_common.Button, {
|
|
1736
1724
|
text: "Scroll to selected",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/react-native-ui-lite",
|
|
3
|
-
"version": "10.4.
|
|
3
|
+
"version": "10.4.2-next.0",
|
|
4
4
|
"description": "lightweight ui components for react native storybook",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"@legendapp/list": "3.0.0-beta.38",
|
|
33
33
|
"@nozbe/microfuzz": "^1.0.0",
|
|
34
34
|
"@storybook/react": "^10.3.2",
|
|
35
|
-
"@storybook/react-native-theming": "^10.4.
|
|
36
|
-
"@storybook/react-native-ui-common": "^10.4.
|
|
35
|
+
"@storybook/react-native-theming": "^10.4.2-next.0",
|
|
36
|
+
"@storybook/react-native-ui-common": "^10.4.2-next.0",
|
|
37
37
|
"polished": "^4.3.1"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
package/src/MobileMenuDrawer.tsx
CHANGED
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
} from 'react-native';
|
|
26
26
|
|
|
27
27
|
import { useSelectedNode } from './SelectedNodeProvider';
|
|
28
|
+
import { DrawerKeyboardInsetContext } from './DrawerKeyboardInsetContext';
|
|
28
29
|
import useAnimatedValue from './useAnimatedValue';
|
|
29
30
|
|
|
30
31
|
const flexStyle: ViewStyle = { flex: 1 };
|
|
@@ -52,68 +53,47 @@ export interface MobileMenuDrawerRef {
|
|
|
52
53
|
export const useAnimatedModalHeight = () => {
|
|
53
54
|
const { height } = useWindowDimensions();
|
|
54
55
|
const modalHeight = 0.65 * height;
|
|
55
|
-
const
|
|
56
|
-
const [
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
setIsKeyboardVisible(false);
|
|
64
|
-
}, [modalHeight]);
|
|
56
|
+
const maxKeyboardModalHeight = 0.75 * height;
|
|
57
|
+
const [keyboardHeight, setKeyboardHeight] = useState(0);
|
|
58
|
+
const isKeyboardVisible = keyboardHeight > 0;
|
|
59
|
+
const keyboardAvoidanceOffset = isKeyboardVisible
|
|
60
|
+
? Math.min(keyboardHeight, maxKeyboardModalHeight - modalHeight)
|
|
61
|
+
: 0;
|
|
62
|
+
const sheetHeight = modalHeight + keyboardAvoidanceOffset;
|
|
63
|
+
const keyboardInset = isKeyboardVisible ? keyboardHeight : 0;
|
|
65
64
|
|
|
66
65
|
useEffect(() => {
|
|
67
66
|
const expand = (keyboardHeight: number = 0) => {
|
|
68
|
-
|
|
69
|
-
const keyboardAvoidanceOffset = Math.min(keyboardHeight, maxKeyboardOffset);
|
|
70
|
-
|
|
71
|
-
setIsKeyboardVisible(true);
|
|
72
|
-
setSheetHeight(modalHeight + keyboardAvoidanceOffset);
|
|
73
|
-
setKeyboardInset(Math.max(keyboardHeight - keyboardAvoidanceOffset, 0));
|
|
67
|
+
setKeyboardHeight(keyboardHeight);
|
|
74
68
|
};
|
|
75
69
|
|
|
76
70
|
const collapse = () => {
|
|
77
|
-
|
|
78
|
-
setKeyboardInset(0);
|
|
79
|
-
setIsKeyboardVisible(false);
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const handleKeyboardWillShow: KeyboardEventListener = (e) => {
|
|
83
|
-
if (Platform.OS === 'ios') {
|
|
84
|
-
expand(e.endCoordinates.height);
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
const handleKeyboardDidShow: KeyboardEventListener = (e) => {
|
|
89
|
-
if (Platform.OS === 'android') {
|
|
90
|
-
expand(e.endCoordinates.height);
|
|
91
|
-
}
|
|
71
|
+
setKeyboardHeight(0);
|
|
92
72
|
};
|
|
93
73
|
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
collapse();
|
|
97
|
-
}
|
|
74
|
+
const handleKeyboardShow: KeyboardEventListener = (e) => {
|
|
75
|
+
expand(e.endCoordinates.height);
|
|
98
76
|
};
|
|
99
77
|
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
collapse();
|
|
103
|
-
}
|
|
78
|
+
const handleKeyboardHide: KeyboardEventListener = () => {
|
|
79
|
+
collapse();
|
|
104
80
|
};
|
|
105
81
|
|
|
106
82
|
const subscriptions = [
|
|
107
|
-
Keyboard.addListener(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
83
|
+
Keyboard.addListener(
|
|
84
|
+
Platform.OS === 'ios' ? 'keyboardWillShow' : 'keyboardDidShow',
|
|
85
|
+
handleKeyboardShow
|
|
86
|
+
),
|
|
87
|
+
Keyboard.addListener(
|
|
88
|
+
Platform.OS === 'ios' ? 'keyboardWillHide' : 'keyboardDidHide',
|
|
89
|
+
handleKeyboardHide
|
|
90
|
+
),
|
|
111
91
|
];
|
|
112
92
|
|
|
113
93
|
return () => {
|
|
114
94
|
subscriptions.forEach((subscription) => subscription.remove());
|
|
115
95
|
};
|
|
116
|
-
}, [
|
|
96
|
+
}, []);
|
|
117
97
|
|
|
118
98
|
return {
|
|
119
99
|
height: sheetHeight,
|
|
@@ -271,9 +251,8 @@ export const MobileMenuDrawer = memo(
|
|
|
271
251
|
() => ({
|
|
272
252
|
flex: 1,
|
|
273
253
|
backgroundColor: theme.background.content,
|
|
274
|
-
paddingBottom: keyboardInset,
|
|
275
254
|
}),
|
|
276
|
-
[
|
|
255
|
+
[theme.background.content]
|
|
277
256
|
);
|
|
278
257
|
|
|
279
258
|
const scrollToSelectedButtonWrapperStyle = useMemo(
|
|
@@ -320,8 +299,10 @@ export const MobileMenuDrawer = memo(
|
|
|
320
299
|
<View style={handleStyle} />
|
|
321
300
|
</View>
|
|
322
301
|
|
|
323
|
-
<
|
|
324
|
-
|
|
302
|
+
<DrawerKeyboardInsetContext.Provider value={keyboardInset}>
|
|
303
|
+
<View style={childrenWrapperStyle}>{children}</View>
|
|
304
|
+
</DrawerKeyboardInsetContext.Provider>
|
|
305
|
+
{showScrollToSelected && !isKeyboardVisible ? (
|
|
325
306
|
<View style={scrollToSelectedButtonWrapperStyle}>
|
|
326
307
|
<Button
|
|
327
308
|
text="Scroll to selected"
|
package/src/SearchResults.tsx
CHANGED
|
@@ -11,6 +11,7 @@ import type { FC, PropsWithChildren, ReactNode } from 'react';
|
|
|
11
11
|
import React, { useCallback, useMemo } from 'react';
|
|
12
12
|
import { PressableProps, View, ViewStyle, TextStyle } from 'react-native';
|
|
13
13
|
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
14
|
+
import { useDrawerKeyboardInset } from './DrawerKeyboardInsetContext';
|
|
14
15
|
import { ComponentIcon, StoryIcon } from './icon/iconDataUris';
|
|
15
16
|
|
|
16
17
|
// Microfuzz highlight types
|
|
@@ -218,6 +219,7 @@ export const SearchResults: FC<{
|
|
|
218
219
|
clearLastViewed,
|
|
219
220
|
}) {
|
|
220
221
|
const insets = useSafeAreaInsets();
|
|
222
|
+
const drawerKeyboardInset = useDrawerKeyboardInset();
|
|
221
223
|
|
|
222
224
|
const handleClearLastViewed = useCallback(() => {
|
|
223
225
|
clearLastViewed();
|
|
@@ -228,9 +230,9 @@ export const SearchResults: FC<{
|
|
|
228
230
|
() => ({
|
|
229
231
|
paddingHorizontal: 10,
|
|
230
232
|
paddingTop: 8,
|
|
231
|
-
paddingBottom: insets.bottom + 20,
|
|
233
|
+
paddingBottom: insets.bottom + drawerKeyboardInset + 20,
|
|
232
234
|
}),
|
|
233
|
-
[insets.bottom]
|
|
235
|
+
[insets.bottom, drawerKeyboardInset]
|
|
234
236
|
);
|
|
235
237
|
|
|
236
238
|
const listData = useMemo<ListItemType[]>(() => {
|
package/src/Tree.tsx
CHANGED
|
@@ -15,6 +15,7 @@ import { View, ViewStyle } from 'react-native';
|
|
|
15
15
|
import { LegendList, LegendListRef, LegendListRenderItemProps } from './LegendList';
|
|
16
16
|
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
17
17
|
import { useSelectedNode } from './SelectedNodeProvider';
|
|
18
|
+
import { useDrawerKeyboardInset } from './DrawerKeyboardInsetContext';
|
|
18
19
|
import type {
|
|
19
20
|
ComponentEntry,
|
|
20
21
|
GroupEntry,
|
|
@@ -225,6 +226,7 @@ export const Tree = React.memo<{
|
|
|
225
226
|
const [pendingScrollTarget, setPendingScrollTarget] = useState<PendingScrollTarget | null>(null);
|
|
226
227
|
|
|
227
228
|
const insets = useSafeAreaInsets();
|
|
229
|
+
const drawerKeyboardInset = useDrawerKeyboardInset();
|
|
228
230
|
const listRef = useRef<LegendListRef | null>(null);
|
|
229
231
|
// Find top-level nodes and group them so we can hoist any orphans and expand any roots.
|
|
230
232
|
const [rootIds, orphanIds, initialExpanded] = useMemo(
|
|
@@ -434,10 +436,10 @@ export const Tree = React.memo<{
|
|
|
434
436
|
const contentContainerStyle = useMemo(
|
|
435
437
|
() => ({
|
|
436
438
|
marginTop: isMain && orphanIds.length > 0 ? 20 : 0,
|
|
437
|
-
paddingBottom: insets.bottom + 20,
|
|
439
|
+
paddingBottom: insets.bottom + drawerKeyboardInset + 20,
|
|
438
440
|
paddingLeft: 6,
|
|
439
441
|
}),
|
|
440
|
-
[isMain, orphanIds.length, insets.bottom]
|
|
442
|
+
[isMain, orphanIds.length, insets.bottom, drawerKeyboardInset]
|
|
441
443
|
);
|
|
442
444
|
|
|
443
445
|
// so we can call the scroll to function in the search component
|