1
- import React , { useState , useEffect , Fragment } from 'react' ;
1
+ import React , { useState , useEffect , useCallback } from 'react' ;
2
+ import { createNativeStackNavigator , NativeStackHeaderProps } from '@react-navigation/native-stack' ;
2
3
import { navigationRef , customTheme , AsyncStatus } from '~/utils' ;
3
- import { createNativeStackNavigator } from '@react-navigation/native-stack' ;
4
+ import { HeartAndBrowser , PrehandleDrawer } from '~/views/Detail' ;
5
+ import { SearchAndPlugin , PluginSelect } from '~/views/Discovery' ;
4
6
import { GestureHandlerRootView } from 'react-native-gesture-handler' ;
5
7
import { store , useAppSelector } from '~/redux' ;
6
8
import { NavigationContainer } from '@react-navigation/native' ;
7
9
import { NativeBaseProvider } from 'native-base' ;
8
10
import { useMessageToast } from '~/hooks' ;
11
+ import { SearchAndAbout } from '~/views/Home' ;
9
12
import { StyleSheet } from 'react-native' ;
10
13
import { Provider } from 'react-redux' ;
11
14
import RNBootSplash from 'react-native-bootsplash' ;
12
15
import loadable from '@loadable/component' ;
16
+ import Header from '~/components/Header' ;
13
17
14
18
interface NavigationScreenProps {
15
19
ready ?: boolean ;
16
20
}
17
21
18
- const Header = loadable ( ( ) => import ( '~/components/Header' ) ) ;
19
22
const Home = loadable ( ( ) => import ( '~/views/Home' ) ) ;
20
- const SearchAndAbout = loadable ( ( ) => import ( '~/views/Home' ) , {
21
- resolveComponent : ( components ) => components . SearchAndAbout ,
22
- } ) ;
23
23
const Search = loadable ( ( ) => import ( '~/views/Search' ) ) ;
24
24
const Discovery = loadable ( ( ) => import ( '~/views/Discovery' ) ) ;
25
- const SearchAndPlugin = loadable ( ( ) => import ( '~/views/Discovery' ) , {
26
- resolveComponent : ( components ) => components . SearchAndPlugin ,
27
- } ) ;
28
- const PluginSelect = loadable ( ( ) => import ( '~/views/Discovery' ) , {
29
- resolveComponent : ( components ) => components . PluginSelect ,
30
- } ) ;
31
25
const Detail = loadable ( ( ) => import ( '~/views/Detail' ) ) ;
32
- const HeartAndBrowser = loadable ( ( ) => import ( '~/views/Detail' ) , {
33
- resolveComponent : ( components ) => components . HeartAndBrowser ,
34
- } ) ;
35
- const PrehandleDrawer = loadable ( ( ) => import ( '~/views/Detail' ) , {
36
- resolveComponent : ( components ) => components . PrehandleDrawer ,
37
- } ) ;
38
26
const Chapter = loadable ( ( ) => import ( '~/views/Chapter' ) ) ;
39
27
const Plugin = loadable ( ( ) => import ( '~/views/Plugin' ) ) ;
40
28
const Webview = loadable ( ( ) => import ( '~/views/Webview' ) ) ;
@@ -48,6 +36,11 @@ const NavigationScreen = ({ ready = false }: NavigationScreenProps) => {
48
36
const latestRelease = useAppSelector ( ( state ) => state . release . latest ) ;
49
37
const haveUpdate = Boolean ( latestRelease ) ;
50
38
39
+ const DefaultHeader = useCallback (
40
+ ( props : NativeStackHeaderProps ) => < Header { ...props } enableShake = { haveUpdate } /> ,
41
+ [ haveUpdate ]
42
+ ) ;
43
+
51
44
useEffect ( ( ) => {
52
45
if ( ready && launchStatus === AsyncStatus . Fulfilled ) {
53
46
RNBootSplash . hide ( ) ;
@@ -56,20 +49,17 @@ const NavigationScreen = ({ ready = false }: NavigationScreenProps) => {
56
49
useMessageToast ( ) ;
57
50
58
51
return (
59
- < Navigator
60
- initialRouteName = "Home"
61
- screenOptions = { { header : ( props ) => < Header { ...props } enableShake = { haveUpdate } /> } }
62
- >
63
- < Screen name = "Home" options = { { headerRight : ( ) => < SearchAndAbout /> } } component = { Home } />
52
+ < Navigator initialRouteName = "Home" screenOptions = { { header : DefaultHeader } } >
53
+ < Screen name = "Home" options = { { headerRight : SearchAndAbout } } component = { Home } />
64
54
< Screen
65
55
name = "Discovery"
66
- options = { { title : '' , headerLeft : ( ) => < SearchAndPlugin /> } }
56
+ options = { { title : '' , headerLeft : SearchAndPlugin } }
67
57
component = { Discovery }
68
58
/>
69
- < Screen name = "Search" options = { { headerRight : ( ) => < PluginSelect /> } } component = { Search } />
59
+ < Screen name = "Search" options = { { headerRight : PluginSelect } } component = { Search } />
70
60
< Screen
71
61
name = "Detail"
72
- options = { { title : 'loading...' , headerRight : ( ) => < HeartAndBrowser /> } }
62
+ options = { { title : 'loading...' , headerRight : HeartAndBrowser } }
73
63
component = { Detail }
74
64
/>
75
65
< Screen name = "Chapter" options = { { headerShown : false } } component = { Chapter } />
@@ -80,14 +70,6 @@ const NavigationScreen = ({ ready = false }: NavigationScreenProps) => {
80
70
) ;
81
71
} ;
82
72
83
- const ModalWrapper = ( ) => {
84
- return (
85
- < Fragment >
86
- < PrehandleDrawer />
87
- </ Fragment >
88
- ) ;
89
- } ;
90
-
91
73
const App = ( ) => {
92
74
const [ ready , setReady ] = useState ( false ) ;
93
75
@@ -97,7 +79,7 @@ const App = () => {
97
79
< NativeBaseProvider theme = { customTheme } >
98
80
< NavigationContainer ref = { navigationRef } onReady = { ( ) => setReady ( true ) } >
99
81
< NavigationScreen ready = { ready } />
100
- < ModalWrapper />
82
+ < PrehandleDrawer />
101
83
</ NavigationContainer >
102
84
</ NativeBaseProvider >
103
85
</ Provider >
0 commit comments