-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlashButton.js
More file actions
85 lines (81 loc) · 1.87 KB
/
FlashButton.js
File metadata and controls
85 lines (81 loc) · 1.87 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
import React, { Component } from 'react';
import {
StyleSheet,
Text,
View,
TouchableOpacity,
Alert
} from 'react-native';
export default class FlashButton extends Component {
constructor(props) {
super(props);
this.state = {
marginLeft:0,
marginTop:0,
isShown:true
};
}
componentDidMount(){
setInterval(this._changeLocation.bind(this), 300);
}
_changeLocation(){
//console.warn(this.state.marginLeft);
//this.state.marginLeft +=50;
this.setState({
marginLeft:Math.random()*(this.props.style.width-75),
marginTop:Math.random()*(this.props.style.height-50),
isShown: Math.random()>0.5
})
}
render() {
let tmp=(
<TouchableOpacity
onPress = {this._click.bind(this)}
style={[styles.button,{
marginLeft:this.state.marginLeft,
marginTop:this.state.marginTop
}]}>
<Text style={styles.text}>
Save
</Text>
</TouchableOpacity>)
let button=this.state.isShown ? tmp : null
return (
<View style={[styles.buttonContainer,this.props.style]}>
{ button
}
</View>
);
}
_click() {
// this.setState({isShown:true});
Alert.alert(
'Congraulations',
null,
[
{text: 'Ask me later', onPress: () => console.log('Ask me later pressed')},
{text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel'},
],
{ cancelable: false }
)
}
}
const styles = StyleSheet.create({
buttonContainer: {
justifyContent: 'flex-start',
flexDirection: 'row',
alignItems: 'flex-start'
},
button: {
borderRadius:7,
width: 75,
height: 50,
justifyContent: 'center',
flexDirection: 'row',
alignItems: 'center',
backgroundColor: '#CE3E3E'
},
text:{
color:'white'
}
});