React Native中的Tab视图无法正常渲染组件

时间:2019-10-08 06:55:01

标签: react-native navigation react-native-tabnavigator

我正在使用TabView在底部导航器中显示顶部导航。在正确渲染最后两个屏幕时,第一个屏幕没有正确显示某些不必要的边框颜色。在其他屏幕上也是如此。

我也尝试了createMaterialTopTabNavigator,但结果是相同的。

import React from 'react';
import { View, Text, StyleSheet, Dimensions, Button, FlatList } from 'react-native';
import { TabView, SceneMap, TabBar } from 'react-native-tab-view';
import { Card, ListItem } from 'react-native-elements';
import { createMaterialTopTabNavigator } from 'react-navigation-tabs';
//import { ListItem } from 'react-native-elements';
import Icon from "react-native-vector-icons/MaterialCommunityIcons";
const list = [
{
    title: 'We are using List item and we will integrate flat list with it.testing done.',
    icon: 'av-timer'
},
{
    title: 'We are using List item and we will integrate flat list with it.testing done.',
    icon: 'flight-takeoff'
},
{
    title: 'We are using List item and we will integrate flat list with it.testing done.',
    icon: 'flight-takeoff'
},
{
    title: 'We are using List item and we will integrate flat list with it.testing done.',
    icon: 'flight-takeoff'
},
{
    title: 'We are using List item and we will integrate flat list with it.testing done.',
    icon: 'flight-takeoff'
},
{
    title: 'We are using List item and we will integrate flat list with it.testing done.',
    icon: 'flight-takeoff'
},
{
    title: 'We are using List item and we will integrate flat list with it.testing done.',
    icon: 'flight-takeoff'
},
{
    title: 'We are using List item and we will integrate flat list with it.testing done.',
    icon: 'flight-takeoff'
},
//... // more items
]

export default class Property extends React.Component {
[enter image description here][1]  state = {
    index: 0,
    isUnmounted: false,
    routes: [
        { key: 'newProjects', title: 'New Projects(3)' },
        { key: 'rentals', title: 'Rentals(4)' },
        { key: 'resale', title: 'Resale(8)' }

    ],
};

componentDidMount() {
    this.setState({ isUnmounted: true });

}

detailedScreen = () => {
    alert('Pressed OK');
}
keyExtractor = (item, index) => index.toString()
renderItem = ({ item }) => (
    <Card
        containerStyle={{ borderRadius: 5, borderWidth: 1 }}
        imageStyle={{ borderColor: 'transparent', borderWidth: 1, borderRadius: 5 }}
        image={require('../../../propertiyImage.jpg')}
        featuredSubtitle='8 Leads'
        onPress={() => {
            alert('You tapped the button!');
        }}
    >
        <View style={{ flex: 1, flexDirection: 'row' }}>
            <Text style={{ marginBottom: 10, flex: 3 }}>
                Hero World Trade Tower{'\n\n'}
                <Icon name="map-marker" size={16} /> Ambegaon
        </Text>
            <Text style={{ marginBottom: 10, flex: 1 }}>
                8 Leads
        </Text>
        </View>
    </Card>
)
NewProjects = () => (
    <FlatList
        keyExtractor={this.keyExtractor}
        data={list}
        renderItem={this.renderItem}
    />
);

Rentals = () => (
    <FlatList
        keyExtractor={this.keyExtractor}
        data={list}
        renderItem={this.renderItem}
    />
);
Resale = () => (
    <FlatList
        keyExtractor={this.keyExtractor}
        data={list}
        renderItem={this.renderItem}
    />
);
renderTabBar = props => {
    return (
        <TabBar
            {...props}
            indicatorStyle={{ backgroundColor: 'black' }}
            style={{ backgroundColor: 'white', color: 'black' }}
            renderLabel={this.renderLabel}
        />
    )
};
renderLabel = ({ route, focused }) => (
    <Text style={{ color: 'black' }}>
        {route.title}
    </Text>
);

render() {
    return (
        <TabView
            navigationState={this.state}
            renderScene={SceneMap({
                newProjects: this.NewProjects,
                rentals: this.Rentals,
                resale: this.Resale
            })}
            onIndexChange={index => this.setState({ index })}
            renderTabBar={this.renderTabBar}
            initialLayout={{ width: Dimensions.get('window').width }}
            scrollEnabled={true}
            tabStyle={{ width: 600, backgroundColor: 'red' }}

        />
    );
}

} `

You can see that screens are rendered properly

You can see that first screen is not rendered properly

0 个答案:

没有答案