-
Notifications
You must be signed in to change notification settings - Fork 45
/
index.js
111 lines (90 loc) · 3.19 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { View, NativeModules, DeviceEventEmitter, Slider, requireNativeComponent, Image, Platform, Dimensions, Text, StyleSheet } from 'react-native';
const ReactNativeVolumeController = NativeModules.ReactNativeVolumeController;
type Event = Object;
export default class SliderVolumeController extends Component {
static propTypes = {
/**
* The color used for the thumb.
*/
thumbTintColor: PropTypes.string,
/**
* The image for the thumb
*/
thumbImage: Image.propTypes.source,
/**
* The size of the thumb area that allows moving the thumb.
* The default is {width: 23, height: 23}.
*/
thumbSize: PropTypes.shape({
width: PropTypes.number,
height: PropTypes.number
}),
/**
* The color used for the track to the left of the button. Overrides the
* default blue gradient image.
*/
minimumTrackTintColor: PropTypes.string,
/**
* The color used for the track to the right of the button. Overrides the
* default blue gradient image.
*/
maximumTrackTintColor: PropTypes.string,
/**
* Specifies whether or not to show the route button for airplay
*/
showsRouteButton: PropTypes.bool,
/**
* Callback continuously called while the user is dragging the slider.
*/
onValueChange: PropTypes.func
};
static defaultProps = {
thumbSize: { width: 23, height: 23 },
showsRouteButton: true
};
constructor(props) {
super(props);
this.state = {volume_value:0.8, has_button_route:false};
this.isDragging = false;
}
render() {
const dimension = Dimensions.get("window")
const viewWidth = dimension.width-20;
let sliderWidth = viewWidth;
let slider = <Slider {...this.props} value={this.state.volume_value} onValueChange={
(value)=>{
this.isDragging = true;
ReactNativeVolumeController.change(value);
ReactNativeVolumeController.update();
setTimeout(()=>{
this.isDragging = false;
}, 500);
}
}/>
if( Platform.OS === 'ios' ){
const onValueChange = this.props.onValueChange && ((event: Event) => {
this.props.onValueChange &&
this.props.onValueChange(event);
});
const { style, ...rest } = this.props;
slider = <ReactNativeVolumeControllerSlider {...rest}
onValueChange={onValueChange}
style={[styles.slider, style, {width:sliderWidth}]}/>
}
return(<View style={[this.props.style, {marginLeft:10, marginRight:10,flex:1, flexDirection:"row", width:viewWidth,
alignItems:'center',
justifyContent:'center'}]}>
{slider}
</View>
);
}
}
const styles = StyleSheet.create({
slider: {
height: 23,
},
});
var ReactNativeVolumeControllerSlider = requireNativeComponent('ReactNativeVolumeController', SliderVolumeController);
export {SliderVolumeController, ReactNativeVolumeController}