Skip to content

Commit e9bacd0

Browse files
committed
fix progress bar when switching layout
1 parent 7712515 commit e9bacd0

File tree

6 files changed

+59
-1
lines changed

6 files changed

+59
-1
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ module.exports = {
111111
'template-curly-spacing': [2, 'never'],
112112
'@typescript-eslint/ban-ts-comment': 0,
113113
'@typescript-eslint/no-misused-promises': 0,
114+
'@typescript-eslint/no-unsafe-member-access': 0,
114115
},
115116
overrides: [
116117
{

.husky/pre-commit

100644100755
File mode changed.

src/ProgressBar.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class ProgressBar extends Component<ProgressBarProps, ProgressBarState> {
191191
}, 200)
192192
}
193193

194-
componentDidUpdate(): void {
194+
initialize(): void {
195195
const { audio } = this.props
196196
if (audio && !this.hasAddedAudioEventListener) {
197197
this.audio = audio
@@ -201,6 +201,14 @@ class ProgressBar extends Component<ProgressBarProps, ProgressBarState> {
201201
}
202202
}
203203

204+
componentDidMount(): void {
205+
this.initialize()
206+
}
207+
208+
componentDidUpdate(): void {
209+
this.initialize()
210+
}
211+
204212
componentWillUnmount(): void {
205213
if (this.audio && this.hasAddedAudioEventListener) {
206214
this.audio.removeEventListener('timeupdate', this.handleAudioTimeUpdate)

stories/change-layout.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React, { useState } from 'react'
2+
import AudioPlayer, { RHAP_UI } from '../src/index.tsx'
3+
import { MAIN_LAYOUT } from '../src/constants.ts'
4+
5+
const expandedPlayerProps: {
6+
layout: MAIN_LAYOUT
7+
customControlsSection: RHAP_UI[]
8+
customProgressBarSection: RHAP_UI[]
9+
} = {
10+
layout: 'stacked',
11+
customControlsSection: [RHAP_UI.CURRENT_TIME, RHAP_UI.CURRENT_LEFT_TIME],
12+
customProgressBarSection: [RHAP_UI.PROGRESS_BAR, RHAP_UI.MAIN_CONTROLS],
13+
}
14+
15+
const ChangeLayout: React.FC = () => {
16+
const [config, setConfig] = useState({})
17+
18+
const setStacked = () => setConfig(expandedPlayerProps)
19+
const setHorizontal = () => setConfig({})
20+
21+
return (
22+
<div className="container">
23+
<button onClick={setStacked}>stacked</button>
24+
<button onClick={setHorizontal}>horizontal</button>
25+
26+
<h1>Hello, audio player!</h1>
27+
<AudioPlayer
28+
src="https://www.soundhelix.com/examples/mp3/SoundHelix-Song-9.mp3"
29+
volume={0.5}
30+
layout="stacked-reverse"
31+
{...config}
32+
/>
33+
</div>
34+
)
35+
}
36+
37+
export default ChangeLayout

stories/layouts-advanced.stories.mdx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Meta, Story, Preview } from '@storybook/addon-docs/blocks';
22
import { SAMPLE_MP3_URL } from './utils'
33
import VolumePercentage from './volume-percentage.tsx'
44
import AudioPlayer, { RHAP_UI } from '../src/index.tsx'
5+
import ChangeLayout from './change-layout.tsx'
56

67
<Meta title="Layouts - Advanced" component={AudioPlayer} />
78

@@ -257,3 +258,13 @@ class VolumePercentage extends PureComponent<{}, { volumeText: string }> {
257258
}
258259
/>
259260
```
261+
262+
#### Change Layout
263+
264+
<Story name="Change Layout">
265+
<ChangeLayout />
266+
</Story>
267+
268+
```jsx
269+
<ChangeLayout />
270+
```

tsconfig.eslint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"include": [
44
"./src",
55
"./.eslintrc.js",
6+
"./stories/**/*.tsx",
67
"babel.config.js",
78
"webpack.config.js"
89
]

0 commit comments

Comments
 (0)