PlayerControls.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import React, { useState } from 'react';
  2. import {
  3. View,
  4. StyleSheet,
  5. Text,
  6. Dimensions,
  7. TouchableWithoutFeedback,
  8. Platform
  9. } from 'react-native';
  10. import { Icon, Slider } from 'react-native-elements';
  11. import C from 'rn-class';
  12. const { width } = Dimensions.get('window');
  13. export const PLACEHOLDER_WIDTH = width / 4;
  14. export default PlayerControls = props => {
  15. const { Pages, closePlayer, currentPlayerValue, setCurrentPlayerValue} = props;
  16. const [curPlayerValue, setCurPlayerValue] = useState(0);
  17. const [isPlay, setPlay] = useState(false);
  18. const onSetPlay = () => {
  19. setPlay(!isPlay);
  20. }
  21. const getThumbTopFromStyleHeight = (styleHeight=40, trackHeight=4) => {
  22. const thumbTop = (styleHeight / 2) + (trackHeight / 2) +
  23. (Platform.OS==='android'&&(styleHeight<40||trackHeight<4)?0.5:0);
  24. return {
  25. sh: {height:styleHeight},
  26. th: {height:trackHeight},
  27. tt: {top:thumbTop}
  28. }
  29. }
  30. const sliderLayout = getThumbTopFromStyleHeight(20,2);
  31. return (
  32. <>
  33. <View style={styles.container}>
  34. <View style={styles.placeholder} />
  35. <C.View cls="flx2">
  36. <C.View cls="flx-row jc-sb">
  37. <Text numerOfLine={1}>{Pages.subtitle.replace(/\r\n|\n|\r/gm,' ')}</Text>
  38. <Text>{`2:50`}</Text>
  39. </C.View>
  40. <Slider
  41. style={sliderLayout.sh}
  42. trackStyle={sliderLayout.th}
  43. thumbTintColor="#333"
  44. thumbStyle={{width:10, height:5, ...sliderLayout.tt}}
  45. value={currentPlayerValue}
  46. onValueChange={value => setCurrentPlayerValue(value)}
  47. />
  48. </C.View>
  49. <C.View cls="flx0.5 jc-sa ai-sa flx-row">
  50. { isPlay
  51. ?<C.EL.Icon {...C.n2cls("size8")} type="ionicon" name="md-pause" onPress={onSetPlay} />
  52. :<C.EL.Icon {...C.n2cls("size8")} type="ionicon" name="md-play" onPress={onSetPlay} />
  53. }
  54. </C.View>
  55. <C.EL.Icon ccls="mr2" type="ionicon" name="md-close" onPress={closePlayer} />
  56. </View>
  57. </>
  58. );
  59. };
  60. const styles = StyleSheet.create({
  61. container: {
  62. ...StyleSheet.absoluteFillObject,
  63. flexDirection: 'row',
  64. justifyContent: 'space-around',
  65. alignItems: 'center'
  66. },
  67. placeholder: {
  68. width: PLACEHOLDER_WIDTH
  69. }
  70. });