This repository was archived by the owner on Dec 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathBasicAppTemplateInfoButton.react.js
More file actions
executable file
·145 lines (134 loc) · 3.44 KB
/
Copy pathBasicAppTemplateInfoButton.react.js
File metadata and controls
executable file
·145 lines (134 loc) · 3.44 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
* A simple component to use
* Do the "providesModule" provides module name to haste map
* So you can reference it from other file by
* import BasicAppTemplateInfoButton from "BasicAppTemplateInfoButton.react"
* @providesModule BasicAppTemplateInfoButton.react
*/
'use strict';
import React from 'react';
import {
StyleSheet,
Text,
View,
Image,
asset,
VrButton,
Animated,
NativeModules,
} from 'react-360';
const {AudioModule} = NativeModules;
const CLICK_SOUND = asset('menu-click.wav');
const FOCUS_SCALE = 1.3;
class BasicAppTemplateInfoButton extends React.Component {
static defaultProps = {
width: 180,
text: '',
};
// This component has example to show how animation works
// You can check the doc: https://reactnative.dev/docs/0.49/animated#docsNav
constructor(props) {
super(props);
this.state = {
hasFocus: false,
scaleAnim: new Animated.Value(0), // initial a value for doing animation
};
}
_focus = () => {
// start an animation
Animated.timing(this.state.scaleAnim, {
toValue: 1,
duration: 300,
}).start();
this.setState({hasFocus: true});
};
_blur = () => {
// start an animation
Animated.timing(this.state.scaleAnim, {
toValue: 0,
duration: 300,
}).start();
this.setState({hasFocus: false});
};
_click = () => {
// input handling
this.props.onClick && this.props.onClick();
};
render() {
return (
<View
style={[
styles.wrapper,
this.props.style,
{width: this.props.width * FOCUS_SCALE}
]}>
<VrButton
onClick={this._click} //this event trigger when click the view
onExit={this._blur} //this event trigger when cursor move out of the view
onEnter={this._focus} //this event trigger when cursor move into of the view
onClickSound={CLICK_SOUND}
onEnterSound={CLICK_SOUND}
onExitSound={CLICK_SOUND}
onLongClickSound={CLICK_SOUND}
>
<Animated.View
style={[
styles.button,
this.state.hasFocus && styles.buttonFocused,
{
// With this the width of the this view
// is animated with the value of scaleAnim
// by an interpolation
width: this.state.scaleAnim.interpolate({
inputRange: [0, 1],
outputRange: [this.props.width, this.props.width * FOCUS_SCALE],
}),
}]}>
<Image
style={styles.icon}
source={this.props.source} />
<Text style={styles.text}>
{this.props.text}
</Text>
</Animated.View>
</VrButton>
</View>
);
}
}
const styles = StyleSheet.create({
wrapper: {
justifyContent: 'center',
alignItems: 'center',
},
button: {
backgroundColor: 'grey',
justifyContent: 'center',
alignItems: 'center',
borderColor: '#639dda',
borderWidth: 2,
borderRadius: 5,
flexDirection: 'row',
height: 60,
},
buttonFocused: {
backgroundColor: 'white',
borderColor: '#4477dd',
},
icon: {
padding: 20,
tintColor: 'grey',
height: '100%',
aspectRatio: 1,
},
iconFocused: {
tintColor: 'white',
},
text: {
fontSize: 30,
color: 'black',
textAlign: 'center',
flex: 1,
},
});
module.exports = BasicAppTemplateInfoButton;