-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
fix(rn): 修复previewImage 预览图片API的current必须是urls其中的一个 #11632
base: 3.x
Are you sure you want to change the base?
Conversation
3.4.5-zeta.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这不是 bug,是为了提醒使用者需要校验好这两个属性的,不然没法 previewImage
current控制显示任何一张图片,urls用于控制需要预览的一些图片(可能预览除cunrrent显示之外的图片,也存在这样的真实场景),当urls里不包括current的图片时 我试过是可以正常预览的,而且不做这样的校验更灵活,且其他端侧也没有这样的限制 |
删除这段限制后,不包括 current 也可以正常预览是因为做了兼容。 index={index === -1 ? 0 : index} 此外,这块可以确实可以优化一下:处理成 current 非必填,此时默认取第一个。但是,如果没有 urls 的限制还是要有的。参考如下: let index = 0
if (urls.length === 0) {
throw new Error('"current" or "urls" is invalid')
} else {
index = Math.max(current, urls.indexOf(current))
} |
可以的 |
@iChengbo 再review一个 |
|
||
let index = 0 | ||
if (urls.length === 0) { | ||
throw new Error('"current" or "urls" is invalid') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里把提示文案给改下吧
if (urls.length === 0) { | ||
throw new Error('"current" or "urls" is invalid') | ||
} else { | ||
index = Math.max(current, urls.indexOf(current)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的 urls.indexOf(current) 可以先声明出来,然后 === -1 时给个 warning 信息(console.warn('xxxx xxxx xxxx')),不等于 -1 时再取 max。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
突然发现不能取max,因为curreny是一个字符串,取max是返回的NaN
改成这样看是否可以?
let index = 0
if (!urls || urls.length === 0) {
throw new Error('待预览的图片列表"urls"不能为空')
} else {
urls.indexOf(current) === -1 ? console.warn('显示的图片不在预览列表当中') : ''
index = Math.max(0, urls.indexOf(current))
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 提示文案翻译成英文;
- 下面一段你看看这样写呢?少执行一次 indexOf
const _index = urls.indexOf(current)
if (_index === -1) {
console.warn('xxxx')
}
index = Math.max(0, _index)
…an/taro into feature-fix-previewImage
|
||
let index = 0 | ||
if (!urls || urls.length === 0) { | ||
throw new Error('the list of images to be previewed "urls" cannot be empty') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the "urls" cannot be empty
throw new Error('the list of images to be previewed "urls" cannot be empty') | ||
} else { | ||
const _index = urls.indexOf(current) | ||
_index === -1 ? console.warn('the displayed image is not in the preview list') : '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_index === -1 && console.warning('"current" is not listed in the "urls"')
} else { | ||
const _index = urls.indexOf(current) | ||
_index === -1 ? console.warn('the displayed image is not in the preview list') : '' | ||
index = Math.max(0, _index) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
修改后把 commit 合并成一个就行了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个我们 squash and merge 就会是一个commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
哦哦 我以为要先合并呢😂
这个 PR 做了什么? (简要描述所做更改)
修复previewImage 预览图片API的current必须是urls其中的一个,当current不是urls当中一个时,程序抛出异常,这个pr解决这个bug,去掉这个校验
这个 PR 是什么类型? (至少选择一个)
这个 PR 涉及以下平台: