react-native - BottomTabNavigator 上的涟漪效应
问题描述
我正在尝试在 BottomTabNavigator 中添加这样的涟漪效应,但不知道如何?
我将createMaterialBottomTabNavigator用于 BottomTabNavigator。
解决方案
要让 Material Bottom Tab Navigator 更改颜色,您需要使用每个选项卡的tabBarColor
属性navigationOptions
。您可以在此处的文档中看到这一点。如果您想要波纹效果,还需要在导航器中设置shifting
为 true 。config
您需要确保已安装以下依赖项:
react-navigation
react-navigation-material-bottom-tabs
react-native-paper
react-native-vector-icons
, 虽然如果使用 Expo 这不是必需的,因为它已经包含在内
有关您需要的依赖项的更多详细信息,请参阅文档
这是一个示例导航器:
import * as React from 'react';
import Screen1 from './Screen1';
import Screen2 from './Screen2';
import { createAppContainer } from 'react-navigation';
import { createMaterialBottomTabNavigator } from 'react-navigation-material-bottom-tabs'; // <- notice where we import createMaterialBottomTabNavigator from
import { MaterialIcons } from '@expo/vector-icons';
const tabBarIcon = name => ({ tintColor }) => (
<MaterialIcons
style={{ backgroundColor: 'transparent' }}
name={name}
color={tintColor}
size={24}
/>
);
const screens = {
Screen1: {
screen: Screen1,
navigationOptions: {
tabBarIcon: tabBarIcon('photo-album'),
tabBarColor: 'blue' // <- set this to the color you want
}
},
Screen2: {
screen: Screen2,
navigationOptions: {
tabBarIcon: tabBarIcon('favorite'),
tabBarColor: 'green' // <- set this to the color you want
}
}
};
const config = {
headerMode: 'none',
initialRouteName: 'Screen1',
shifting: true, // <- notice this has been set to true
activeColor: 'white',
inactiveColor: 'black'
};
const MainNavigator = createMaterialBottomTabNavigator(screens, config);
export default createAppContainer(MainNavigator);
我会创建一个零食来展示这个工作,但不幸的是它在零食中表现不佳,但它在本地或应用程序react-navigation-material-bottom-tabs
中表现不错。Expo
react-native
推荐阅读
- lua - 如何使用 hamerspoon 将富文本粘贴板内容转换为纯文本?
- python-requests - json转换问题
- python - Pandas 数据框按参数设置边距
- emscripten - 如何使用 emscripten 将文件从 C 保存到浏览器存储
- java - 我在 SQLite 中正确使用 Cursor 吗?
- python - 向 Keras 中的嵌入层添加偏差
- javascript - 在 html 的支票簿中添加 if 条件
- python - 将字符串视为列表
- android-studio - 无法解析 Android Studio 上的原始符号错误
- html - PNG图像不显示透明