Skip to content

Commit

Permalink
fix: should not call onAudioListsPanelChange if panel is closed when …
Browse files Browse the repository at this point in the history
…hide panel
  • Loading branch information
lijinke666 committed Sep 19, 2020
1 parent 52ba3ae commit ade1774
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
17 changes: 17 additions & 0 deletions __tests__/tests/player.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1478,4 +1478,21 @@ describe('<ReactJkMusicPlayer/>', () => {
wrapper.instance().onAudioCanPlay()
expect(onAudioPlay).toHaveBeenCalled()
})

it('should not call onAudioListsPanelChange if panel is closed when hide panel', () => {
const onAudioListsPanelChange = jest.fn()
const wrapper = mount(
<ReactJkMusicPlayer
audioLists={[
{ musicSrc: 'aaa', name: 'aaa' },
{ musicSrc: 'ddd', name: 'ddd' },
]}
mode="full"
onAudioListsPanelChange={onAudioListsPanelChange}
/>,
)

wrapper.find('.hide-panel').simulate('click')
expect(onAudioListsPanelChange).not.toHaveBeenCalled()
})
})
8 changes: 5 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

// FIXME: quietUpdate 更新之后 不能点击播放列表里的其他歌曲
// FIXME: audio lists panel visible 收起时会调用
import cls from 'classnames'
import download from 'downloadjs'
import getIsMobile from 'is-mobile'
Expand Down Expand Up @@ -917,9 +916,12 @@ export default class ReactJkMusicPlayer extends PureComponent {
}

_closeAudioListsPanel = () => {
const { audioListsPanelVisible } = this.state
this.setState({ audioListsPanelVisible: false })
this.props.onAudioListsPanelChange &&
this.props.onAudioListsPanelChange(false)
if (audioListsPanelVisible) {
this.props.onAudioListsPanelChange &&
this.props.onAudioListsPanelChange(false)
}
}

themeChange = (isLight) => {
Expand Down

0 comments on commit ade1774

Please sign in to comment.