Skip to content
Snippets Groups Projects
Commit 6216e7df authored by Chris Garrity's avatar Chris Garrity
Browse files

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.
parent 8ff41a39
No related branches found
No related tags found
No related merge requests found
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
...@@ -208,8 +208,8 @@ ...@@ -208,8 +208,8 @@
justify-content: center; justify-content: center;
overflow: hidden; /* Mask the icon animation */ overflow: hidden; /* Mask the icon animation */
width: 1.5rem; width: 2.5rem;
height: 1.5rem; height: 2.5rem;
background-color: $sound-primary; background-color: $sound-primary;
color: $ui-white; color: $ui-white;
border-radius: 50%; border-radius: 50%;
......
...@@ -9,9 +9,11 @@ import classNames from 'classnames'; ...@@ -9,9 +9,11 @@ import classNames from 'classnames';
import bluetoothIconURL from './bluetooth.svg'; import bluetoothIconURL from './bluetooth.svg';
import internetConnectionIconURL from './internet-connection.svg'; import internetConnectionIconURL from './internet-connection.svg';
import playIcon from './icon--play.svg'; import playIcon from './icon--play.svg';
import stopIcon from './icon--stop.svg';
const preventClick = e => { const preventClick = e => {
e.stopPropagation(); e.stopPropagation();
e.preventDefault();
}; };
/* eslint-disable react/prefer-stateless-function */ /* eslint-disable react/prefer-stateless-function */
...@@ -141,15 +143,14 @@ class LibraryItemComponent extends React.PureComponent { ...@@ -141,15 +143,14 @@ class LibraryItemComponent extends React.PureComponent {
<div <div
aria-label="Play" aria-label="Play"
className={styles.playButton} className={styles.playButton}
role="button"
tabIndex="0"
onClick={preventClick} onClick={preventClick}
onMouseDown={this.props.onPlay} onMouseDown={this.props.isPlaying ? this.props.onStop : this.props.onPlay}
onMouseLeave={this.props.isPlaying ? this.props.onStop : null}
> >
<img <img
className={styles.playIcon} className={styles.playIcon}
draggable={false} draggable={false}
src={playIcon} src={this.props.isPlaying ? stopIcon : playIcon}
/> />
</div> </div>
) : null} ) : null}
...@@ -174,6 +175,7 @@ LibraryItemComponent.propTypes = { ...@@ -174,6 +175,7 @@ LibraryItemComponent.propTypes = {
iconURL: PropTypes.string, iconURL: PropTypes.string,
insetIconURL: PropTypes.string, insetIconURL: PropTypes.string,
internetConnectionRequired: PropTypes.bool, internetConnectionRequired: PropTypes.bool,
isPlaying: PropTypes.bool,
name: PropTypes.oneOfType([ name: PropTypes.oneOfType([
PropTypes.string, PropTypes.string,
PropTypes.node PropTypes.node
...@@ -185,6 +187,7 @@ LibraryItemComponent.propTypes = { ...@@ -185,6 +187,7 @@ LibraryItemComponent.propTypes = {
onMouseEnter: PropTypes.func.isRequired, onMouseEnter: PropTypes.func.isRequired,
onMouseLeave: PropTypes.func.isRequired, onMouseLeave: PropTypes.func.isRequired,
onPlay: PropTypes.func.isRequired, onPlay: PropTypes.func.isRequired,
onStop: PropTypes.func.isRequired,
showPlayButton: PropTypes.bool showPlayButton: PropTypes.bool
}; };
......
...@@ -43,7 +43,7 @@ class LibraryComponent extends React.Component { ...@@ -43,7 +43,7 @@ class LibraryComponent extends React.Component {
'setFilteredDataRef' 'setFilteredDataRef'
]); ]);
this.state = { this.state = {
selectedItem: null, playingItem: null,
filterQuery: '', filterQuery: '',
selectedTag: ALL_TAG.tag, selectedTag: ALL_TAG.tag,
loaded: false loaded: false
...@@ -75,10 +75,20 @@ class LibraryComponent extends React.Component { ...@@ -75,10 +75,20 @@ class LibraryComponent extends React.Component {
}); });
} }
handleMouseEnter (id) { handleMouseEnter (id) {
if (this.props.onItemMouseEnter) this.props.onItemMouseEnter(this.getFilteredData()[id]); console.log('Library MouseEnter id:', id, ', playingItem: ', this.state.playingItem);
// don't restart if mouse over already playing item
if (this.props.onItemMouseEnter && this.state.playingItem !== id) {
this.setState({
playingItem: id
}, this.props.onItemMouseEnter(this.getFilteredData()[id]));
}
} }
handleMouseLeave (id) { handleMouseLeave (id) {
if (this.props.onItemMouseLeave) this.props.onItemMouseLeave(this.getFilteredData()[id]); if (this.props.onItemMouseLeave) {
this.setState({
playingItem: null
}, this.props.onItemMouseLeave(this.getFilteredData()[id]));
}
} }
handleFilterChange (event) { handleFilterChange (event) {
this.setState({ this.setState({
...@@ -185,6 +195,7 @@ class LibraryComponent extends React.Component { ...@@ -185,6 +195,7 @@ class LibraryComponent extends React.Component {
id={index} id={index}
insetIconURL={dataItem.insetIconURL} insetIconURL={dataItem.insetIconURL}
internetConnectionRequired={dataItem.internetConnectionRequired} internetConnectionRequired={dataItem.internetConnectionRequired}
isPlaying={this.state.playingItem === index}
key={typeof dataItem.name === 'string' ? dataItem.name : dataItem.rawURL} key={typeof dataItem.name === 'string' ? dataItem.name : dataItem.rawURL}
name={dataItem.name} name={dataItem.name}
showPlayButton={this.props.showPlayButton} showPlayButton={this.props.showPlayButton}
......
...@@ -16,6 +16,7 @@ class LibraryItem extends React.PureComponent { ...@@ -16,6 +16,7 @@ class LibraryItem extends React.PureComponent {
'handleMouseEnter', 'handleMouseEnter',
'handleMouseLeave', 'handleMouseLeave',
'handlePlay', 'handlePlay',
'handleStop',
'rotateIcon', 'rotateIcon',
'startRotatingIcons', 'startRotatingIcons',
'stopRotatingIcons' 'stopRotatingIcons'
...@@ -65,8 +66,14 @@ class LibraryItem extends React.PureComponent { ...@@ -65,8 +66,14 @@ class LibraryItem extends React.PureComponent {
} }
handlePlay (e) { handlePlay (e) {
e.stopPropagation(); // To prevent from bubbling back to handleClick e.stopPropagation(); // To prevent from bubbling back to handleClick
e.preventDefault();
this.props.onMouseEnter(this.props.id); this.props.onMouseEnter(this.props.id);
} }
handleStop (e) {
e.stopPropagation(); // To prevent from bubbling back to handleClick
e.preventDefault();
this.props.onMouseLeave(this.props.id);
}
startRotatingIcons () { startRotatingIcons () {
this.rotateIcon(); this.rotateIcon();
this.intervalId = setInterval(this.rotateIcon, 300); this.intervalId = setInterval(this.rotateIcon, 300);
...@@ -109,6 +116,7 @@ class LibraryItem extends React.PureComponent { ...@@ -109,6 +116,7 @@ class LibraryItem extends React.PureComponent {
id={this.props.id} id={this.props.id}
insetIconURL={this.props.insetIconURL} insetIconURL={this.props.insetIconURL}
internetConnectionRequired={this.props.internetConnectionRequired} internetConnectionRequired={this.props.internetConnectionRequired}
isPlaying={this.props.isPlaying}
name={this.props.name} name={this.props.name}
showPlayButton={this.props.showPlayButton} showPlayButton={this.props.showPlayButton}
onBlur={this.handleBlur} onBlur={this.handleBlur}
...@@ -118,6 +126,7 @@ class LibraryItem extends React.PureComponent { ...@@ -118,6 +126,7 @@ class LibraryItem extends React.PureComponent {
onMouseEnter={this.handleMouseEnter} onMouseEnter={this.handleMouseEnter}
onMouseLeave={this.handleMouseLeave} onMouseLeave={this.handleMouseLeave}
onPlay={this.handlePlay} onPlay={this.handlePlay}
onStop={this.handleStop}
/> />
); );
} }
...@@ -144,6 +153,7 @@ LibraryItem.propTypes = { ...@@ -144,6 +153,7 @@ LibraryItem.propTypes = {
id: PropTypes.number.isRequired, id: PropTypes.number.isRequired,
insetIconURL: PropTypes.string, insetIconURL: PropTypes.string,
internetConnectionRequired: PropTypes.bool, internetConnectionRequired: PropTypes.bool,
isPlaying: PropTypes.bool,
name: PropTypes.oneOfType([ name: PropTypes.oneOfType([
PropTypes.string, PropTypes.string,
PropTypes.node PropTypes.node
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment