Skip to content

Commit 629acd3

Browse files
committed
chore: Clean up storybook and lightning
- A little more straightforward to create react-lightning apps - Fixes issues with multiple instances of react-lightning (eg for storybook) - Fixes storybook stories logging multiple renderer errors Note: lightning renderer beta14 seems to have issues with multiple instances of lightning rendering text with multiple renderers. When using storybook you'll need to refresh the page each time to fix text rendering for now.
1 parent 3acf225 commit 629acd3

46 files changed

Lines changed: 606 additions & 1054 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/react-lightning-example/src/components/Button.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const containerStyles: LightningElementStyle = {
1111
w: 330,
1212
h: 100,
1313
borderRadius: 15,
14-
border: { width: 3, color: 0xffffffff },
14+
border: { w: 3, color: 0xffffffff },
1515
display: 'flex' as const,
1616
justifyContent: 'center' as const,
1717
alignItems: 'center' as const,

‎apps/react-lightning-example/src/index.tsx‎

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
import {
2-
Canvas,
3-
createRoot as createRootLng,
4-
type RenderOptions,
5-
} from '@plextv/react-lightning';
1+
import { Canvas, type RenderOptions } from '@plextv/react-lightning';
62
import { plugin as cssTransformPlugin } from '@plextv/react-lightning-plugin-css-transform';
73
import { plugin as flexPlugin } from '@plextv/react-lightning-plugin-flexbox';
8-
import { createRoot as createRootDom } from 'react-dom/client';
4+
import { createRoot } from 'react-dom/client';
95
import { createBrowserRouter, RouterProvider } from 'react-router-dom';
106
import { keyMap } from './keyMap';
117
import { AnimationPage } from './pages/AnimationPage';
@@ -70,7 +66,7 @@ const options: RenderOptions = {
7066
},
7167
],
7268
numImageWorkers: window.navigator.hardwareConcurrency || 2,
73-
plugins: [cssTransformPlugin(), flexPlugin()],
69+
plugins: [cssTransformPlugin(), flexPlugin({ useWebWorker: true })],
7470
shaders: [
7571
'Border',
7672
'Shadow',
@@ -85,8 +81,6 @@ const options: RenderOptions = {
8581
},
8682
};
8783

