Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

百度小程序中 swiper-item、cover-view 和 cover-image 组件使用非递归方式渲染 #9884

Closed
wants to merge 5 commits into from

Conversation

SyMind
Copy link
Member

@SyMind SyMind commented Jul 24, 2021

这个 PR 做了什么? (简要描述所做更改)

百度小程序中 swiper-item、cover-view 和 cover-image 组件使用非递归方式渲染

这个 PR 是什么类型? (至少选择一个)

这个 PR 涉及以下平台:

  • 所有小程序
  • 微信小程序
  • 支付宝小程序
  • 百度小程序
  • 字节跳动小程序
  • QQ 轻应用
  • 京东小程序
  • 快应用平台(QuickApp)
  • Web 平台(H5)
  • 移动端(React-Native)

@SyMind
Copy link
Member Author

SyMind commented Jul 25, 2021

@Chen-jj 看一下。

<button s-elif="{{item.nn==='text'&&(item.st||item.cl)}}}}" id="{{item.uid}}" ${this.buildFlattenNodeAttributes('button')}>
<template is="{{xs.e(0)}}" data="{{{i:item}}}" />
</button>
<input s-elif="{{item.nn==='text'&&(item.st||item.cl)}}}}" id="{{item.uid}}" ${this.buildFlattenNodeAttributes('input')} />
<block s-else>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

漏了对 static-text 的处理,除了不需要绑定事件,和上述 text 一致。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swiper 也麻烦加一下哈

<block s-for="{{item.cn}}" s-key="uid">
${indent(child, 4)}
</block>
</view>
<text s-elif="{{item.nn==='text'&&(item.st||item.cl)}}}}" id="{{item.uid}}" ${this.buildFlattenNodeAttributes('text')}>
<template is="{{xs.e(0)}}" data="{{{i:item}}}" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里错了,item 仍是 text 自身,应该遍历渲染 item.cn

改为:

<block s-for="{{item.cn}}" s-key="uid">
  <block>{{item.v}}</block>
</block>

<text s-elif="{{item.nn==='text'&&(item.st||item.cl)}}}}" id="{{item.uid}}" ${this.buildFlattenNodeAttributes('text')}>
<template is="{{xs.e(0)}}" data="{{{i:item}}}" />
</text>
<button s-elif="{{item.nn==='text'&&(item.st||item.cl)}}}}" id="{{item.uid}}" ${this.buildFlattenNodeAttributes('button')}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应该是 s-elif="{{item.nn==='button',请先在本地测试通过再提交。

<button s-elif="{{item.nn==='text'&&(item.st||item.cl)}}}}" id="{{item.uid}}" ${this.buildFlattenNodeAttributes('button')}>
<template is="{{xs.e(0)}}" data="{{{i:item}}}" />
</button>
<input s-elif="{{item.nn==='text'&&(item.st||item.cl)}}}}" id="{{item.uid}}" ${this.buildFlattenNodeAttributes('input')} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应该是 s-elif="{{item.nn==='input'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

此外,input 应该分为 focus 和 blur 两种,如果比较麻烦,可以先不做

<template is="{{xs.e(0)}}" data="{{{i:item}}}" />
</text>
<button s-elif="{{item.nn==='text'&&(item.st||item.cl)}}}}" id="{{item.uid}}" ${this.buildFlattenNodeAttributes('button')}>
<template is="{{xs.e(0)}}" data="{{{i:item}}}" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改为:

<block s-for="{{item.cn}}" s-key="uid">
  <template is="{{xs.e(0)}}" data="{{{ i:item }}}" />
</block>

case 'textarea':
case 'camera':
case 'live-player':
case 'input':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

input textarea 被配置了 voidElements,所以这里对它们的模板没有用处

</block>
</cover-view>
<cover-image s-elif="{{item.nn==='cover-image'}}" id="{{item.uid}}" ${this.buildFlattenNodeAttributes('cover-image')}></cover-image>
<block s-else>{{item.v}}</block>`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里应该是 <block s-else><template is="{{xs.e(0)}}" data="{{{i:item}}}" /></block>,现在的处理就只能渲染文本节点。

@Chen-jj
Copy link
Contributor

Chen-jj commented Aug 12, 2021

@SyMind 增加了其他组件的支持后,情况是相当复杂的,有很多排列组合的场景都需要测试,请按上述评论进行修改,并在本地先进行尽量完备的测试。

这是我的测试用例,可能还有一些考虑不全的地方,请修改后回复一下你的测试用例:

import { Component } from 'react'
import { View, Input, Text, Button, Canvas, CoverView, CoverImage, Swiper, SwiperItem } from '@tarojs/components'
import './index.scss'

export default class Index extends Component {
  render () {
    return (
      <View>
        <View className='box'>
          <Text className='item'>s-text 1</Text>
          <Text className='item'>s-text 2</Text>
        </View>
        <View className='box'>
          <Text onClick={() => {}} className='item'>text 1</Text>
          <Text onClick={() => {}} className='item'>text 2</Text>
        </View>
        <View className='box'>
          <Button className='item'>Button 1</Button>
          <Button className='item'>Button 2</Button>
        </View>
        <View className='box'>
          <Input type='text' placeholder='A' onClick={() => {}} className='item'>A</Input>
          <Input type='text' placeholder='A1' onClick={() => {}} className='item'>Hello world!</Input>
        </View>
        <Canvas canvasId='my'>
          <CoverView className='box'>
            <CoverView className='item'>1</CoverView>
            <CoverView className='item'>2</CoverView>
            <CoverImage className='item'></CoverImage>
            <View>
              <Text>3</Text>
            </View>
          </CoverView>
        </Canvas>
      </View>
    )
  }
}


if (nodeName === 'picker-view') {
return `<picker-view-column name="{{ item.name }}" style="{{ item.st }}" class="{{ item.cl }}" bindtap="eh" id="{{item.uid}}">
modifyLoopContainer = (children: string, nodeName: string): string => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这段不需要修改,因为 swiper > swiper-item + swiper-item 这种情况就是不支持 flex 的。

buildFlattenView 里处理 view > swiper + swiper 这种情况即可。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
V-3 Version - 3.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants