@storybook/react-native-ui 8.5.5-alpha.3 → 8.5.5

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 CHANGED
@@ -3487,19 +3487,37 @@ var import_jsx_runtime11 = require("react/jsx-runtime");
3487
3487
  var SelectedNodeContext = (0, import_react9.createContext)({
3488
3488
  nodeRef: { current: null },
3489
3489
  setNodeRef: () => {
3490
- }
3490
+ },
3491
+ scrollToSelectedNode: () => {
3492
+ },
3493
+ scrollRef: null
3491
3494
  });
3492
3495
  var SelectedNodeProvider = ({ children }) => {
3493
3496
  const nodeRef = (0, import_react9.useRef)(null);
3494
3497
  const setNodeRef = (0, import_react9.useCallback)((node) => {
3495
3498
  nodeRef.current = node;
3496
3499
  }, []);
3500
+ const scrollRef = (0, import_react9.useRef)(null);
3501
+ const scrollToSelectedNode = (0, import_react9.useCallback)(() => {
3502
+ setTimeout(() => {
3503
+ if (nodeRef?.current && scrollRef?.current) {
3504
+ try {
3505
+ nodeRef.current.measureLayout?.(scrollRef.current, (_x, y) => {
3506
+ scrollRef.current?.scrollTo({ y: y - 100, animated: true });
3507
+ });
3508
+ } catch (error) {
3509
+ }
3510
+ }
3511
+ }, 500);
3512
+ }, []);
3497
3513
  return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3498
3514
  SelectedNodeContext.Provider,
3499
3515
  {
3500
3516
  value: {
3501
3517
  nodeRef,
3502
- setNodeRef
3518
+ setNodeRef,
3519
+ scrollToSelectedNode,
3520
+ scrollRef
3503
3521
  },
3504
3522
  children
3505
3523
  }
@@ -4077,14 +4095,16 @@ var Search = import_react15.default.memo(function Search2({ children, dataset, s
4077
4095
  const [isOpen, setIsOpen] = (0, import_react15.useState)(false);
4078
4096
  const [allComponents, showAllComponents] = (0, import_react15.useState)(false);
4079
4097
  const { isMobile } = useLayout();
4098
+ const { scrollToSelectedNode } = useSelectedNode();
4080
4099
  const selectStory = (0, import_react15.useCallback)(
4081
4100
  (id, refId) => {
4082
4101
  setSelection({ storyId: id, refId });
4083
4102
  inputRef.current?.blur();
4084
4103
  setIsOpen(false);
4085
4104
  showAllComponents(false);
4105
+ scrollToSelectedNode();
4086
4106
  },
4087
- [setSelection]
4107
+ [scrollToSelectedNode, setSelection]
4088
4108
  );
4089
4109
  const getItemProps = (0, import_react15.useCallback)(
4090
4110
  ({ item: result }) => {
@@ -4761,23 +4781,13 @@ var MobileMenuDrawer = (0, import_react22.memo)(
4761
4781
  const reducedMotion = (0, import_react_native_reanimated2.useReducedMotion)();
4762
4782
  const insets = (0, import_react_native_safe_area_context2.useSafeAreaInsets)();
4763
4783
  const theme = (0, import_react_native_theming14.useTheme)();
4764
- const scrollRef = (0, import_react22.useRef)(null);
4765
4784
  const menuBottomSheetRef = (0, import_react22.useRef)(null);
4766
- const { nodeRef } = useSelectedNode();
4785
+ const { scrollToSelectedNode, scrollRef } = useSelectedNode();
4767
4786
  (0, import_react22.useImperativeHandle)(ref, () => ({
4768
4787
  setMobileMenuOpen: (open) => {
4769
4788
  if (open) {
4770
4789
  menuBottomSheetRef.current?.snapToIndex(1);
4771
- setTimeout(() => {
4772
- if (nodeRef?.current) {
4773
- try {
4774
- nodeRef.current.measureLayout?.(scrollRef.current, (_x, y) => {
4775
- scrollRef.current?.scrollTo({ y: y - 100, animated: true });
4776
- });
4777
- } catch (error) {
4778
- }
4779
- }
4780
- }, 500);
4790
+ scrollToSelectedNode();
4781
4791
  } else {
4782
4792
  import_react_native7.Keyboard.dismiss();
4783
4793
  menuBottomSheetRef.current?.close();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/react-native-ui",
3
- "version": "8.5.5-alpha.3",
3
+ "version": "8.5.5",
4
4
  "description": "ui components for react native storybook",
5
5
  "keywords": [
6
6
  "react",
@@ -60,7 +60,7 @@
60
60
  "dependencies": {
61
61
  "@storybook/core": "^8.5.1",
62
62
  "@storybook/react": "^8.5.1",
63
- "@storybook/react-native-theming": "^8.5.5-alpha.3",
63
+ "@storybook/react-native-theming": "^8.5.5",
64
64
  "fuse.js": "^7.0.0",
65
65
  "memoizerific": "^1.11.3",
66
66
  "polished": "^4.3.1",
@@ -81,5 +81,5 @@
81
81
  "publishConfig": {
82
82
  "access": "public"
83
83
  },
84
- "gitHead": "2a5a124d6646c080d72298e0fb12d8f28c85b412"
84
+ "gitHead": "08be202a23cb2490d295c6c3476d414163b8d40e"
85
85
  }
@@ -3,7 +3,6 @@ import BottomSheet, {
3
3
  BottomSheetBackdropProps,
4
4
  BottomSheetScrollView,
5
5
  } from '@gorhom/bottom-sheet';
6
- import { BottomSheetScrollViewMethods } from '@gorhom/bottom-sheet/lib/typescript/components/bottomSheetScrollable/types';
7
6
  import { useTheme } from '@storybook/react-native-theming';
8
7
  import { forwardRef, memo, ReactNode, useImperativeHandle, useMemo, useRef } from 'react';
9
8
  import { Keyboard } from 'react-native';
@@ -36,26 +35,15 @@ export const MobileMenuDrawer = memo(
36
35
  const reducedMotion = useReducedMotion();
37
36
  const insets = useSafeAreaInsets();
38
37
  const theme = useTheme();
39
- const scrollRef = useRef<BottomSheetScrollViewMethods>(null);
40
38
  const menuBottomSheetRef = useRef<BottomSheet>(null);
41
- const { nodeRef } = useSelectedNode();
39
+ const { scrollToSelectedNode, scrollRef } = useSelectedNode();
42
40
 
43
41
  useImperativeHandle(ref, () => ({
44
42
  setMobileMenuOpen: (open: boolean) => {
45
43
  if (open) {
46
44
  menuBottomSheetRef.current?.snapToIndex(1);
47
45
 
48
- setTimeout(() => {
49
- if (nodeRef?.current) {
50
- // im just not sure if older versions would error here,
51
- // since measure layout probably changed since new arch
52
- try {
53
- nodeRef.current.measureLayout?.(scrollRef.current as any, (_x, y) => {
54
- scrollRef.current?.scrollTo({ y: y - 100, animated: true });
55
- });
56
- } catch (error) {}
57
- }
58
- }, 500);
46
+ scrollToSelectedNode();
59
47
  } else {
60
48
  Keyboard.dismiss();
61
49
 
package/src/Search.tsx CHANGED
@@ -18,6 +18,7 @@ import {
18
18
  } from './types';
19
19
  import { getGroupStatus, getHighestStatus } from './util/status';
20
20
  import { searchItem } from './util/tree';
21
+ import { useSelectedNode } from './SelectedNodeProvider';
21
22
 
22
23
  const DEFAULT_MAX_SEARCH_RESULTS = 50;
23
24
 
@@ -111,6 +112,7 @@ export const Search = React.memo<{
111
112
  const [isOpen, setIsOpen] = useState(false);
112
113
  const [allComponents, showAllComponents] = useState(false);
113
114
  const { isMobile } = useLayout();
115
+ const { scrollToSelectedNode } = useSelectedNode();
114
116
 
115
117
  const selectStory = useCallback(
116
118
  (id: string, refId: string) => {
@@ -121,8 +123,10 @@ export const Search = React.memo<{
121
123
  setIsOpen(false);
122
124
 
123
125
  showAllComponents(false);
126
+
127
+ scrollToSelectedNode();
124
128
  },
125
- [setSelection]
129
+ [scrollToSelectedNode, setSelection]
126
130
  );
127
131
 
128
132
  const getItemProps: GetSearchItemProps = useCallback(
@@ -1,3 +1,4 @@
1
+ import { BottomSheetScrollViewMethods } from '@gorhom/bottom-sheet/lib/typescript/components/bottomSheetScrollable/types';
1
2
  import type { FC, PropsWithChildren } from 'react';
2
3
  import { createContext, useCallback, useContext, useRef } from 'react';
3
4
  import type { View } from 'react-native';
@@ -5,11 +6,15 @@ import type { View } from 'react-native';
5
6
  type SelectedNodeContextType = {
6
7
  nodeRef: React.RefObject<View>;
7
8
  setNodeRef: (node: View | null) => void;
9
+ scrollToSelectedNode: () => void;
10
+ scrollRef: React.RefObject<BottomSheetScrollViewMethods>;
8
11
  };
9
12
 
10
13
  const SelectedNodeContext = createContext<SelectedNodeContextType>({
11
14
  nodeRef: { current: null },
12
15
  setNodeRef: () => {},
16
+ scrollToSelectedNode: () => {},
17
+ scrollRef: null,
13
18
  });
14
19
 
15
20
  export const SelectedNodeProvider: FC<PropsWithChildren> = ({ children }) => {
@@ -19,11 +24,30 @@ export const SelectedNodeProvider: FC<PropsWithChildren> = ({ children }) => {
19
24
  nodeRef.current = node;
20
25
  }, []);
21
26
 
27
+ const scrollRef = useRef<BottomSheetScrollViewMethods>(null);
28
+
29
+ const scrollToSelectedNode = useCallback(() => {
30
+ // maybe later we can improve on this to not use setTimeout but right now it seems like the simplest solution
31
+ setTimeout(() => {
32
+ if (nodeRef?.current && scrollRef?.current) {
33
+ // im just not sure if older versions would error here,
34
+ // since measure layout probably changed since new arch
35
+ try {
36
+ nodeRef.current.measureLayout?.(scrollRef.current as any, (_x, y) => {
37
+ scrollRef.current?.scrollTo({ y: y - 100, animated: true });
38
+ });
39
+ } catch (error) {}
40
+ }
41
+ }, 500);
42
+ }, []);
43
+
22
44
  return (
23
45
  <SelectedNodeContext.Provider
24
46
  value={{
25
47
  nodeRef,
26
48
  setNodeRef,
49
+ scrollToSelectedNode,
50
+ scrollRef,
27
51
  }}
28
52
  >
29
53
  {children}