Skip to content

Commit 6216e7d

Browse files
committed
improve touch interactions
Play button is larger (easier to touch). Can both start and stop sounds. Sound doesn’t restart on mouseEnter if the sound is already playing. Sound stops if you move off play button Missing: stop button does not revert to play button when the sound finishes.
1 parent 8ff41a3 commit 6216e7d

File tree

5 files changed

+61
-9
lines changed

5 files changed

+61
-9
lines changed
Lines changed: 28 additions & 0 deletions
Loading

src/components/library-item/library-item.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@
208208
justify-content: center;
209209

210210
overflow: hidden; /* Mask the icon animation */
211-
width: 1.5rem;
212-
height: 1.5rem;
211+
width: 2.5rem;
212+
height: 2.5rem;
213213
background-color: $sound-primary;
214214
color: $ui-white;
215215
border-radius: 50%;

src/components/library-item/library-item.jsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import classNames from 'classnames';
99
import bluetoothIconURL from './bluetooth.svg';
1010
import internetConnectionIconURL from './internet-connection.svg';
1111
import playIcon from './icon--play.svg';
12+
import stopIcon from './icon--stop.svg';
1213

1314
const preventClick = e => {
1415
e.stopPropagation();
16+
e.preventDefault();
1517
};
1618

1719
/* eslint-disable react/prefer-stateless-function */
@@ -141,15 +143,14 @@ class LibraryItemComponent extends React.PureComponent {
141143
<div
142144
aria-label="Play"
143145
className={styles.playButton}
144-
role="button"
145-
tabIndex="0"
146146
onClick={preventClick}
147-
onMouseDown={this.props.onPlay}
147+
onMouseDown={this.props.isPlaying ? this.props.onStop : this.props.onPlay}
148+
onMouseLeave={this.props.isPlaying ? this.props.onStop : null}
148149
>
149150
<img
150151
className={styles.playIcon}
151152
draggable={false}
152-
src={playIcon}
153+
src={this.props.isPlaying ? stopIcon : playIcon}
153154
/>
154155
</div>
155156
) : null}
@@ -174,6 +175,7 @@ LibraryItemComponent.propTypes = {
174175
iconURL: PropTypes.string,
175176
insetIconURL: PropTypes.string,
176177
internetConnectionRequired: PropTypes.bool,
178+
isPlaying: PropTypes.bool,
177179
name: PropTypes.oneOfType([
178180
PropTypes.string,
179181
PropTypes.node
@@ -185,6 +187,7 @@ LibraryItemComponent.propTypes = {
185187
onMouseEnter: PropTypes.func.isRequired,
186188
onMouseLeave: PropTypes.func.isRequired,
187189
onPlay: PropTypes.func.isRequired,
190+
onStop: PropTypes.func.isRequired,
188191
showPlayButton: PropTypes.bool
189192
};
190193

src/components/library/library.jsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class LibraryComponent extends React.Component {
4343
'setFilteredDataRef'
4444
]);
4545
this.state = {
46-
selectedItem: null,
46+
playingItem: null,
4747
filterQuery: '',
4848
selectedTag: ALL_TAG.tag,
4949
loaded: false
@@ -75,10 +75,20 @@ class LibraryComponent extends React.Component {
7575
});
7676
}
7777
handleMouseEnter (id) {
78-
if (this.props.onItemMouseEnter) this.props.onItemMouseEnter(this.getFilteredData()[id]);
78+
console.log('Library MouseEnter id:', id, ', playingItem: ', this.state.playingItem);
79+
// don't restart if mouse over already playing item
80+
if (this.props.onItemMouseEnter && this.state.playingItem !== id) {
81+
this.setState({
82+
playingItem: id
83+
}, this.props.onItemMouseEnter(this.getFilteredData()[id]));
84+
}
7985
}
8086
handleMouseLeave (id) {
81-
if (this.props.onItemMouseLeave) this.props.onItemMouseLeave(this.getFilteredData()[id]);
87+
if (this.props.onItemMouseLeave) {
88+
this.setState({
89+
playingItem: null
90+
}, this.props.onItemMouseLeave(this.getFilteredData()[id]));
91+
}
8292
}
8393
handleFilterChange (event) {
8494
this.setState({
@@ -185,6 +195,7 @@ class LibraryComponent extends React.Component {
185195
id={index}
186196
insetIconURL={dataItem.insetIconURL}
187197
internetConnectionRequired={dataItem.internetConnectionRequired}
198+
isPlaying={this.state.playingItem === index}
188199
key={typeof dataItem.name === 'string' ? dataItem.name : dataItem.rawURL}
189200
name={dataItem.name}
190201
showPlayButton={this.props.showPlayButton}

src/containers/library-item.jsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class LibraryItem extends React.PureComponent {
1616
'handleMouseEnter',
1717
'handleMouseLeave',
1818
'handlePlay',
19+
'handleStop',
1920
'rotateIcon',
2021
'startRotatingIcons',
2122
'stopRotatingIcons'
@@ -65,8 +66,14 @@ class LibraryItem extends React.PureComponent {
6566
}
6667
handlePlay (e) {
6768
e.stopPropagation(); // To prevent from bubbling back to handleClick
69+
e.preventDefault();
6870
this.props.onMouseEnter(this.props.id);
6971
}
72+
handleStop (e) {
73+
e.stopPropagation(); // To prevent from bubbling back to handleClick
74+
e.preventDefault();
75+
this.props.onMouseLeave(this.props.id);
76+
}
7077
startRotatingIcons () {
7178
this.rotateIcon();
7279
this.intervalId = setInterval(this.rotateIcon, 300);
@@ -109,6 +116,7 @@ class LibraryItem extends React.PureComponent {
109116
id={this.props.id}
110117
insetIconURL={this.props.insetIconURL}
111118
internetConnectionRequired={this.props.internetConnectionRequired}
119+
isPlaying={this.props.isPlaying}
112120
name={this.props.name}
113121
showPlayButton={this.props.showPlayButton}
114122
onBlur={this.handleBlur}
@@ -118,6 +126,7 @@ class LibraryItem extends React.PureComponent {
118126
onMouseEnter={this.handleMouseEnter}
119127
onMouseLeave={this.handleMouseLeave}
120128
onPlay={this.handlePlay}
129+
onStop={this.handleStop}
121130
/>
122131
);
123132
}
@@ -144,6 +153,7 @@ LibraryItem.propTypes = {
144153
id: PropTypes.number.isRequired,
145154
insetIconURL: PropTypes.string,
146155
internetConnectionRequired: PropTypes.bool,
156+
isPlaying: PropTypes.bool,
147157
name: PropTypes.oneOfType([
148158
PropTypes.string,
149159
PropTypes.node

0 commit comments

Comments
 (0)