forked from damowanglidong/react-native-polyv
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLive.js
More file actions
97 lines (78 loc) · 2.24 KB
/
Live.js
File metadata and controls
97 lines (78 loc) · 2.24 KB
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
import React, { Component } from "react";
import { requireNativeComponent } from "react-native";
const PropTypes = require("prop-types");
class Live extends Component {
constructor(props) {
super(props);
this._assignRoot = this._assignRoot.bind(this);
this.message = this.message.bind(this);
this._onLoaded = this._onLoaded.bind(this);
this._onStop = this._onStop.bind(this);
this._onError = this._onError.bind(this);
this._onPlaying = this._onPlaying.bind(this);
this._onReceiveMessage = this._onReceiveMessage.bind(this);
}
_assignRoot(component) {
this._root = component;
}
setNativeProps(nativeProps) {
this._root.setNativeProps(nativeProps);
}
paused(paused) {
this.setNativeProps({ paused: paused });
}
message(message) {
this.setNativeProps({ message: message });
}
danmu(danmu) {
this.setNativeProps({ danmu: danmu });
}
_onLoaded(event) {
this.props.onLoaded && this.props.onLoaded(event.nativeEvent);
}
_onPlaying(event) {
this.props.onPlaying && this.props.onPlaying(event.nativeEvent);
}
_onStop(event) {
this.props.onStop && this.props.onStop(event.nativeEvent);
}
_onError(event) {
this.props.onError && this.props.onError(event.nativeEvent);
}
_onReceiveMessage(event) {
this.props.onReceiveMessage &&
this.props.onReceiveMessage(event.nativeEvent);
}
render() {
const nativeProps = Object.assign({}, this.props);
return <RCTLive ref={this._assignRoot} {...nativeProps} />;
}
}
Live.propTypes = {
source: PropTypes.shape({
channel: PropTypes.string.isRequired,
nickname: PropTypes.string.isRequired,
avatar: PropTypes.string.avatar
}),
message: PropTypes.string,
danmu: PropTypes.bool,
paused: PropTypes.bool,
onLoaded: PropTypes.func,
onStop: PropTypes.func,
onError: PropTypes.func,
onPlaying: PropTypes.func,
onReceiveMessage: PropTypes.func
};
const RCTLive = requireNativeComponent("RCTLive", Live, {
nativeOnly: {
testID: true,
accessibilityComponentType: true,
renderToHardwareTextureAndroid: true,
accessibilityLabel: true,
accessibilityLiveRegion: true,
importantForAccessibility: true,
onLayout: true,
nativeID: true
}
});
module.exports = Live;