Commit acf9123e authored by huanglu's avatar huanglu

fix: update template

parent 5ffbf57c
import { StackNavigationProp } from "@react-navigation/stack"
declare module "*.png";
declare module "*.gif";
declare module "*.jpg";
declare module "*.jpeg";
declare module "*.svg";
declare module 'dva-core';
declare module 'dva-loading'
declare module 'dva-immer'
declare module 'dva-*';
declare module 'react-native-refresh-list-view'
type Action<T> = {
......@@ -41,3 +41,8 @@ type DvaModel<T> = {
[key: string]: Effect
}
}
type PageProps = {
navigation: StackNavigationProp<any>,
dispatch: Dispatch
}
import { push, jump } from "@/utils/routeUtil"
import { push, jump } from "@/utils/router"
export default {
......
......@@ -6,6 +6,7 @@ import { TouchableHighlight } from 'react-native-gesture-handler';
import navigate from '@/navigate';
import { useHeaderShow } from '@/hooks';
import { useNavigation } from '@react-navigation/native';
import { PageProps } from 'global';
// Idle (普通状态)
// HeaderRefreshing (头部菊花转圈圈中)
......@@ -13,7 +14,7 @@ import { useNavigation } from '@react-navigation/native';
// NoMoreData (已加载全部数据)
// Failure (加载失败)
const Home = (props: any) => {
const Home = (props: PageProps) => {
useHeaderShow(true)
const [list, setList] = useState([1,2,3])
......@@ -22,6 +23,7 @@ const Home = (props: any) => {
useEffect(() => {
const handleFocus = () => {
props.navigation
}
navigation.addListener('focus', handleFocus)
return () => {
......
import React from 'react'
import { BaseRouteConfig } from "./routes"
import { createStackNavigator } from "@react-navigation/stack"
const Stack = createStackNavigator()
const configtabChildren = (components: [BaseRouteConfig]) => {
const stacks = components.map(com => {
return (
<Stack.Screen
key={com.name}
name={com.name}
component={com.component as any}
options={{
...com.options || {}
}}
/>
)
})
return stacks
}
export default ({routes} : {routes: [BaseRouteConfig]}) => {
return (
<Stack.Navigator>
{configtabChildren(routes || [] as any)}
</Stack.Navigator>
)
}
\ No newline at end of file
import React from 'react'
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'
import routes from './routes'
import Stack from './Stack'
const Tab = createBottomTabNavigator()
export default () => {
const tabs = (routes.tabs || []).map((tab, index) => {
const Child = () => {
return <Stack routes={tab.children as any} />
}
return (
<Tab.Screen
name={tab.name}
key={index + 'tab'}
options={({ route }) => {
const hiddenTabBar = (route as any).state &&
(route as any).state.index &&
(route as any).state.index === 0;
return {
tabBarVisible: hiddenTabBar,
...tab.options || {},
tabBarBadge: tab.name === 'Home' ? 3 : tab.name === 'About' ? 2 : 1
}
}}
component={Child}
/>
)
})
return (
<Tab.Navigator tabBarOptions={{
}} screenOptions={{
tabBarVisible: true,
}}>
{tabs}
</Tab.Navigator>
)
}
\ No newline at end of file
import React from 'react'
import { createStackNavigator } from '@react-navigation/stack'
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'
import { NavigationContainer, getFocusedRouteNameFromRoute } from '@react-navigation/native'
import { TopStackNavigationRef } from '@/utils/routeUtil'
import routes, { BaseRouteConfig } from './routes'
const Stack = createStackNavigator()
const Tab = createBottomTabNavigator()
const configtabChildren = (components: [BaseRouteConfig]) => {
const stacks = components.map(com => {
return (
<Stack.Screen key={com.name} name={com.name} component={com.component as any} options={{
...com.options || {}
}} />
)
})
return stacks
}
const tabs = (routes.tabs || []).map((tab, index) => {
const Child = () => {
return <Stack.Navigator>
{ configtabChildren(tab.children || [] as any) }
</Stack.Navigator>
}
return (
<Tab.Screen name={tab.name} key={index + 'tab'}
options={({route}) => {
const routeName = getFocusedRouteNameFromRoute(route)
const hiddenTabBar = (route as any).state && (route as any).state.index && (route as any).state.index === 0
return {
tabBarVisible: hiddenTabBar,
...tab.options || {}
}
}}
component={Child} />
)
})
import { NavigationContainer } from '@react-navigation/native'
import { TopStackNavigationRef } from '@/utils/router'
import Tab from './Tab'
const RouteApp = () => {
return (
<NavigationContainer ref={ref => TopStackNavigationRef(ref)}>
<Tab.Navigator tabBarOptions={{
}} screenOptions={{
tabBarVisible: true,
}}>
{ tabs }
</Tab.Navigator>
<Tab />
</NavigationContainer>
)
}
......
......@@ -52,8 +52,7 @@ const routesConfig: {
name: 'About',
options: {
tabBarLabel: 'About',
tabBarIcon: (props) => <View style={{ width: 30, height: 30, backgroundColor: 'blue' }}></View>,
tabBarBadge: 4
tabBarIcon: (props) => <View style={{ width: 30, height: 30, backgroundColor: 'blue' }}></View>
},
children: [
{
......@@ -72,7 +71,6 @@ const routesConfig: {
options: {
tabBarLabel: 'Person',
tabBarIcon: (props) => <View style={{ width: 30, height: 30, backgroundColor: 'blue' }}></View>,
tabBarBadge: 4
},
children: [
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment