我正在使用react native开发带有onpress事件的简单Touchablehighlight元素。 iOS可以使用,但Android每次需要花费几秒钟来加载功能。我查找了几种可能的解决方案,例如TouchableWithoutFeedback,TouchableNativeFeedback等。
我的想法是单击一个Flatable下的TouchableHighlight->调用handlePress函数-> alert('hello world')
这是我的代码。
import React from "react";
import { Image, TouchableHighlight, Platform, TouchableNativeFeedback, View, Text } from "react-native";
import styles from "./Styles";
// Plugin
import FastImage from "react-native-fast-image";
class BacktoTop extends React.Component {
constructor(props) {
super(props);
}
_handlePress = () => {
alert('hello world')
}
render() {
return (
<TouchableHighlight
style={ styles.container }
underlayColor={"#ffffff"}
// onPress={this.props.handlePress }
onPress={this._handlePress }>
<FastImage
source={
(Platform.OS === 'ios') ?
require("../../images/back_to_top.png")
:
{
// 6 months at least 1 view no deletion
uri: 'https://image.ibb.co/grvFS8/back_to_top.png',
priority: FastImage.priority.cacheOnly,
}
}
resizeMode={FastImage.resizeMode.cover}
style={{ width: 35, height: 35 }} />
</TouchableHighlight>
);
}
}
export default BacktoTop;
非常感谢您的帮助。
答案 0 :(得分:0)
我认为要渲染的上层视图组件越多,加载时间就越长。
在我删除了一些父项并删除了onMomentumScrollEnd之后,反应得到了改善。
谢谢。