react-native实践日记--1.react-navigation实现底部导航栏,真机调试时点击tab无反应或反应延迟卡顿

开发者在使用ReactNative的createBottomTabNavigator创建底部导航栏时遇到问题,真机调试时点击无响应。解决原因是开启手机远程调试导致应用反应减慢,需关闭该功能才能正常操作。
摘要由CSDN通过智能技术生成

最近做了个App项目,基于react-native的,其中要设计一个底部的导航栏,就用到了react-navigation的bottom-tabs。

引入bottom-tabs,代码如下:

import {
  NavigationContainer
} from '@react-navigation/native';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { createNativeStackNavigator } from '@react-navigation/native-stack'; //本机原生导航,性能强,自定义性不如stack


const Stack = createNativeStackNavigator();
const Tab = createBottomTabNavigator();

render() {
	return (<NavigationContainer ref={navigationRef}>
		<Stack.Navigator initialRouteName={initialRouteName}>
	        <Stack.Screen
	          options={{ headerShown: false }}
	          name="Tab"
	          component={TabNavigator}
	        />
	        <Stack.Screen
	          options={{
	            headerShown: false
	          }}
	          name="Login"
	          component={LoginScreen}
	        />
	    </Stack.Navigator>
      </NavigationContainer>)
}

但在用真机调试时,点击tab按钮死活没反应,只偶尔能跳转页面,找了半天资料发现都不行。
最终发现是因为开启了手机的远程调试,关闭stopDebugging即可,因为这个远程调试可能会影响app的一些反应速度,但没想到会彻底点不动,坑呀!

在这里插入图片描述

  • 12
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
React Native中可以使用第三方库`react-native-scrollable-tab-view`来实现滑动标题栏。以下是一个简单的示例代码: ```tsx import * as React from 'react'; import { StyleSheet, Text, View } from 'react-native'; import ScrollableTabView, { DefaultTabBar } from 'react-native-scrollable-tab-view'; type Props = {}; const FirstTabScreen = () => { return ( <View style={styles.container}> <Text>First Tab</Text> </View> ); }; const SecondTabScreen = () => { return ( <View style={styles.container}> <Text>Second Tab</Text> </View> ); }; const ScrollableTabNavigator = (props: Props) => { return ( <ScrollableTabView renderTabBar={() => <DefaultTabBar />} tabBarUnderlineStyle={styles.tabBarUnderline} tabBarBackgroundColor="#FFFFFF" tabBarActiveTextColor="#000000" tabBarInactiveTextColor="#999999" > <FirstTabScreen tabLabel="Tab 1" /> <SecondTabScreen tabLabel="Tab 2" /> </ScrollableTabView> ); }; export default ScrollableTabNavigator; const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', }, tabBarUnderline: { backgroundColor: '#000000', height: 2, }, }); ``` 在这个示例中,我们首先导入了`react-native-scrollable-tab-view`库中的`ScrollableTabView`和`DefaultTabBar`组件。然后,我们创建了两个Tab项组件`FirstTabScreen`和`SecondTabScreen`,每个组件中都有一个`tabLabel`属性,用于设置Tab的标签。最后,我们使用`ScrollableTabView`组件来包含Tab项,并设置了一些Tab导航的样式属性,例如`tabBarUnderlineStyle`、`tabBarBackgroundColor`、`tabBarActiveTextColor`和`tabBarInactiveTextColor`。在`renderTabBar`属性中,我们使用了`DefaultTabBar`组件来渲染Tab导航栏。 注意:`react-native-scrollable-tab-view`库已经很久没有更新了,建议使用`react-native-tab-view`等其他替代库。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

戴花环的蜗牛

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值