Skip to content

Commit a13f421

Browse files
authored
fix: add LegendList wrapper to use react entrypoint on web (#859)
* fix: add LegendList wrapper to use react entrypoint on web Create a LegendList wrapper component that uses @legendapp/list/react on web and @legendapp/list/react-native on native via a runtime Platform check. This removes the need for @ts-ignore comments in Tree.tsx and SearchResults.tsx. * changeset
1 parent 399e347 commit a13f421

7 files changed

Lines changed: 39 additions & 41 deletions

File tree

.changeset/polite-brooms-decide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@storybook/react-native-ui-lite': patch
3+
---
4+
5+
feat: use legend list react for web

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@
6161
"markdown-it": "^14.0.0",
6262
"@types/markdown-it": "^14.0.1",
6363
"zod-validation-error": "^4.0.0",
64-
"minimatch@3": "~3.1.3"
64+
"minimatch@3": "~3.1.3",
65+
"serialize-javascript": ">=7.0.3"
6566
}
6667
},
6768
"engines": {

packages/react-native-ui-lite/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
},
4242
"dependencies": {
4343
"@gorhom/portal": "^1.0.14",
44-
"@legendapp/list": "3.0.0-beta.31",
44+
"@legendapp/list": "3.0.0-beta.38",
4545
"@nozbe/microfuzz": "^1.0.0",
4646
"@storybook/react": "10.3.0-alpha.12",
4747
"@storybook/react-native-theming": "^10.3.0-next.3",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { LegendList as LegendListWeb } from '@legendapp/list/react';
2+
import {
3+
LegendList as LegendListNative,
4+
LegendListRef as LegendListRefNative,
5+
LegendListRenderItemProps as LegendListRenderItemPropsNative,
6+
} from '@legendapp/list/react-native';
7+
import { Platform } from 'react-native';
8+
9+
export type LegendListRenderItemProps<T> = LegendListRenderItemPropsNative<T>;
10+
export type LegendListRef = LegendListRefNative;
11+
12+
const isWeb = Platform.OS === 'web';
13+
14+
export const LegendList = (isWeb ? LegendListWeb : LegendListNative) as typeof LegendListNative;

packages/react-native-ui-lite/src/SearchResults.tsx

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { LegendList } from '@legendapp/list';
1+
import { LegendList } from './LegendList';
22
import { styled, useTheme } from '@storybook/react-native-theming';
33
import type {
44
GetSearchItemProps,
@@ -9,12 +9,10 @@ import { Button, IconButton, isExpandType, ExpandType } from '@storybook/react-n
99
import { transparentize } from 'polished';
1010
import type { FC, PropsWithChildren, ReactNode } from 'react';
1111
import React, { useCallback, useMemo } from 'react';
12-
import { Platform, PressableProps, View, ViewStyle, TextStyle } from 'react-native';
12+
import { PressableProps, View, ViewStyle, TextStyle } from 'react-native';
1313
import { useSafeAreaInsets } from 'react-native-safe-area-context';
1414
import { ComponentIcon, StoryIcon } from './icon/iconDataUris';
1515

16-
const isWeb = Platform.OS === 'web';
17-
1816
// Microfuzz highlight types
1917
type HighlightRange = [number, number];
2018
type HighlightRanges = HighlightRange[];
@@ -327,19 +325,6 @@ export const SearchResults: FC<{
327325
[getItemProps, highlightedIndex]
328326
);
329327

330-
// On web, use a simple scrollable div to avoid LegendList web infinite update stack
331-
if (isWeb) {
332-
return (
333-
<View style={flexStyle}>
334-
<div style={{ flex: 1, overflow: 'auto', ...contentContainerStyle }}>
335-
{listData.map((item) => (
336-
<div key={keyExtractor(item)}>{renderItem({ item })}</div>
337-
))}
338-
</div>
339-
</View>
340-
);
341-
}
342-
343328
return (
344329
<View style={flexStyle}>
345330
<LegendList

packages/react-native-ui-lite/src/Tree.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
} from '@storybook/react-native-ui-common';
1313
import React, { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
1414
import { View, ViewStyle } from 'react-native';
15-
import { LegendList, LegendListRef, LegendListRenderItemProps } from '@legendapp/list';
15+
import { LegendList, LegendListRef, LegendListRenderItemProps } from './LegendList';
1616
import { useSafeAreaInsets } from 'react-native-safe-area-context';
1717
import { useSelectedNode } from './SelectedNodeProvider';
1818
import type {

pnpm-lock.yaml

Lines changed: 14 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)