Skip to content

Instantly share code, notes, and snippets.

@Charpell
Created May 30, 2020 16:58
Show Gist options
  • Save Charpell/a2c9aeb0369d738a6fa45c80df8b28a3 to your computer and use it in GitHub Desktop.
Save Charpell/a2c9aeb0369d738a6fa45c80df8b28a3 to your computer and use it in GitHub Desktop.
import React, { useState } from "react";
import { View, Text, StyleSheet, TouchableOpacity } from "react-native";
import {
MaterialCommunityIcons,
SimpleLineIcons,
FontAwesome5,
} from "@expo/vector-icons";
import { useTheme } from "@react-navigation/native";
const Like = ({ like }) => {
const { colors } = useTheme()
const [toggle, setToggle] = useState(true);
const [count, setCount] = useState(0);
const toggleColor =()=>{
const newState=!toggle
const newCount = count === 0 ? 1 : 0
setToggle(newState)
setCount(newCount)
}
const textColor = toggle?'grey':'dodgerblue'
return (
<View style={styles.container}>
<TouchableOpacity style={styles.like}>
<SimpleLineIcons name='like' size={25} style={{color:textColor}} onPress={() =>toggleColor()} />
</TouchableOpacity>
<View>
<Text style={[styles.text, {color:textColor}]}>{like}</Text>
<Text style={[styles.text, {color:textColor}]}>{count}</Text>
</View>
</View>
);
};
const styles = StyleSheet.create({
container: {
flexDirection: "row",
alignItems: "center",
},
like: {
marginLeft: 20,
marginTop: 20,
marginRight: 20,
},
text: {
marginLeft: 10,
marginTop: 20,
color: "grey",
fontSize: 20,
},
});
export default Like;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment