-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathInfoButton.js
executable file
·112 lines (104 loc) · 2.99 KB
/
InfoButton.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
112
/**
* The examples provided by Oculus are for non-commercial testing and
* evaluation purposes only.
*
* Oculus reserves all rights not expressly granted.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
* OCULUS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
'use strict';
import React from 'react';
import {Animated, Image, View, VrButton} from 'react-360';
import Tooltip from './Tooltip';
/**
* On hover the InfoButton fades in a Tooltip component, and then fades it out
* when the cursor leaves both the button and the Tooltip.
*
* When using with CylinderLayer, set pixelsPerMeter to convert units, otherise
* set translateZ to specify distance between camera and button.
*/
class InfoButton extends React.Component {
static defaultProps = {
fadeIn: 500,
fadeOut: 500,
height: 0.3,
onInput: null,
pixelsPerMeter: 1,
rotateY: 0,
translateX: 0,
translateZ: 0,
width: 0.3,
};
constructor(props) {
super();
this.state = {
hasFocus: false,
opacityAnim: new Animated.Value(0),
};
}
_fadeIn() {
Animated.timing(this.state.opacityAnim, {
toValue: 1,
duration: this.props.fadeIn,
}).start();
}
_fadeOut() {
Animated.timing(this.state.opacityAnim, {
toValue: 0,
duration: this.props.fadeOut,
}).start();
}
render() {
const PPM = this.props.pixelsPerMeter;
return (
<VrButton
style={{
layoutOrigin: [0.5, 0.5, 0],
position: 'absolute',
transform: [
{rotateY: this.props.rotateY},
{translateX: this.props.translateX},
{translateZ: this.props.translateZ},
],
}}
ignoreLongClick={true}
onInput={this.props.onInput}
onExit={() => {
this._fadeOut();
}}
// onClickSound={this.props.onClickSound}
// onEnterSound={this.props.onEnterSound}
onExitSound={this.props.onExitSound}
onLongClickSound={this.props.onLongClickSound}>
<Image
style={{
height: 0.3 * PPM,
width: 0.3 * PPM,
flexDirection: 'row',
}}
onEnter={() => {
this._fadeIn();
}}
source={this.props.source}>
<Animated.View
style={{
flexDirection: 'row',
alignItems: 'center',
opacity: this.state.opacityAnim,
paddingLeft: 0.4 * PPM,
}}
billboarding={'on'}>
<Tooltip pixelsPerMeter={PPM} tooltip={this.props.tooltip} />
</Animated.View>
</Image>
</VrButton>
);
}
}
module.exports = InfoButton;