我是 React Native 的新手,我正在尝试使用这个包https://github.com/LiuC520/react-native-scrollable-tab-view-forked来使用标签,这就是标签的创建方式
<ScrollableTabView
renderTabBar={() => (
<ScrollableTabBar
style={styles.scrollStyle}
tabStyle={styles.tabStyle}
/>
)}
tabBarTextStyle={styles.tabBarTextStyle}
tabBarInactiveTextColor={'black'}
tabBarActiveTextColor={'red'}
tabBarUnderlineStyle={styles.underlineStyle}
initialPage={2}
>
<View key={'1'} tabLabel={'firt tab '} style={{flex:1,backgroundColor:'red'}}/>
<View key={'2'} tabLabel={'second tab'} style={{flex:1,backgroundColor:'blue'}}/>
<View key={'3'} tabLabel={'third tab'} style={{flex:1,backgroundColor:'yellow'}}/>
</ScrollableTabView>
它工作正常
但是当我试图渲染视图以在我失败的每个选项卡中显示它时,我已经尝试过这种方式
<View key={'1'} tabLabel={'firt tab '} style={{flex:1,backgroundColor:'red',height:100}}>
<View><Text>first</Text></View>
</View>
但它给出了错误“TypeError:JSON.stringify 无法序列化循环结构”,我不是这个意思,如果有人已经使用过这个包或者知道解决方案是什么,请帮忙。
这是我的全部代码
import React from 'react';
import { ScrollView, ImageBackground, Image, View, StyleSheet,
StatusBar, Dimensions, Platform } from 'react-native';
import { Block, Button, Text, theme } from 'galio-framework';
import ScrollableTabView, { DefaultTabBar, ScrollableTabBar } from 'react-native-scrollable-tab-view-forked';
const { height, width } = Dimensions.get('screen');
import { Images, argonTheme } from '../constants/';
import { HeaderHeight } from "../constants/utils";
import ajax from '../services/FetchSubjects';
import Loader from '../components/Loader';
const URI = 'http://localhost:8000';
export default class SubjectDetails extends React.Component {
constructor(props) {
super(props);
this.state = {
loading: true,
data: {
subject: {},
meals: []
}
}
}
async componentDidMount() {
const data = await ajax.fetchSubjectDetails(this.props.navigation.state.params.subjectId);
this.setState({
data: {
subject: data.subject,
meals: data.meals
},
loading: false
});
}
render() {
const { navigation } = this.props;
return (
<Block safe style={styles.container}>
<Block>
<StatusBar barStyle="light-content" />
<Loader loading={this.state.loading} />
<Block flex style={styles.category}>
<ImageBackground
source={this.state.loading ? Images.Pro : { uri: URI + this.state.data.subject.cover.url }}
style={{ flex: 1, height: 160, width, zIndex: 1 }}
>
<Block style={styles.categoryBg}>
<Block style={styles.categoryTitle}>
<Text size={18} bold color={theme.COLORS.WHITE}>
{this.state.data.subject.name}
</Text>
</Block>
</Block>
</ImageBackground>
</Block>
</Block>
<Block style={{marginTop:160,height:"100%"}}>
<ScrollView>
<ScrollableTabView
renderTabBar={() => (
<ScrollableTabBar
style={styles.scrollStyle}
tabStyle={styles.tabStyle}
/>
)}
tabBarTextStyle={styles.tabBarTextStyle}
tabBarInactiveTextColor={'black'}
tabBarActiveTextColor={'#2B4D8E'}
tabBarUnderlineStyle={styles.underlineStyle}
initialPage={2}
>
<View key={'1'} tabLabel={'firt tab '} style={{flex:1,backgroundColor:'red',height:100}}><Text>Lorem ipsum</Text></View>
<View key={'2'} tabLabel={'second tab'} style={{flex:1,backgroundColor:'blue',height:100}}/>
<View key={'3'} tabLabel={'third tab'} style={{flex:1,backgroundColor:'yellow',height:100}}/>
<View key={'4'} tabLabel={'Fourth tab'} style={{flex:1,backgroundColor:'yellow',height:100}}/>
</ScrollableTabView>
</ScrollView>
</Block>
</Block>
);
}
}