You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

react-native-tab-view导致Expo Go应用闪退的问题求助

react-native-tab-view导致Expo Go应用闪退的问题求助

大家好,我最近碰到一个特别头疼的问题,想请各位帮忙分析下:

我在项目里用了react-native-tab-view库的TabView组件做一个带标签页的用户资料页面,结果只要在Expo Go应用里打开这个页面,App预览就直接闪退,跳回Expo Go的首页了。但奇怪的是,在Web端运行完全正常,而且控制台也没有输出任何错误日志,我实在搞不清到底哪里出问题了,希望能得到大家的帮助,谢谢!

我当前使用的相关依赖版本是:

"react-native-pager-view": "^6.7.1"
"react-native-tab-view": "^4.1.3"

以下是我的代码:

import { TabView } from 'react-native-tab-view';
import Screen1 from '../screens/screen1';
import Screen2 from '../screens/screen2';

const UserProfile = () => {
  const { colors } = useSelector((state: any) => state.theme);
  const styles = StyleSheet.create({
    container: {
      flex: 1,
      backgroundColor: colors.background,
    },
  });

  const layout = useWindowDimensions();
  const [index, setIndex] = useState(0);
  const routes = [
    { key: '1', title: <OneIcon /> },
    { key: '2', title: <TwoIcon /> },
  ];

  const renderScene = ({ route, jumpTo }: { route: any; jumpTo: any }) => {
    switch (route.key) {
      case '1':
        return <Screen1 jumpTo={jumpTo} />;
      case '2':
        return <Screen2 jumpTo={jumpTo} />;
    }
  };

  return (
    <SafeAreaView style={styles.container}>
      <View style={{ height: 100, flex: 1 }}>
        <TabView
          tabStyle={{ color: colors.backgroundColor }}
          navigationState={{ index, routes }}
          renderScene={renderScene}
          onIndexChange={setIndex}
          initialLayout={{ width: layout.width }}
        />
      </View>
    </SafeAreaView>
  );
};

有没有朋友遇到过类似的情况,或者能帮我检查下代码里有没有潜在的问题?再次感谢大家的帮助!

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.07 09:09:32