React Native - 在SectionList中渲染图像时,性能下降到10 fps

时间:2018-02-19 18:09:49

标签: react-native react-native-android

我在一个水平FlatList(react-native-snap-carousel)中有SectionLists。每个SectionList项表示时间轴中的条目。有些项目只是文字,有些也有图像。

滚动时,每次在屏幕上显示图像时, fps会降至10以下。如果我只是评论<Image>标记,以便不渲染图像,则fps最高可达50> fps。

左边的应用有图片,右边的应用评论了<Image />个元素。

performance issue

我只测试了Android上的应用。 有关显示图像时fps下降的原因吗?

renderItem:

  render() {
    const {
      containerStyle,
      hourStyle,
      hourTextStyle,
      contentStyle,
      iconDashesStyle,
      titleText,
      descriptionText,
      notesText
    } = styles;

    const activity = this.props.item;
    const { type, category, date, note } = activity;

    return (
      <View style={containerStyle}>
        <View style={hourStyle} >
          <Text style={hourTextStyle}>
            {moment(date).format('HH:mm')}
          </Text>
        </View>
        <View style={iconDashesStyle}>
          {this.renderIcons()}
          {this.renderDashes()}
        </View>
        <View style={contentStyle}>
          <Text style={titleText}>{getActivityName(type, category).toUpperCase()}</Text>
          <Text style={descriptionText}>{getActivityDescription(activity)}</Text>
          <Text style={notesText}>{note}</Text>
          {this.renderImage()}
        </View>

      </View>
    );
  }

renderImage函数:

  renderImage() {
    const { type } = this.props.item;
    if (type === ID_SHARE_MOMENT && this.props.image) {
      const { uri, ratio } = this.props.image;
      return (
        <View
          ref={r => (this.imgRef = r)}
          style={[styles.momentImgContainer, { aspectRatio: ratio }]}
          collapsable={false}
        >
          <TouchableOpacity onPress={this.onPressImage}> 
            <Image
              style={styles.momentImg}
              source={{ uri }}
              resizeMode='cover'
            />
          </TouchableOpacity>
        </View>
      );
    }
  }

没有图像的第二个应用程序具有如下的renderImage:

       <TouchableOpacity onPress={this.onPressImage}> 
       { /* 
         <Image
           style={styles.momentImg}
           source={{ uri }}
           resizeMode='cover'
         />
       */ }
       </TouchableOpacity>

编辑1

在尝试提高应用程序性能时,我遵循了link of Adam Stanford on medium,建议直接从应用程序包中加载静态资源(通过Xcode资产目录或Android drawable文件夹中包含的图像)。

我开始使用上面显示的屏幕之前的输入屏幕的背景图像,它只有背景图像,徽标和微调器:

entryView

只有在第一张图片中执行此操作,看看发生了什么:

enter image description here

即使在时间线中渲染图像,fps也会上升到40+。但是,我不明白这种关系...

0 个答案:

没有答案