From 1b9fe0d05ce2fed3ea6c12286283e2ac58f8ecb0 Mon Sep 17 00:00:00 2001 From: aniketbiswas21 Date: Thu, 22 Apr 2021 13:54:14 +0530 Subject: [PATCH] feat: added a boolean to modify the current previous song handler --- README.md | 2 ++ __tests__/tests/__snapshots__/locale.test.js.snap | 2 ++ example/example.js | 15 +++++++++++++++ index.d.ts | 1 + src/index.js | 8 ++++++++ 5 files changed, 28 insertions(+) diff --git a/README.md b/README.md index 2cbbdc1e..0d36c029 100644 --- a/README.md +++ b/README.md @@ -203,6 +203,7 @@ ReactDOM.render( | mobileMediaQuery | `string` | `(max-width: 768px) and (orientation : portrait)` | custom mobile media query string, eg use the mobile version UI on iPad. | | volumeFade | `{ fadeIn: number(ms), fadeOut: number(ms) }` | `-` | audio fade in and out. [Detail](#bulb-audio-volume-fade-in-and-fade-out) | | sortableOptions | `object` | `{swap: true, animation: 100, swapClass: 'audio-lists-panel-sortable-highlight-bg'}` | [SortableJs Options](https://github.com/SortableJS/Sortable#options) | +| restartCurrentOnPrev | `boolean` | `false` | Restarts the current track when trying to play previous song, if the current time of the song is more than 1 second | ## :bulb: Custom operation ui @@ -222,6 +223,7 @@ Support feature: - `play prev audio` - `play audio by custom play index` - `update play index` +- `restart current song on play prev audio` - [SortableJS methods](https://github.com/SortableJS/Sortable#methods) ```jsx diff --git a/__tests__/tests/__snapshots__/locale.test.js.snap b/__tests__/tests/__snapshots__/locale.test.js.snap index 9bc7b4bb..fa745df4 100644 --- a/__tests__/tests/__snapshots__/locale.test.js.snap +++ b/__tests__/tests/__snapshots__/locale.test.js.snap @@ -77,6 +77,7 @@ exports[`Locale test should render default locale with en_US 1`] = ` remember={false} remove={true} responsive={true} + restartCurrentOnPrev={false} seeked={true} showDestroy={true} showDownload={true} @@ -771,6 +772,7 @@ exports[`Locale test should render locale with zh_CN 1`] = ` remember={false} remove={true} responsive={true} + restartCurrentOnPrev={false} seeked={true} showDestroy={true} showDownload={true} diff --git a/example/example.js b/example/example.js index 904803f2..b9295b3a 100644 --- a/example/example.js +++ b/example/example.js @@ -260,6 +260,12 @@ const options = { fadeIn: 1000, fadeOut: 1000, }, + /** + * Restarts the current track when trying to play previous song, if the current time of the song is more than 1 second + Otherwise, plays the previous song in the list + [type `Boolean` default `false`] + */ + restartCurrentOnPrev: false, // https://github.com/SortableJS/Sortable#options sortableOptions: {}, @@ -989,6 +995,15 @@ class Demo extends React.PureComponent { /> quietUpdate +
theme :{params.theme} { + const { restartCurrentOnPrev } = this.props + if (restartCurrentOnPrev && this.audio.currentTime > 1) { + this.audio.currentTime = 0 + return + } + this.audioPrevAndNextBasePlayHandle(false) }