forked from callstack/react-native-pager-view
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLikeCount.js
57 lines (50 loc) · 1.24 KB
/
LikeCount.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
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
import React from 'react';
import {StyleSheet, Text, TouchableOpacity, View} from 'react-native';
import {thumbsUp} from '../../utils';
type Props = $ReadOnly<{||}>;
type State = {|likes: number|};
export class LikeCount extends React.Component<Props, State> {
state = {
likes: 7,
};
onClick = () => {
this.setState(state => ({likes: state.likes + 1}));
};
render() {
return (
<View style={styles.likeContainer}>
<TouchableOpacity onPress={this.onClick} style={styles.likeButton}>
<Text style={styles.likesText}>{thumbsUp + ' Like'}</Text>
</TouchableOpacity>
<Text style={styles.likesText}>{this.state.likes + ' likes'}</Text>
</View>
);
}
}
const styles = StyleSheet.create({
likeContainer: {
flexDirection: 'row',
height: 45,
},
likesText: {
flex: 1,
fontSize: 18,
alignSelf: 'center',
},
likeButton: {
backgroundColor: 'rgba(0, 0, 0, 0.1)',
borderColor: '#333333',
borderWidth: 1,
borderRadius: 5,
flex: 1,
margin: 8,
},
});