Skip to content

Commit a97be20

Browse files
fix(example): add web script and fix benchmark crash on web (#13)
- Add `web` script to example package.json - Add .web stub for frame-metrics module (no-op on web) - Hide benchmark demo from example index on web
1 parent 9f324c7 commit a97be20

3 files changed

Lines changed: 33 additions & 5 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export type FrameMetricsResult = {
2+
avgUiThreadTime: number;
3+
p95UiThreadTime: number;
4+
p99UiThreadTime: number;
5+
avgAnimationTime?: number;
6+
avgLayoutTime?: number;
7+
avgDrawTime?: number;
8+
};
9+
10+
export const isAndroid = false;
11+
12+
export function startCollecting(): void {
13+
// no-op on web
14+
}
15+
16+
export function stopCollecting(): FrameMetricsResult {
17+
return {
18+
avgUiThreadTime: 0,
19+
p95UiThreadTime: 0,
20+
p99UiThreadTime: 0,
21+
};
22+
}

example/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"android": "expo run:android",
88
"ios": "expo run:ios",
99
"start": "expo start",
10+
"web": "expo start --web",
1011
"prebuild": "expo prebuild",
1112
"build:android": "expo prebuild --platform android --clean && cd android && ./gradlew assembleDebug --no-daemon --console=plain -PreactNativeArchitectures=arm64-v8a",
1213
"build:ios": "expo prebuild --platform ios --clean && xcodebuild -workspace ios/EaseExample.xcworkspace -scheme EaseExample -configuration Debug -sdk iphonesimulator -arch x86_64 build"

example/src/demos/index.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { ComponentType } from 'react';
2+
import { Platform } from 'react-native';
23

34
import { BackgroundColorDemo } from './BackgroundColorDemo';
45
import { BenchmarkDemo } from './BenchmarkDemo';
@@ -79,11 +80,15 @@ export const demos: Record<string, DemoEntry> = {
7980
title: 'Comparison',
8081
section: 'Advanced',
8182
},
82-
'benchmark': {
83-
component: BenchmarkDemo,
84-
title: 'Benchmark',
85-
section: 'Advanced',
86-
},
83+
...(Platform.OS !== 'web'
84+
? {
85+
benchmark: {
86+
component: BenchmarkDemo,
87+
title: 'Benchmark',
88+
section: 'Advanced',
89+
},
90+
}
91+
: {}),
8792
};
8893

8994
interface SectionData {

0 commit comments

Comments
 (0)