Commit 5ffbf57c authored by huanglu's avatar huanglu

fix: update

parent d876b5e9
...@@ -21,9 +21,7 @@ const HomeModel: DvaModel<HomeState> = { ...@@ -21,9 +21,7 @@ const HomeModel: DvaModel<HomeState> = {
effects: { effects: {
*fetch(action, { select, take, put }) { *fetch(action, { select, take, put }) {
setTimeout(() => { setTimeout(() => {
take({
})
}, 1000); }, 1000);
} }
} }
......
...@@ -16,14 +16,12 @@ import { useNavigation } from '@react-navigation/native'; ...@@ -16,14 +16,12 @@ import { useNavigation } from '@react-navigation/native';
const Home = (props: any) => { const Home = (props: any) => {
useHeaderShow(true) useHeaderShow(true)
const insets = useSafeAreaInsets()
const [list, setList] = useState([1,2,3]) const [list, setList] = useState([1,2,3])
const [refreshState, setRefreshState] = useState(RefreshState.Idle) const [refreshState, setRefreshState] = useState(RefreshState.Idle)
const navigation = useNavigation() const navigation = useNavigation()
useEffect(() => { useEffect(() => {
const handleFocus = () => { const handleFocus = () => {
console.log('==== home =====')
} }
navigation.addListener('focus', handleFocus) navigation.addListener('focus', handleFocus)
return () => { return () => {
...@@ -50,7 +48,6 @@ const Home = (props: any) => { ...@@ -50,7 +48,6 @@ const Home = (props: any) => {
} }
const onFooterRefresh = () => { const onFooterRefresh = () => {
console.log('onFooterRefresh')
setRefreshState(RefreshState.FooterRefreshing) setRefreshState(RefreshState.FooterRefreshing)
if (list.length >= 5) { if (list.length >= 5) {
setRefreshState(RefreshState.NoMoreData) setRefreshState(RefreshState.NoMoreData)
...@@ -62,7 +59,6 @@ const Home = (props: any) => { ...@@ -62,7 +59,6 @@ const Home = (props: any) => {
}, 1000); }, 1000);
} }
console.log(list)
return ( return (
<View style={{ flex: 1 }}> <View style={{ flex: 1 }}>
<RefreshListView <RefreshListView
......
import React, { useEffect } from 'react' import React from 'react'
import { createStackNavigator } from '@react-navigation/stack' import { createStackNavigator } from '@react-navigation/stack'
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs' import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'
import { NavigationContainer, getFocusedRouteNameFromRoute } from '@react-navigation/native' import { NavigationContainer, getFocusedRouteNameFromRoute } from '@react-navigation/native'
import { TopStackNavigationRef } from '@/utils/routeUtil' import { TopStackNavigationRef } from '@/utils/routeUtil'
import routes, { BaseRouteConfig } from './routes' import routes, { BaseRouteConfig } from './routes'
import Home from '@/pages/home'
const Stack = createStackNavigator() const Stack = createStackNavigator()
const Tab = createBottomTabNavigator() const Tab = createBottomTabNavigator()
...@@ -21,8 +20,6 @@ const configtabChildren = (components: [BaseRouteConfig]) => { ...@@ -21,8 +20,6 @@ const configtabChildren = (components: [BaseRouteConfig]) => {
return stacks return stacks
} }
const tabRouterNames = routes.tabs.map(itm => itm.name)
const tabs = (routes.tabs || []).map((tab, index) => { const tabs = (routes.tabs || []).map((tab, index) => {
const Child = () => { const Child = () => {
return <Stack.Navigator> return <Stack.Navigator>
...@@ -30,10 +27,10 @@ const tabs = (routes.tabs || []).map((tab, index) => { ...@@ -30,10 +27,10 @@ const tabs = (routes.tabs || []).map((tab, index) => {
</Stack.Navigator> </Stack.Navigator>
} }
return ( return (
<Tab.Screen name={tab.name} key={index} <Tab.Screen name={tab.name} key={index + 'tab'}
options={({route}) => { options={({route}) => {
const routeName = getFocusedRouteNameFromRoute(route) const routeName = getFocusedRouteNameFromRoute(route)
const hiddenTabBar = tabRouterNames.includes(routeName) const hiddenTabBar = (route as any).state && (route as any).state.index && (route as any).state.index === 0
return { return {
tabBarVisible: hiddenTabBar, tabBarVisible: hiddenTabBar,
...tab.options || {} ...tab.options || {}
...@@ -47,6 +44,8 @@ const RouteApp = () => { ...@@ -47,6 +44,8 @@ const RouteApp = () => {
return ( return (
<NavigationContainer ref={ref => TopStackNavigationRef(ref)}> <NavigationContainer ref={ref => TopStackNavigationRef(ref)}>
<Tab.Navigator tabBarOptions={{ <Tab.Navigator tabBarOptions={{
}} screenOptions={{
tabBarVisible: true,
}}> }}>
{ tabs } { tabs }
</Tab.Navigator> </Tab.Navigator>
......
...@@ -37,6 +37,9 @@ const routesConfig: { ...@@ -37,6 +37,9 @@ const routesConfig: {
{ {
component: Home, component: Home,
name: 'Home', name: 'Home',
options: {
}
}, },
{ {
name: 'Message', name: 'Message',
...@@ -47,6 +50,11 @@ const routesConfig: { ...@@ -47,6 +50,11 @@ const routesConfig: {
{ {
title: 'About', title: 'About',
name: 'About', name: 'About',
options: {
tabBarLabel: 'About',
tabBarIcon: (props) => <View style={{ width: 30, height: 30, backgroundColor: 'blue' }}></View>,
tabBarBadge: 4
},
children: [ children: [
{ {
name: 'About', name: 'About',
...@@ -61,14 +69,24 @@ const routesConfig: { ...@@ -61,14 +69,24 @@ const routesConfig: {
{ {
title: 'Person', title: 'Person',
name: 'Person', name: 'Person',
options: {
tabBarLabel: 'Person',
tabBarIcon: (props) => <View style={{ width: 30, height: 30, backgroundColor: 'blue' }}></View>,
tabBarBadge: 4
},
children: [ children: [
{ {
name: 'Person', name: 'Person',
component: Person, component: Person,
options: {
}
}, },
{ {
name: 'Message', name: 'Message',
component: Message, component: Message,
options: {
header: null
}
} }
] ]
} }
......
...@@ -5,46 +5,46 @@ import { createLogger } from 'redux-logger' ...@@ -5,46 +5,46 @@ import { createLogger } from 'redux-logger'
import { Store } from 'redux'; import { Store } from 'redux';
let app: { let app: {
use: (arg0: {onError(err: any): void}) => void; use: (arg0: {onError(err: any): void}) => void;
model: (arg0: any) => any; model: (arg0: any) => any;
start: () => void; start: () => void;
_store: Store; _store: Store;
getStore: () => Store; getStore: () => Store;
dispatch: any; dispatch: any;
}; };
let store: Store; let store: Store;
let dispatch; let dispatch;
let registered: boolean; let registered: boolean;
function createApp(opt: any) { function createApp(opt: any) {
// redux 的日志 // redux 的日志
opt.onAction = [createLogger()]; opt.onAction = [createLogger()];
app = create(opt); app = create(opt);
app.use(immer()); app.use(immer());
app.use(createLoading()); app.use(createLoading());
app.use({ app.use({
onError(err: any) { onError(err: any) {
console.log('dvaError', err); console.log('dvaError', err);
}, },
}); });
if (!registered) { if (!registered) {
opt.models.forEach((model: any) => app.model(model)); opt.models.forEach((model: any) => app.model(model));
}
registered = true;
app.start();
store = app._store;
app.getStore = () => store;
dispatch = store.dispatch;
app.dispatch = dispatch;
return app;
} }
registered = true;
app.start();
store = app._store;
app.getStore = () => store;
dispatch = store.dispatch;
app.dispatch = dispatch;
return app;
}
export default { export default {
createApp, createApp,
getDispatch() { getDispatch() {
return app.dispatch; return app.dispatch;
}, },
}; };
\ No newline at end of file \ No newline at end of file
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