implement touch to seek for media playback using the seek bar (#271)
This commit is contained in:
parent
a34a8136c2
commit
7313e2d1c4
4 changed files with 39 additions and 5 deletions
|
@ -1,9 +1,10 @@
|
||||||
// @flow
|
// @flow
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Text, TouchableOpacity, View } from 'react-native';
|
import { ActivityIndicator, Text, TouchableOpacity, View } from 'react-native';
|
||||||
import { formatCredits } from 'lbry-redux'
|
import { formatCredits } from 'lbry-redux'
|
||||||
import Address from '../address';
|
import Address from '../address';
|
||||||
import Button from '../button';
|
import Button from '../button';
|
||||||
|
import Colors from '../../styles/colors';
|
||||||
import floatingButtonStyle from '../../styles/floatingButton';
|
import floatingButtonStyle from '../../styles/floatingButton';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
|
@ -17,6 +18,7 @@ class FloatingWalletBalance extends React.PureComponent<Props> {
|
||||||
return (
|
return (
|
||||||
<TouchableOpacity style={[floatingButtonStyle.container, floatingButtonStyle.bottomRight]}
|
<TouchableOpacity style={[floatingButtonStyle.container, floatingButtonStyle.bottomRight]}
|
||||||
onPress={() => navigation && navigation.navigate({ routeName: 'Wallet' })}>
|
onPress={() => navigation && navigation.navigate({ routeName: 'Wallet' })}>
|
||||||
|
{isNaN(balance) && <ActivityIndicator size="small" color={Colors.White} />}
|
||||||
<Text style={floatingButtonStyle.text}>
|
<Text style={floatingButtonStyle.text}>
|
||||||
{(balance || balance === 0) && (formatCredits(balance, 2) + ' LBC')}
|
{(balance || balance === 0) && (formatCredits(balance, 2) + ' LBC')}
|
||||||
</Text>
|
</Text>
|
||||||
|
|
|
@ -295,6 +295,17 @@ class MediaPlayer extends React.PureComponent {
|
||||||
return encodedFilePath;
|
return encodedFilePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onSeekerTouchAreaPressed = (evt) => {
|
||||||
|
if (evt && evt.nativeEvent) {
|
||||||
|
const newSeekerPosition = evt.nativeEvent.locationX;
|
||||||
|
if (!isNaN(newSeekerPosition)) {
|
||||||
|
const time = this.state.duration * (newSeekerPosition / this.seekerWidth);
|
||||||
|
this.setSeekerPosition(newSeekerPosition);
|
||||||
|
this.seekTo(time);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { backgroundPlayEnabled, fileInfo, thumbnail, onLayout, style } = this.props;
|
const { backgroundPlayEnabled, fileInfo, thumbnail, onLayout, style } = this.props;
|
||||||
const completedWidth = this.getCurrentTimePercentage() * this.seekerWidth;
|
const completedWidth = this.getCurrentTimePercentage() * this.seekerWidth;
|
||||||
|
@ -348,6 +359,10 @@ class MediaPlayer extends React.PureComponent {
|
||||||
{ left: this.state.seekerPosition }]} { ...this.seekResponder.panHandlers }>
|
{ left: this.state.seekerPosition }]} { ...this.seekResponder.panHandlers }>
|
||||||
<View style={this.state.seeking ? mediaPlayerStyle.bigSeekerCircle : mediaPlayerStyle.seekerCircle} />
|
<View style={this.state.seeking ? mediaPlayerStyle.bigSeekerCircle : mediaPlayerStyle.seekerCircle} />
|
||||||
</View>
|
</View>
|
||||||
|
<TouchableOpacity
|
||||||
|
style={[mediaPlayerStyle.seekerTouchArea,
|
||||||
|
(this.state.fullscreenMode ? mediaPlayerStyle.seekerTouchAreaFs : mediaPlayerStyle.seekerTouchAreaContained)]}
|
||||||
|
onPress={this.onSeekerTouchAreaPressed} />
|
||||||
</View>}
|
</View>}
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
|
|
|
@ -229,6 +229,10 @@ class FilePage extends React.PureComponent {
|
||||||
const isLandscape = screenWidth > screenHeight;
|
const isLandscape = screenWidth > screenHeight;
|
||||||
this.setState({ isLandscape });
|
this.setState({ isLandscape });
|
||||||
|
|
||||||
|
if (!this.playerBackground) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (isLandscape) {
|
if (isLandscape) {
|
||||||
this.playerBackground.setNativeProps({ height: screenHeight - StyleSheet.flatten(uriBarStyle.uriContainer).height });
|
this.playerBackground.setNativeProps({ height: screenHeight - StyleSheet.flatten(uriBarStyle.uriContainer).height });
|
||||||
} else if (this.state.playerBgHeight > 0) {
|
} else if (this.state.playerBgHeight > 0) {
|
||||||
|
|
|
@ -39,7 +39,7 @@ const mediaPlayerStyle = StyleSheet.create({
|
||||||
},
|
},
|
||||||
fullscreenTrackingControls: {
|
fullscreenTrackingControls: {
|
||||||
alignSelf: 'center',
|
alignSelf: 'center',
|
||||||
width: '70%'
|
width: '60%'
|
||||||
},
|
},
|
||||||
playerControls: {
|
playerControls: {
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
|
@ -75,7 +75,7 @@ const mediaPlayerStyle = StyleSheet.create({
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
left: 8,
|
left: 8,
|
||||||
bottom: 24,
|
bottom: 24,
|
||||||
fontSize: 12,
|
fontSize: 14,
|
||||||
color: '#ffffff'
|
color: '#ffffff'
|
||||||
},
|
},
|
||||||
totalDuration: {
|
totalDuration: {
|
||||||
|
@ -83,7 +83,7 @@ const mediaPlayerStyle = StyleSheet.create({
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
right: 40,
|
right: 40,
|
||||||
bottom: 24,
|
bottom: 24,
|
||||||
fontSize: 12,
|
fontSize: 14,
|
||||||
color: '#ffffff'
|
color: '#ffffff'
|
||||||
},
|
},
|
||||||
seekerCircle: {
|
seekerCircle: {
|
||||||
|
@ -100,7 +100,8 @@ const mediaPlayerStyle = StyleSheet.create({
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
height: 36,
|
height: 36,
|
||||||
width: 48,
|
width: 48,
|
||||||
marginLeft: -18
|
marginLeft: -18,
|
||||||
|
zIndex: 20
|
||||||
},
|
},
|
||||||
seekerHandleContained: {
|
seekerHandleContained: {
|
||||||
bottom: -17
|
bottom: -17
|
||||||
|
@ -108,6 +109,18 @@ const mediaPlayerStyle = StyleSheet.create({
|
||||||
seekerHandleFs: {
|
seekerHandleFs: {
|
||||||
bottom: 0
|
bottom: 0
|
||||||
},
|
},
|
||||||
|
seekerTouchArea: {
|
||||||
|
position: 'absolute',
|
||||||
|
height: 30,
|
||||||
|
width: '100%',
|
||||||
|
zIndex: 10,
|
||||||
|
},
|
||||||
|
seekerTouchAreaContained: {
|
||||||
|
bottom: -15,
|
||||||
|
},
|
||||||
|
seekerTouchAreaFs: {
|
||||||
|
bottom: 0
|
||||||
|
},
|
||||||
bigSeekerCircle: {
|
bigSeekerCircle: {
|
||||||
borderRadius: 24,
|
borderRadius: 24,
|
||||||
position: 'relative',
|
position: 'relative',
|
||||||
|
|
Loading…
Reference in a new issue