Skip to content

Commit

Permalink
Merge pull request #51 from yssk22/develop
Browse files Browse the repository at this point in the history
[expo] fix loading with Suspense
  • Loading branch information
yssk22 authored Nov 10, 2023
2 parents 6dc1e06 + ba1a680 commit 1f306d4
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 21 deletions.
19 changes: 19 additions & 0 deletions expo/features/common/components/Loading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { useColor } from '@hpapp/features/settings/context/theme';
import { ActivityIndicator, StyleSheet, View } from 'react-native';

export default function Loading() {
const [color] = useColor('primary');
return (
<View style={styles.container}>
<ActivityIndicator color={color} />
</View>
);
}

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
}
});
9 changes: 6 additions & 3 deletions expo/features/home/HomeScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ArtistsTab from '@hpapp/features/artist/ArtistsTab';
import Loading from '@hpapp/features/common/components/Loading';
import EventsTab from '@hpapp/features/home/Events';
import GoodsTab from '@hpapp/features/home/GoodsTab';
import HomeTab from '@hpapp/features/home/HomeTab';
Expand All @@ -9,7 +10,7 @@ import { useColor } from '@hpapp/features/settings/context/theme';
import { UPFCProvider } from '@hpapp/features/upfc/context';
import { t } from '@hpapp/system/i18n';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import React from 'react';
import React, { Suspense } from 'react';
import { View, StyleSheet } from 'react-native';
import Ionicons from 'react-native-vector-icons/Ionicons';

Expand Down Expand Up @@ -54,8 +55,10 @@ function tabComponent(c: React.ElementType<any>) {
return function TabComponent() {
return (
<View style={styles.tab}>
<AppUpdateBanner />
{React.createElement(c)}
<Suspense fallback={<Loading />}>
<AppUpdateBanner />
{React.createElement(c)}
</Suspense>
</View>
);
};
Expand Down
9 changes: 6 additions & 3 deletions expo/features/root/banner/AppUpdateBanner.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Text from '@hpapp/features/common/components/Text';
import { FontSize, Spacing } from '@hpapp/features/common/constants';
import { useColor } from '@hpapp/features/settings/context/theme';
import Constants from 'expo-constants';
import * as Updates from 'expo-updates';
import { useState, useEffect } from 'react';
import { AppState, AppStateStatus, TouchableOpacity, StyleSheet, View } from 'react-native';
Expand Down Expand Up @@ -49,9 +50,11 @@ export default function AppUpdateBanner({
setUpdateAvailable(update.isAvailable);
}
} catch (e: any) {
logging.Error('features.root.banner.AppUpdateBanner', 'failed to check update', {
error: e.toString()
});
if (Constants.expoConfig?.extra?.hpapp?.isDev !== true) {
logging.Error('features.root.banner.AppUpdateBanner', 'failed to check update', {
error: e.toString()
});
}
if (!unmounted) {
setUpdateCheckState(null);
setUpdateAvailable(false);
Expand Down
11 changes: 2 additions & 9 deletions expo/features/root/protected/ProtectedRoot.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Loading from '@hpapp/features/common/components/Loading';
import { initURICache } from '@hpapp/features/common/hooks/uricache';
import Initialize from '@hpapp/features/root/protected/Initializer';
import LoadError from '@hpapp/features/root/protected/LoadError';
import RootWrapper from '@hpapp/features/root/protected/RootWrapper';
import { ServiceRootProvider } from '@hpapp/features/root/protected/context';
import { Screen, ScreenParams, createStackNavigator } from '@hpapp/features/root/protected/stack';
import { useNavigationContainerRef } from '@react-navigation/native';
import { Text } from '@rneui/base';

const Stack = createStackNavigator({
rootComponent: RootWrapper
Expand All @@ -17,14 +17,7 @@ export default function ProtectedRoot({ screens }: { screens: Screen<ScreenParam
const navigation = useNavigationContainerRef<ReactNavigation.RootParamList>();
return (
<Initialize initializers={initializers}>
<ServiceRootProvider
errorFallback={<LoadError />}
loadingFallback={
<>
<Text>Loading</Text>
</>
}
>
<ServiceRootProvider errorFallback={<LoadError />} loadingFallback={<Loading />}>
<Stack ref={navigation} screens={screens} initialRouteName="/" />
</ServiceRootProvider>
</Initialize>
Expand Down
11 changes: 6 additions & 5 deletions expo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
"start": "expo start --dev-client --lan",
"start-go": "yarn expo start",
"eas-build-pre-install": "./scripts/eas-build-pre-install.sh",
"build-dev": "HPAPP_CONFIG_NAME=dev ./scripts/eas.sh build --profile dev --non-interactive",
"build-beta": "HPAPP_CONFIG_NAME=beta ./scripts/eas.sh build --profile beta --non-interactive",
"build-prod": "HPAPP_CONFIG_NAME=prod ./scripts/eas.sh build --profile prod --non-interactive",
"update-beta": "HPAPP_CONFIG_NAME=beta ./scripts/eas.sh update --channel beta --non-interactive --auto",
"relay": "node ./scripts/genschema.js && yarn relay-compiler",
"test": "yarn jest ./",
"lint": "yarn eslint ./",
"genscreen": "node ./scripts/genscreen.js"
"genscreen": "node ./scripts/genscreen.js",
"start-dev": "HPAPP_CONFIG_NAME=dev expo start --dev-client --lan",
"build-dev": "HPAPP_CONFIG_NAME=dev ./scripts/eas.sh build --profile dev --non-interactive",
"build-beta": "HPAPP_CONFIG_NAME=beta ./scripts/eas.sh build --profile beta --non-interactive",
"build-prod": "HPAPP_CONFIG_NAME=prod ./scripts/eas.sh build --profile prod --non-interactive",
"update-beta": "HPAPP_CONFIG_NAME=beta ./scripts/eas.sh update --channel beta --non-interactive --auto"
},
"relay": {
"src": "./",
Expand Down
2 changes: 1 addition & 1 deletion expo/system/logging/Console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { LogLevel, LogSink } from '@hpapp/system/logging/types';
import Constants from 'expo-constants';

const defaultEvents = '.*'; // '.*';
const defaultEvents: string[] = []; //'.*'; // '.*';

const consoleEvents: RegExp[] = (Constants.expoConfig?.extra?.hpapp?.consoleEvents || [defaultEvents]).map(
(re: string) => {
Expand Down

0 comments on commit 1f306d4

Please sign in to comment.