88-
const lngAsRoot = true;
89-
9084
const App = () => (
9185
<Canvas keyMap={keyMap} options={options}>
9286
<RouterProvider router={router} />
@@ -99,14 +93,4 @@ if (!appElement) {
9993
throw new Error('No app element found');
10094
}
10195

102-
if (lngAsRoot) {
103-
createRootLng(appElement, options)
104-
.then((root) => {
105-
root.render(<App />);
106-
})
107-
.catch((error) => {
108-
console.error(error);
109-
});
110-
} else {
111-
createRootDom(appElement).render(<App />);
112-
}
96+
createRoot(appElement).render(<App />);

‎apps/react-lightning-example/src/pages/Page60.tsx‎

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export const Question = ({
2929
fontSize: 48,
3030
maxLines: 3,
3131
textAlign: 'center',
32-
autosize: false,
3332
h: TEXT_HEIGHT,
3433
y: TEXT_HEIGHT / 2,
3534
maxWidth: w,
@@ -58,31 +57,29 @@ export const Page60 = () => {
5857
}, []);
5958

6059
return (
61-
<>
62-
<Column
63-
focusable
64-
style={{
65-
gap: 20,
66-
zIndex: 10,
67-
position: 'absolute',
68-
top: 0,
69-
left: 0,
70-
w: 1920,
71-
h: 1080,
72-
justifyContent: 'center',
73-
alignItems: 'center',
74-
}}
75-
>
76-
<Row style={{ gap: 20 }}>
77-
<Button onPress={addText}>Add text</Button>
78-
<Button onPress={reduceW}>Shrink</Button>
79-
<Button onPress={increaseW}>Grow</Button>
80-
</Row>
60+
<Column
61+
focusable
62+
style={{
63+
gap: 20,
64+
zIndex: 10,
65+
position: 'absolute',
66+
top: 0,
67+
left: 0,
68+
w: 1920,
69+
h: 1080,
70+
justifyContent: 'center',
71+
alignItems: 'center',
72+
}}
73+
>
74+
<Row style={{ gap: 20 }}>
75+
<Button onPress={addText}>Add text</Button>
76+
<Button onPress={reduceW}>Shrink</Button>
77+
<Button onPress={increaseW}>Grow</Button>
78+
</Row>
8179

82-
<Question text={text} w={w} />
83-
<Question text="This is a multi line test. Lorem ipsum dolor sit amet, consectetur adipiscing elit." />
84-
<Question text="This is a truncation test. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam arcu sem, placerat eu egestas eu, rutrum id neque. Integer rhoncus faucibus ante a tempor. Fusce mollis est sit amet nunc fermentum, ut pellentesque nisl ultrices. Duis ac dolor sed odio feugiat venenatis in ut est. Proin tincidunt posuere accumsan. Etiam lobortis ultrices bibendum. Vivamus consectetur nulla quis mollis aliquet. Nam scelerisque justo in nibh ornare, eu dapibus quam pulvinar. In a libero placerat, sagittis ante quis, maximus turpis. Proin neque eros, eleifend vel est hendrerit, pharetra laoreet nibh. Donec sed urna eu mi iaculis sollicitudin eu in ante. Aliquam ultrices blandit sem, eget suscipit ipsum bibendum in. Fusce nec lorem id dui interdum vestibulum." />
85-
</Column>
86-
</>
80+
<Question text={text} w={w} />
81+
<Question text="This is a multi line test. Lorem ipsum dolor sit amet, consectetur adipiscing elit." />
82+
<Question text="This is a truncation test. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam arcu sem, placerat eu egestas eu, rutrum id neque. Integer rhoncus faucibus ante a tempor. Fusce mollis est sit amet nunc fermentum, ut pellentesque nisl ultrices. Duis ac dolor sed odio feugiat venenatis in ut est. Proin tincidunt posuere accumsan. Etiam lobortis ultrices bibendum. Vivamus consectetur nulla quis mollis aliquet. Nam scelerisque justo in nibh ornare, eu dapibus quam pulvinar. In a libero placerat, sagittis ante quis, maximus turpis. Proin neque eros, eleifend vel est hendrerit, pharetra laoreet nibh. Donec sed urna eu mi iaculis sollicitudin eu in ante. Aliquam ultrices blandit sem, eget suscipit ipsum bibendum in. Fusce nec lorem id dui interdum vestibulum." />
83+
</Column>
8784
);
8885
};

‎apps/react-lightning-example/src/pages/ShaderPage.tsx‎

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,27 @@ import { Column } from '@plextv/react-lightning-components';
22

33
export const ShaderPage = () => {
44
return (
5-
<>
6-
<Column
7-
focusable
8-
style={{
9-
gap: 20,
10-
zIndex: 10,
11-
position: 'absolute',
12-
top: 0,
13-
left: 0,
14-
w: 1920,
15-
h: 1080,
16-
justifyContent: 'center',
17-
alignItems: 'center',
5+
<Column
6+
focusable
7+
style={{
8+
gap: 20,
9+
zIndex: 10,
10+
position: 'absolute',
11+
top: 0,
12+
left: 0,
13+
w: 1920,
14+
h: 1080,
15+
justifyContent: 'center',
16+
alignItems: 'center',
17+
}}
18+
>
19+
<lng-view
20+
shader={{
21+
type: 'MyCustomShader',
22+
props: {},
1823
}}
19-
>
20-
<lng-view
21-
shader={{
22-
type: 'MyCustomShader',
23-
props: {},
24-
}}
25-
style={{ w: 300, h: 300 }}
26-
/>
27-
</Column>
28-
</>
24+
style={{ w: 300, h: 300 }}
25+
/>
26+
</Column>
2927
);
3028
};

‎apps/react-lightning-example/src/pages/TexturePage.tsx‎

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,31 @@ import { Column } from '@plextv/react-lightning-components';
22

33
export const TexturePage = () => {
44
return (
5-
<>
6-
<Column
7-
focusable
8-
style={{
9-
gap: 20,
10-
zIndex: 10,
11-
position: 'absolute',
12-
top: 0,
13-
left: 0,
14-
w: 1920,
15-
h: 1080,
16-
justifyContent: 'center',
17-
alignItems: 'center',
5+
<Column
6+
focusable
7+
style={{
8+
gap: 20,
9+
zIndex: 10,
10+
position: 'absolute',
11+
top: 0,
12+
left: 0,
13+
w: 1920,
14+
h: 1080,
15+
justifyContent: 'center',
16+
alignItems: 'center',
17+
}}
18+
>
19+
<lng-view
20+
texture={{
21+
type: 'MyCustomTexture',
22+
props: {
23+
percent: 55,
24+
w: 300,
25+
h: 300,
26+
},
1827
}}
19-
>
20-
<lng-view
21-
texture={{
22-
type: 'MyCustomTexture',
23-
props: {
24-
percent: 55,
25-
w: 300,
26-
h: 300,
27-
},
28-
}}
29-
style={{ w: 300, h: 300, color: 0xe5a00dff }}
30-
/>
31-
</Column>
32-
</>
28+
style={{ w: 300, h: 300, color: 0xe5a00dff }}
29+
/>
30+
</Column>
3331
);
3432
};

‎apps/react-native-lightning-example/package.json‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
"type": "module",
1616
"private": true,
1717
"scripts": {
18-
"build": "react-native build-lightning",
18+
"build": "vite build",
1919
"clean": "del ./dist",
20-
"dev": "react-native run-lightning",
21-
"preview": "react-native preview-lightning",
20+
"dev": "vite --host",
21+
"preview": "vite preview --host --port 3333",
2222
"test:unit": "vitest run --passWithNoTests"
2323
},
2424
"dependencies": {
@@ -40,10 +40,10 @@
4040
"@plextv/vite-plugin-msdf-fontgen": "workspace:*",
4141
"@plextv/vite-plugin-react-native-lightning": "workspace:*",
4242
"@plextv/vite-plugin-react-reanimated-lightning": "workspace:*",
43-
"@react-native-community/cli": "15.1.3",
4443
"@repo/typescript-config": "workspace:*",
4544
"@shopify/flash-list": "1.8.3",
4645
"@types/react": "18.3.14",
46+
"@types/react-dom": "18.3.1",
4747
"@vitejs/plugin-legacy": "^7.0.0",
4848
"typescript": "5.8.3"
4949
},
@@ -53,7 +53,6 @@
5353
"//": "unsure why react-dom needed to be ignored...",
5454
"depcheck": {
5555
"ignoreMatches": [
56-
"@react-native-community/cli",
5756
"typescript",
5857
"react-dom"
5958
]

‎apps/react-native-lightning-example/src/index.tsx‎

Lines changed: 56 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { Canvas, type RenderOptions } from '@plextv/react-lightning';
1+
import { Canvas } from '@plextv/react-lightning';
22
import { Column, Row } from '@plextv/react-lightning-components';
33
import '@plextv/react-lightning-plugin-flexbox/jsx';
4+
import { getReactNativePlugins } from '@plextv/react-native-lightning';
45
import type { LinkingOptions } from '@react-navigation/native';
56
import {
67
createNavigatorFactory,
@@ -10,7 +11,8 @@ import {
1011
useNavigation,
1112
useNavigationBuilder,
1213
} from '@react-navigation/native';
13-
import { AppRegistry, Button } from 'react-native';
14+
import { createRoot } from 'react-dom/client';
15+
import { Button } from 'react-native';
1416
import { ErrorBoundary } from './ErrorBoundary';
1517
import { keyMap } from './keyMap';
1618
import { AnimationBuilderTest } from './pages/AnimationBuilderTest';
@@ -160,7 +162,51 @@ const MainApp = () => {
160162
const App = () => {
161163
return (
162164
<ErrorBoundary>
163-
<Canvas keyMap={keyMap}>
165+
<Canvas
166+
keyMap={keyMap}
167+
options={{
168+
numImageWorkers: window.navigator.hardwareConcurrency - 1 || 2,
169+
fonts: [
170+
{
171+
type: 'sdf',
172+
fontFamily: 'sans-serif',
173+
atlasUrl: '/fonts/Ubuntu-Bold.msdf.png',
174+
atlasDataUrl: '/fonts/Ubuntu-Bold.msdf.json',
175+
metrics: {
176+
ascender: 776,
177+
descender: -185,
178+
lineGap: 56,
179+
unitsPerEm: 1000,
180+
},
181+
},
182+
{
183+
type: 'sdf',
184+
fontFamily: 'sans-serif',
185+
atlasUrl: '/fonts/Ubuntu-Regular.msdf.png',
186+
atlasDataUrl: '/fonts/Ubuntu-Regular.msdf.json',
187+
metrics: {
188+
ascender: 776,
189+
descender: -185,
190+
lineGap: 56,
191+
unitsPerEm: 1000,
192+
},
193+
},
194+
],
195+
plugins: getReactNativePlugins([], {
196+
flexbox: {
197+
useWebWorker: true,
198+
},
199+
}),
200+
shaders: [
201+
'Border',
202+
'Shadow',
203+
'Rounded',
204+
'RoundedWithBorder',
205+
'RoundedWithShadow',
206+
'RoundedWithBorderAndShadow',
207+
],
208+
}}
209+
>
164210
<NavigationContainer linking={linking} theme={DarkTheme}>
165211
<MainApp />
166212
</NavigationContainer>
@@ -169,50 +215,10 @@ const App = () => {
169215
);
170216
};
171217

172-
AppRegistry.registerComponent('plex', () => App);
173-
AppRegistry.runApplication('plex', {
174-
rootId: 'app',
175-
renderOptions: {
176-
driver: 'normal',
177-
numImageWorkers: window.navigator.hardwareConcurrency - 1 || 2,
178-
fonts: [
179-
{
180-
type: 'sdf',
181-
fontFamily: 'sans-serif',
182-
atlasUrl: '/fonts/Ubuntu-Bold.msdf.png',
183-
atlasDataUrl: '/fonts/Ubuntu-Bold.msdf.json',
184-
metrics: {
185-
ascender: 776,
186-
descender: -185,
187-
lineGap: 56,
188-
unitsPerEm: 1000,
189-
},
190-
},
191-
{
192-
type: 'sdf',
193-
fontFamily: 'sans-serif',
194-
atlasUrl: '/fonts/Ubuntu-Regular.msdf.png',
195-
atlasDataUrl: '/fonts/Ubuntu-Regular.msdf.json',
196-
metrics: {
197-
ascender: 776,
198-
descender: -185,
199-
lineGap: 56,
200-
unitsPerEm: 1000,
201-
},
202-
},
203-
],
204-
shaders: [
205-
'Border',
206-
'Shadow',
207-
'Rounded',
208-
'RoundedWithBorder',
209-
'RoundedWithShadow',
210-
'RoundedWithBorderAndShadow',
211-
],
212-
} as RenderOptions,
213-
pluginOptions: {
214-
flexbox: {
215-
useWebWorker: true,
216-
},
217-
},
218-
});
218+
const appElement = document.getElementById('app');
219+
220+
if (!appElement) {
221+
throw new Error('No app element found');
222+
}
223+
224+
createRoot(appElement).render(<App />);

0 commit comments

Comments
 (0)