【发布时间】:2017-12-16 09:26:41
【问题描述】:
当我尝试从登录屏幕导航到主屏幕时,打开主屏幕大约需要 5 秒钟。您单击登录按钮并等待很长时间,直到它导航到主页。有趣的是,只有导航到主页的按钮会导致此问题。我的意思是它仅在您想要导航主页时发生。似乎问题出在主页上。代码如下:
将包含在主屏幕中的组件文件
const Posts = [
{
id: 1,
title: "Lorem Ipsum",
views: "260 Views",
comments: "19 Comments",
published: "14h ago",
image: require("../img/img1.png"),
},
...
];
const Posts = props => {
return (
<Content>
{Posts.map((item, idx) => {
return <DataContainer {...props} key={idx} item={item} />;
})}
</Content>
);
};
const DataContainer = ({item, navigation}) => {
return (
<Card style={styles.card}>
<TouchableHighlight onPress={() => navigation.navigate("Post")}>
<CardItem cardBody>
<Image
source={item.image}
style={styles.img}
>
<Text
style={styles.text}
>
{item.title}
</Text>
</Image>
</CardItem>
</TouchableHighlight>
<CardItem>
<Left>
<Button transparent>
<Icon
active
name="eye"
style={styles.icon}
/>
<Text style={{color: '#4286f4'}}>
{item.views}
</Text>
</Button>
</Left>
<Body>
<Button transparent>
<Icon
active
name="chatbubbles"
style={styles.icon}
/>
<Text style={{color: '#4286f4'}}>
{item.comments}
</Text>
</Button>
</Body>
<Right>
<Text style={{color: '#4286f4'}}>
{item.published}
</Text>
</Right>
</CardItem>
</Card>
);
};
export default Posts;
主屏幕文件
export default class HomeScreen extends React.Component {
static navigationOptions = {
gesturesEnabled: false,
};
render() {
return (
<Container style={{backgroundColor: '#EEE'}}>
<CommonHeader {...this.props} />
<Tabs tabBarUnderlineStyle={{backgroundColor: '#4286f4'}}>
<Tab
tabStyle={{backgroundColor: '#EEE'}}
heading="Popular"
activeTextStyle={{color: '#4286f4'}}
'#EEE'Style={{backgroundColor: '#EEE'}}
textStyle={{color: '#333333'}}
>
<Posts {...this.props} />
</Tab>
<Tab
tabStyle={{backgroundColor: '#EEE'}}
heading="New"
activeTextStyle={{color: '#4286f4'}}
Style={{backgroundColor: '#EEE'}}
textStyle={{color:'#333333' }}
>
<Posts {...this.props} />
</Tab>
</Tabs>
</Container>
);
}
}
有什么遗漏吗?为什么加载这么慢?在 ios 和 android 设备上也很慢,但在 Android 移动设备上最慢。
【问题讨论】:
标签: react-native react-native-android react-navigation react-native-ios expo