import React, { useState, useContext } from 'react'; import { View, StyleSheet, Text, Dimensions, TouchableWithoutFeedback, Platform } from 'react-native'; import { Icon, Slider } from 'react-native-elements'; import C from 'rn-class'; import {PlayerStateContext, PlayerDispatchContext, playerCommon} from './PlayerReducer'; const { width } = Dimensions.get('window'); export const PLACEHOLDER_WIDTH = width / 4; export default PlayerControls = props => { const { Pages, closePlayer, currentPlayerValue, setCurrentPlayerValue} = props; const [curPlayerValue, setCurPlayerValue] = useState(0); const [isPlay, setPlay] = useState(false); const playerDispatch = useContext(PlayerDispatchContext); const playerState = useContext(PlayerStateContext); const {paused, player, duration, currentTime} = playerState; const { secondsTohhmmss } = playerCommon; const {playerData} = Pages; const onSetPlay = () => { //setPlay(!isPlay); playerDispatch({type:'paused', setPaused:!paused}); }; const getThumbTopFromStyleHeight = (styleHeight=40, trackHeight=4) => { const thumbTop = (styleHeight / 2) + (trackHeight / 2) + (Platform.OS==='android'&&(styleHeight<40||trackHeight<4)?0.5:0); return { sh: {height:styleHeight}, th: {height:trackHeight}, tt: {top:thumbTop} } } const sliderLayout = getThumbTopFromStyleHeight(20,2); return ( <> {playerData.title.replace(/\r\n|\n|\r/gm,' ')} {secondsTohhmmss(duration)} playerDispatch({type: 'seek', seekValue: Math.floor(value)})} /> { paused===false ? : } ); }; const styles = StyleSheet.create({ container: { ...StyleSheet.absoluteFillObject, flexDirection: 'row', justifyContent: 'space-around', alignItems: 'center' }, placeholder: { width: PLACEHOLDER_WIDTH } });