Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vt-rn-pre-study
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
朱传永
vt-rn-pre-study
Commits
33d77043
Commit
33d77043
authored
Jan 27, 2021
by
zhuchuanyong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: tab navigation
parent
0a383897
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
4 deletions
+50
-4
TabsNavigation.js
src/router/TabsNavigation.js
+50
-4
No files found.
src/router/TabsNavigation.js
View file @
33d77043
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
* @Author: zhuchuanyong
* @Author: zhuchuanyong
* @Date: 2021-01-26 10:17:27
* @Date: 2021-01-26 10:17:27
* @LastEditors: zhuchuanyong
* @LastEditors: zhuchuanyong
* @LastEditTime: 2021-01-2
6 13:21:57
* @LastEditTime: 2021-01-2
7 11:07:54
* @FilePath: \src\router\TabsNavigation.js
* @FilePath: \src\router\TabsNavigation.js
*/
*/
...
@@ -10,18 +10,54 @@ import React from 'react';
...
@@ -10,18 +10,54 @@ import React from 'react';
import
{
NavigationContainer
}
from
'@react-navigation/native'
;
import
{
NavigationContainer
}
from
'@react-navigation/native'
;
import
{
createBottomTabNavigator
}
from
'@react-navigation/bottom-tabs'
;
import
{
createBottomTabNavigator
}
from
'@react-navigation/bottom-tabs'
;
import
Ionicons
from
'react-native-vector-icons/Ionicons'
;
import
Ionicons
from
'react-native-vector-icons/Ionicons'
;
import
{
Text
,
View
}
from
'react-native'
;
import
Home
from
'../views/Home'
;
import
Home
from
'../views/Home'
;
import
Details
from
'../views/Details'
;
import
Details
from
'../views/Details'
;
const
Tab
=
createBottomTabNavigator
();
const
Tab
=
createBottomTabNavigator
();
export
default
function
App
()
{
/**
* 徽章计数
* @param {Object} obj 参数
* @param {string} obj.name 图标名称
* @param {number} obj.badgeCount - 角标数字
* @param {string} obj.color - 颜色
* @param {string} obj.size - 大小
*/
function
IconWithBadge
({
name
,
badgeCount
,
color
,
size
})
{
const
ViewStyle
=
{
// On React Native < 0.57 overflow outside of parent will not work on Android, see https://git.io/fhLJ8
position
:
'absolute'
,
right
:
-
6
,
top
:
-
3
,
backgroundColor
:
'red'
,
borderRadius
:
6
,
width
:
12
,
height
:
12
,
justifyContent
:
'center'
,
alignItems
:
'center'
,
};
const
TextStyle
=
{
color
:
'white'
,
fontSize
:
10
,
fontWeight
:
'bold'
};
return
(
<
View
style
=
{{
width
:
24
,
height
:
24
,
margin
:
5
}}
>
<
Ionicons
name
=
{
name
}
size
=
{
size
}
color
=
{
color
}
/
>
{
badgeCount
>
0
&&
(
<
View
style
=
{
ViewStyle
}
>
<
Text
style
=
{
TextStyle
}
>
{
badgeCount
}
<
/Text
>
<
/View
>
)}
<
/View
>
);
}
export
default
function
TabNavigation
()
{
return
(
return
(
<
NavigationContainer
>
<
NavigationContainer
>
<
Tab
.
Navigator
<
Tab
.
Navigator
screenOptions
=
{({
route
})
=>
({
screenOptions
=
{({
route
})
=>
({
tabBarIcon
:
({
focused
,
color
,
size
})
=>
{
tabBarIcon
:
({
focused
,
color
,
size
})
=>
{
let
iconName
;
let
iconName
;
//集中处理icon
if
(
route
.
name
===
'Home'
)
{
if
(
route
.
name
===
'Home'
)
{
iconName
=
'ios-information-circle'
;
iconName
=
'ios-information-circle'
;
// iconName = focused
// iconName = focused
...
@@ -33,7 +69,17 @@ export default function App() {
...
@@ -33,7 +69,17 @@ export default function App() {
}
}
// You can return any component that you like here!
// You can return any component that you like here!
return
<
Ionicons
name
=
{
iconName
}
size
=
{
size
}
color
=
{
color
}
/>
;
return
(
// Ionicons 只有图标
// <Ionicons name={iconName} size={size} color={color} />
// 含有徽章的图标
<
IconWithBadge
name
=
{
iconName
}
size
=
{
size
}
color
=
{
color
}
badgeCount
=
{
3
}
/
>
);
},
},
})}
})}
tabBarOptions
=
{{
tabBarOptions
=
{{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment