Skip to content

Commit fcf7f57

Browse files
committed
fix(expo): add start:go script and improve system UI theme handling
1 parent 2f37561 commit fcf7f57

5 files changed

Lines changed: 41 additions & 12 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": "1.0.0",
55
"scripts": {
66
"start": "expo start --dev-client",
7+
"start:go": "expo start --go",
78
"prebuild": "expo prebuild",
89
"build": "node ./scripts/prebuild.js",
910
"android": "expo run:android",

src/app/_layout.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import * as Haptics from 'expo-haptics';
44
import { Stack, useRootNavigationState } from 'expo-router';
55
import * as React from 'react';
66
import { Appearance, Platform, View } from 'react-native';
7-
import { SystemBars } from 'react-native-edge-to-edge';
87
import { GestureHandlerRootView } from 'react-native-gesture-handler';
98
import { SafeAreaProvider } from 'react-native-safe-area-context';
109
import WebView from 'react-native-webview';
@@ -86,8 +85,6 @@ export default function RootLayout() {
8685
Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light)
8786
}
8887
>
89-
{/* 系统状态栏和导航栏管理 */}
90-
<SystemBars style="auto" />
9188
{/* Provider 中带有 Portal,没有 Provider,Toast 和 Modal 会失效,误删 */}
9289
{/* FIX_ME 自建 portal 组件,支持自定义 Toast Modal */}
9390
{/* 手势检测 */}

src/hooks/useJPush.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as Notifications from 'expo-notifications';
1+
import { isRunningInExpoGo } from 'expo';
22
import { router } from 'expo-router';
33
import { useEffect } from 'react';
44
import { NativeModules, Platform } from 'react-native';
@@ -17,6 +17,20 @@ type JPushNotificationResult = {
1717
title?: string;
1818
};
1919

20+
type NotificationsModule = typeof import('expo-notifications');
21+
type NotificationPermissionsStatus =
22+
import('expo-notifications').NotificationPermissionsStatus;
23+
24+
let notificationsModulePromise: Promise<NotificationsModule> | null = null;
25+
26+
const getNotificationsModule =
27+
async (): Promise<NotificationsModule | null> => {
28+
if (isRunningInExpoGo()) return null;
29+
30+
notificationsModulePromise ??= import('expo-notifications');
31+
return notificationsModulePromise;
32+
};
33+
2034
const normalizeExtras = (extras: unknown): Record<string, string> | null => {
2135
if (!extras) return null;
2236
if (typeof extras === 'string') {
@@ -238,7 +252,8 @@ const handleCustomMessage = (result: unknown) => {
238252
};
239253

240254
const hasGrantedPushPermission = (
241-
settings: Notifications.NotificationPermissionsStatus
255+
settings: NotificationPermissionsStatus,
256+
Notifications: NotificationsModule
242257
) => {
243258
return (
244259
settings.granted ||
@@ -247,8 +262,11 @@ const hasGrantedPushPermission = (
247262
};
248263

249264
export const ensurePushPermission = async (requestIfNeeded = false) => {
265+
const Notifications = await getNotificationsModule();
266+
if (!Notifications) return false;
267+
250268
const currentSettings = await Notifications.getPermissionsAsync();
251-
if (hasGrantedPushPermission(currentSettings)) {
269+
if (hasGrantedPushPermission(currentSettings, Notifications)) {
252270
return true;
253271
}
254272

@@ -257,7 +275,7 @@ export const ensurePushPermission = async (requestIfNeeded = false) => {
257275
}
258276

259277
const requestedSettings = await Notifications.requestPermissionsAsync();
260-
return hasGrantedPushPermission(requestedSettings);
278+
return hasGrantedPushPermission(requestedSettings, Notifications);
261279
};
262280

263281
const registerJPushListeners = async () => {
@@ -297,6 +315,9 @@ export const initializeJPush = async ({
297315
return false;
298316
}
299317

318+
const Notifications = await getNotificationsModule();
319+
if (!Notifications) return false;
320+
300321
if (Platform.OS === 'android') {
301322
await Notifications.setNotificationChannelAsync('tips', {
302323
name: '消息通知',

src/modules/courseTable/components/courseTable/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import {
22
BackdropBlur,
33
Canvas,
4+
Image as SkImage,
45
makeImageFromView,
56
Skia,
6-
Image as SkImage,
77
SkImage as SkImageType,
88
useCanvasRef,
99
useImage,
1010
} from '@shopify/react-native-skia';
1111
import * as ImageManipulator from 'expo-image-manipulator';
12-
import * as MediaLibrary from 'expo-media-library';
12+
import * as MediaLibrary from 'expo-media-library/legacy';
1313
import React, {
1414
RefObject,
1515
useDeferredValue,

src/utils/systemUI.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { SystemBars } from 'react-native-edge-to-edge';
1+
import { isRunningInExpoGo } from 'expo';
2+
import { StatusBar } from 'react-native';
23

34
/**
45
* 设置系统UI主题
@@ -7,6 +8,15 @@ import { SystemBars } from 'react-native-edge-to-edge';
78
export const setSystemUITheme = (themeName: 'dark' | 'light') => {
89
const isDark = themeName === 'dark';
910

10-
// 使用 SystemBars 设置状态栏和导航栏样式
11-
SystemBars.setStyle(isDark ? 'light' : 'dark');
11+
StatusBar.setBarStyle(isDark ? 'light-content' : 'dark-content', true);
12+
13+
if (isRunningInExpoGo()) return;
14+
15+
void import('react-native-edge-to-edge')
16+
.then(({ SystemBars }) => {
17+
SystemBars.setStyle(isDark ? 'light' : 'dark');
18+
})
19+
.catch(() => {
20+
// Expo Go and older native clients do not include this module.
21+
});
1222
};

0 commit comments

Comments
 (0)