how to make react native animated transition - react-native

There are 2 gradients, when I press the inactive one, I want the
active one to slowly shift the color of the other, how can I do that?
import React, { useState } from "react";
import { StyleSheet, Text, View, TouchableOpacity,Button } from "react-native";
import LinearGradient from 'react-native-linear-gradient';
import Animated, {useSharedValue,useAnimatedStyle,} from 'react-native-reanimated';
const atciveTab = ['#0067FF', '#00C2FF']
const inactiveTab = ['rgba(0,0,0,0)', 'rgba(0,0,0,0)']
const App = () => {
const [selectedTab, setSelectedTab] = useState({
tickets: true,
collectibles: false
})
const selectTicketTab = () => {
setSelectedTab({
tickets: true,
collectibles: false
})
}
const selectCollectiblesTab = () => {
setSelectedTab({
tickets: false,
collectibles: true
})
}
const offset = useSharedValue(0);
const animatedStyles = useAnimatedStyle(() => {
return {
transform: [{ translateX: offset.value * 255 }],
};
});
The gradient in the background will scroll when I click on it.
return (
<View style={styles.container}>
<TouchableOpacity
onPress={selectTicketTab}
style={styles.mainview}>
<LinearGradient
style={styles.ticketTab}
colors={selectedTab.tickets ? atciveTab : inactiveTab}
start={{ x: 1, y: 2 }}
end={{ x: 0, y: 0 }}
>
<Text style={styles.text}>Tickets</Text>
</LinearGradient>
</TouchableOpacity>
<TouchableOpacity
onPress={selectCollectiblesTab}
style={styles.mainview2}>
<LinearGradient
style={styles.collectiblesTab}
colors={selectedTab.collectibles ? atciveTab : inactiveTab}
start={{ x: 1, y: 2 }}
end={{ x: 0, y: 0 }}
>
<Text style={styles.text}>Collectibles</Text>
</LinearGradient>
</TouchableOpacity>
<Animated.View style={[styles.box, animatedStyles]} />
<Button onPress={() => (offset.value = Math.random())} title="Move" />
</View>
)
}
export default App;
I want the background color to be transferred to the other by sliding
slowly I tried many ways but I couldn't
const styles = StyleSheet.create({
container: {
flexDirection: 'row',
padding: 20,
backgroundColor: '#050035',
flex: 1,
justifyContent: 'center'
},
text: {
fontWeight: '400',
color: 'white',
textAlign: 'center',
padding: 10,
fontSize: 14,
letterSpacing: 0.1,
},
mainview: {
width: 163,
gap: 10,
backgroundColor: 'rgba(209, 214, 219, 0.1)',
height: 40,
borderTopLeftRadius: 8,
borderBottomLeftRadius: 8,
},
mainview2: {
width: 163,
gap: 10,
backgroundColor: 'rgba(209, 214, 219, 0.1)',
marginLeft: 3,
height: 40,
borderTopRightRadius: 8,
borderBottomRightRadius: 8,
},
ticketTab: {
borderTopLeftRadius: 8,
borderBottomLeftRadius: 8,
},
collectiblesTab: {
borderTopRightRadius: 8,
borderBottomRightRadius: 8,
},
box: {
width: 150,
height: 150,
backgroundColor: 'red'
}
})

Related

React Native Alert doesn't accept Navigation in my code

I'm trying to add a navigation in this Alert with Dialog, in the 'OK' option to confirm Logout and go back to the login screen, however it's not working. Does anyone help me with this?
I'm also trying to insert a dark theme for the entire application, local expo finger printing and push notifications in setData options 2, 3, and 4, but it's a difficult task as well.. But I'm more focused on creating this Navigation in my Alert because I'm trying.
i'll be very grateful for the help :)
when I grow up, I'm going to be a great programmer.
import { SafeAreaView,Text, View, FlatList,
TouchableOpacity, StyleSheet, Image, Switch, Alert} from 'react-native';
import { Entypo } from 'react-native-vector-icons';
import React, {useState, useEffect} from 'react';
import { useNavigation } from '#react-navigation/native';
import * as LocalAuthentication from 'expo-local-authentication';
//import Auth from './Biometric'
const Settings = () =>{
const [data, setData] = useState([
{ id: 1, text: 'Perfil', image: require('../../assets/images/user.png'), chosen: false },
{ id: 2, text: 'TouchId', image: require('../../assets/images/fingerprint.png'), chosen: false },
{ id: 3, text: 'Dark/Light mode', image: require('../../assets/images/light-up.png'), chosen: false },
{ id: 4, text: 'Notificações', image: require('../../assets/images/bell-fill.png'), chosen: false },
]);
const [isRender, setisRender] = useState(false);
const navigation = useNavigation();
const handleLogout = () => {
//navigation.navigate();
Alert.alert('Logout!', 'Deseja realmente sair?', [
{
text: 'Cancelar',
onPress: () => {},
},
{
text: 'OK',
onPress:()=>
{navigation.navigate ("Login")}
},
]);
}
const renderItem = ({ item }) => {
return (
<TouchableOpacity
style={styles.item}
>
<View style={styles.avatarContainer}>
<Image source={item.image} style={styles.avatar} />
</View>
<View>
<Text style={styles.text}>{item.text}</Text>
</View>
{item.id > 1 && <Switch style={{ width: 10, alignItems: 'flex-end',
marginTop: 15, flex: 1, marginEnd: 30}}
thumbColor={item.chosen == false ? "#CDCDCD" : "#A0D800"}
trackColor={{ true: "#CDCDCD" }}
value={item.chosen}
onChange={() => setData(data.map(index => item.id === index.id
? { ...index, chosen: !index.chosen }
: index
))} />}
{item.id === 2
}
</TouchableOpacity>
);
};
return (
<SafeAreaView style={styles.container}>
<FlatList
data={data}
keyExtractor={(item) => item.id.toString()}
renderItem={renderItem}
extraData={isRender} />
<View style = {{alignSelf: 'center',}}>
<TouchableOpacity
onPress={()=> (handleLogout)}
style = {{borderRadius: 10,
alignItems: "center",
backgroundColor: "#A0D800",height: 50, width: 200,
bottom: 15,
shadowColor: 'rgba(0,0,0, .4)', // IOS
shadowOffset: { height: 1, width: 1 }, // IOS
shadowOpacity: 1, // IOS
shadowRadius: 1, //IOS
elevation: 2, // Android
}}>
<Text style={{color: "#ffffff",
fontWeight: 'bold', fontSize: 17,
padding: 5, bottom: 0, marginTop: 5,
}}>
SignOut
</Text>
<Entypo name={'log-out'}
style={{alignSelf: 'flex-end', bottom: 25,
marginEnd: 25}}
color={'#ffffff'}
size={20}
/>
</TouchableOpacity>
</View>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
marginTop: 20
//marginHorizontal: 21
},
item:{
borderBottomWidth: 1,
borderBottomColor: '#808080',
alignItems: 'flex-start',
flexDirection: 'row',
},
avatarContainer: {
backgroundColor: 'transparent',
//borderRadius: 100,
height: 30,
width: 30,
justifyContent: 'center',
alignItems: 'center',
},
avatar: {
height: 25,
width: 25,
bottom: -25,
marginLeft: 30
},
text:{
marginVertical: 30,
fontSize: 20,
fontWeight: 'bold',
marginLeft: 30,
marginBottom: 10,
bottom: 5
},
});
export default Settings;
Your mistake is because of your onPress={()=> (handleLogout)}. onPress takes in a function but in your case you are making the function run another function, so your alert will not even be activated. To fix this, simply change your code to this.
onPress={handleLogout}

I want to add Async Storage to my flatlist in todo list app

I want to add Async Storage to my flatlist in todo list app.
this is my App.js code:
import { StatusBar } from 'expo-status-bar';
import {
StyleSheet,
Text,
View,
KeyboardAvoidingView,
FlatList,
TextInput,
TouchableOpacity,
Keyboard,
} from 'react-native';
import React, { useState, useEffect } from 'react';
import {
Poppins_100Thin,
Poppins_100Thin_Italic,
Poppins_200ExtraLight,
Poppins_200ExtraLight_Italic,
Poppins_300Light,
Poppins_300Light_Italic,
Poppins_400Regular,
Poppins_400Regular_Italic,
Poppins_500Medium,
Poppins_500Medium_Italic,
Poppins_600SemiBold,
Poppins_600SemiBold_Italic,
Poppins_700Bold,
Poppins_700Bold_Italic,
Poppins_800ExtraBold,
Poppins_800ExtraBold_Italic,
Poppins_900Black,
Poppins_900Black_Italic,
} from '#expo-google-fonts/poppins';
import { useFonts } from 'expo-font';
import Task from './components/Task';
import AppLoading from 'expo-app-loading';
export default function App() {
const [task, setTask] = useState();
const [taskItems, setTaskItems] = useState([]);
let [fontsLoaded, error] = useFonts({
Poppins_100Thin,
Poppins_100Thin_Italic,
Poppins_200ExtraLight,
Poppins_200ExtraLight_Italic,
Poppins_300Light,
Poppins_300Light_Italic,
Poppins_400Regular,
Poppins_400Regular_Italic,
Poppins_500Medium,
Poppins_500Medium_Italic,
Poppins_600SemiBold,
Poppins_600SemiBold_Italic,
Poppins_700Bold,
Poppins_700Bold_Italic,
Poppins_800ExtraBold,
Poppins_800ExtraBold_Italic,
Poppins_900Black,
Poppins_900Black_Italic,
});
if (!fontsLoaded) {
return <AppLoading />;
}
const handleAddTask = async () => {
try {
Keyboard.dismiss();
setTaskItems([...taskItems, task]);
setTask('');
} catch (err) {
console.log(err);
}
};
const completeTask = (index) => {
let itemsCopy = [...taskItems];
itemsCopy.splice(index, 1);
setTaskItems(itemsCopy);
};
const deleteItem = (index) => {
let arr = [...taskItems];
arr.splice(index, 1);
setTaskItems(arr);
};
return (
<View style={styles.container}>
{/* Todays Tasks */}
<View style={styles.taskWrapper}>
<Text style={styles.sectionTitle}>Today's Tasks</Text>
<View style={styles.items}>
{/* This is where the tasks will go! */}
<FlatList
data={taskItems}
keyExtractor={(item) => item.id}
renderItem={({ item, index }) => (
<Task text={item} handleDelete={() => deleteItem(index)} />
)}
/>
</View>
</View>
{/* Write a Task */}
<KeyboardAvoidingView style={styles.writeTaskWrapper}>
<TextInput
style={styles.input}
placeholder={'Write A Task'}
value={task}
onChangeText={(text) => setTask(text)}
/>
<TouchableOpacity onPress={() => handleAddTask()}>
<View style={styles.addWrapper}>
<Text style={styles.addText}>+</Text>
</View>
</TouchableOpacity>
</KeyboardAvoidingView>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#E8EAED',
},
taskWrapper: {
paddingTop: 80,
paddingHorizontal: 20,
},
sectionTitle: {
fontSize: 24,
backgroundColor: '#fff',
fontFamily: 'Poppins_600SemiBold',
borderRadius: 10,
margin: 'auto',
width: 250,
height: 60,
textAlign: 'center',
shadowColor: '#000',
shadowOffset: { width: 0, height: 1 },
shadowOpacity: 0.2,
shadowRadius: 2,
elevation: 5,
paddingTop: 10,
},
items: {
marginTop: 30,
},
writeTaskWrapper: {
position: 'absolute',
bottom: 60,
width: '100%',
flexDirection: 'row',
justifyContent: 'space-around',
alignItems: 'center',
},
input: {
paddingVertical: 15,
paddingHorizontal: 15,
backgroundColor: '#fff',
borderRadius: 60,
width: 250,
fontFamily: 'Poppins_400Regular',
shadowColor: '#000',
shadowOffset: { width: 0, height: 1 },
shadowOpacity: 0.5,
shadowRadius: 2,
elevation: 3,
},
addWrapper: {
width: 60,
height: 60,
backgroundColor: '#fff',
borderRadius: 60,
justifyContent: 'center',
alignItems: 'center',
shadowColor: '#000',
shadowOffset: { width: 0, height: 1 },
shadowOpacity: 0.5,
shadowRadius: 2,
elevation: 3,
},
addText: {},
});
THIS IS MY TASK.JS CODE:
import React from 'react';
import {View,Text,StyleSheet,Dimensions,Animated,TouchableOpacity} from 'react-native';
import AppLoading from 'expo-app-loading'
import {
Poppins_100Thin,
Poppins_100Thin_Italic,
Poppins_200ExtraLight,
Poppins_200ExtraLight_Italic,
Poppins_300Light,
Poppins_300Light_Italic,
Poppins_400Regular,
Poppins_400Regular_Italic,
Poppins_500Medium,
Poppins_500Medium_Italic,
Poppins_600SemiBold,
Poppins_600SemiBold_Italic,
Poppins_700Bold,
Poppins_700Bold_Italic,
Poppins_800ExtraBold,
Poppins_800ExtraBold_Italic,
Poppins_900Black,
Poppins_900Black_Italic
} from '#expo-google-fonts/poppins'
import {useFonts} from 'expo-font'
import Swipeable from 'react-native-gesture-handler/Swipeable';
const SCREEN_WIDTH = Dimensions.get('window').width;
const Task = (props) => {
let [fontsLoaded,error]=useFonts({
Poppins_100Thin,
Poppins_100Thin_Italic,
Poppins_200ExtraLight,
Poppins_200ExtraLight_Italic,
Poppins_300Light,
Poppins_300Light_Italic,
Poppins_400Regular,
Poppins_400Regular_Italic,
Poppins_500Medium,
Poppins_500Medium_Italic,
Poppins_600SemiBold,
Poppins_600SemiBold_Italic,
Poppins_700Bold,
Poppins_700Bold_Italic,
Poppins_800ExtraBold,
Poppins_800ExtraBold_Italic,
Poppins_900Black,
Poppins_900Black_Italic
})
if (!fontsLoaded){
return <AppLoading/>
}
const leftSwipe = (progress, dragX) => {
const scale = dragX.interpolate({
inputRange: [0, 100],
outputRange: [0, 1],
extrapolate: 'clamp',
});
return (
<TouchableOpacity onPress={props.handleDelete} activeOpacity={0.6}>
<View style={styles.deleteBox}>
<Animated.Text style={{transform: [{scale: scale}],color:'#fff',fontFamily:"Poppins_400Regular",fontSize:18}}>
Delete
</Animated.Text>
</View>
</TouchableOpacity>
);
};
return(
<Swipeable renderLeftActions={leftSwipe}>
<View style={styles.item}>
<View style={styles.itemLeft}>
<View style={styles.square}>
</View>
<Text style={styles.itemText}>
{props.text}
</Text>
</View>
<View style={styles.circular}>
</View>
</View>
</Swipeable>
)
}
const styles = StyleSheet.create({
item:{
backgroundColor:'white',
padding:15,
borderRadius:10,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
marginBottom:20,
shadowColor: '#000',
shadowOffset: { width: 0, height: 1 },
shadowOpacity: 0.5,
shadowRadius: 2,
elevation: 3
},
itemLeft:{
flexDirection: 'row',
alignItems: 'center',
flexWrap:'wrap',
},
square:{
width:24,
height:24,
backgroundColor:'#55BCF6',
opacity:0.5,
borderRadius:5,
marginRight:15,
},
itemText:{
maxWidth:'80%',
fontFamily:'Poppins_400Regular'
},
circular:{
width:12,
height:12,
borderColor:'#55BCF6',
borderWidth:2,
borderRadius:5
},
deleteBox:{
backgroundColor:'red',
justifyContent:'center',
alignItems:'center',
width:100,
height:55,
borderRadius:10,
shadowColor: '#000',
shadowOffset: { width: 0, height: 1 },
shadowOpacity: 0.5,
shadowRadius: 2,
elevation: 5,
}
});
export default Task;
i am learning react native so i dont know much about it
so i want to add async storage such that its shows the tasks which are created after re-opening the app
kindly help with providing code
and yeah i have used expo and swipeable for deleting the tasks
import async-storage
import AsyncStorage from '#react-native-async-storage/async-storage';
get stored task
const task await AsyncStorage.getItem('task')
if(task!=null)
switch(task{
... your cases ...
set a task
await AsyncStorage.setItem('task', 'taskName')
in case refreshing task
await AsyncStorage.removeItem('keyName')

Rect-native Reanimated(v2) interpolate translateY

I am trying to create an animation where the red bar will move along y-axis in an infinite & reverse animation. For some reason, I can not figure out and not able to achieve the desired behavior. Any assistance will be greatly appreciated.
import Animated, {
useAnimatedStyle,
useSharedValue,
interpolate,
withTiming,
withRepeat,
Extrapolate,
} from 'react-native-reanimated';
export default CustomMarker = () => {
const bar = useSharedValue(0);
const barStyle = useAnimatedStyle(() => {
const yValue = interpolate(bar.value, [0, 1], [0, 225]);
return {
transform: [{ translateY: yValue }],
};
});
useEffect(() => {
bar.value = withRepeat(withTiming(1, { duration: 800 }), -1, true);
});
return (
<View
style={{
backgroundColor: COLORS.darkOverlay,
height: 540,
alignItems: 'center',
justifyContent: 'center',
}}>
<View style={styles.rectangleStyle}>
<Animated.View style={[styles.redBarStyle, barStyle]} />
</View>
</View>
);
};
const styles = Stylesheet.create({
rectangleStyle: {
height: 230,
width: 400,
alignItems: 'center',
justifyContent: 'center',
},
redBarStyle: {
position: 'absolute',
top: 0,
height: 10,
width: 225,
backgroundColor: 'red',
borderRadius: 5,
},
})

React Native - Is there any best way to give the style `borderRadius` each button?

I have created three buttons using map, and the 1st and the 3rd buttons have borderRadius on the side.
This is what it looks like :
Even though I anyways displayed the buttons as expected, but I feel like this code should be better than I did. Plus, I am not so sure if it is okay to map the buttons in this way..
My code below :
const styles = StyleSheet.create({
row: {
flexDirection: 'row',
justifyContent: 'flex-end',
marginRight: 15,
marginTop: 15,
},
btnWrap: {
width: 50,
height: 24,
backgroundColor: colors.white_two,
borderWidth: 0.5,
borderColor: colors.very_light_pink_five,
justifyContent: 'center',
alignItems: 'center',
},
textStyle: {
fontSize: 10,
fontWeight: 'normal',
color: colors.very_light_pink_five,
},
btnLeft: {
borderTopLeftRadius: 6,
borderBottomLeftRadius: 6,
},
btnRight: {
borderTopRightRadius: 6,
borderBottomRightRadius: 6,
},
btnMiddle: {
borderLeftWidth: 0,
borderRightWidth: 0,
},
selected: {
backgroundColor: colors.black,
},
selectedText: {
color: colors.white_two,
},
});
const pointType = ['one', 'two', 'three'];
const MypagePoint = ({ totalPoint }) => {
const [btnClicked, setBtnClicked] = useState(null);
return (
<View style={[styles.container]}>
<View style={[styles.row, { marginBottom: 15 }]}>
{pointType.map((type, index) => (
<TouchableOpacity
style={[
styles.btnWrap,
btnClicked === index && styles.selected,
// This is the part I doubt
index === 0 && styles.btnLeft,
index === 1 && styles.btnMiddle,
index === 2 && styles.btnRight,
]}
onPress={() => setBtnClicked(index)}
>
<Text
style={[
styles.textStyle,
btnClicked === index && styles.selectedText,
]}
>
{type}
</Text>
</TouchableOpacity>
))}
</View>
</View>
);
};
Would you let me know the best way to code?
Old Solution: Use ternary operator instead.
Updated: Create a helper function and use the rounded corner styling only for the first and last buttons.
Working Example: Expo Snack
import React, { useState, useEffect } from 'react';
import {
Text,
View,
StyleSheet,
TouchableOpacity,
FlatList,
} from 'react-native';
import Constants from 'expo-constants';
const styles = StyleSheet.create({
row: {
flexDirection: 'row',
justifyContent: 'flex-end',
marginRight: 15,
marginTop: 15,
},
btnWrap: {
width: 50,
height: 24,
backgroundColor: 'white',
borderWidth: 1,
borderColor: 'pink',
justifyContent: 'center',
alignItems: 'center',
margin: -2,
},
textStyle: {
fontSize: 10,
fontWeight: 'normal',
color: 'pink',
},
btnLeft: {
borderTopLeftRadius: 6,
borderBottomLeftRadius: 6,
},
btnRight: {
borderTopRightRadius: 6,
borderBottomRightRadius: 6,
},
selected: {
backgroundColor: 'black',
},
selectedText: {
color: 'white',
},
});
const pointType = ['one', 'two', 'three', 'four', 'five', 'six'];
export default MypagePoint = ({ totalPoint }) => {
const [btnClicked, setBtnClicked] = useState(null);
const buttonStyle = (index) => {
if (index === 0) return styles.btnLeft;
else if (index === pointType.length - 1) return styles.btnRight;
};
return (
<View style={[styles.container]}>
<View style={[styles.row, { marginBottom: 15 }]}>
{pointType.map((type, index) => (
<Button
index={index}
btnClicked={btnClicked}
buttonStyle={buttonStyle}
setBtnClicked={setBtnClicked}
type={type}
/>
))}
</View>
</View>
);
};
const Button = ({ index, btnClicked, buttonStyle, setBtnClicked, type }) => {
return (
<TouchableOpacity
style={[
styles.btnWrap,
btnClicked === index && styles.selected,
buttonStyle(index),
]}
onPress={() => setBtnClicked(index)}>
<Text
style={[styles.textStyle, btnClicked === index && styles.selectedText]}>
{type}
</Text>
</TouchableOpacity>
);
};

React Native - The Color of TouchableOpacity Button Should Change Without Map

I have only two buttons, and I want their backgroundColor to be changed when pressing. I don't want to use map as there are only two buttons. I have tried some ways to approach what I expect, but I am at a loss what to do.
RoundedButtonSet :
const styles = StyleSheet.create({
container: {
marginBottom: 20,
},
});
const RoundedButtonSet = ({ firstBtn, secondBtn, contentStyle }) => {
return (
<View style={[styles.container, contentStyle]}>
<RoundedButtons firstBtn={firstBtn} secondBtn={secondBtn} />
</View>
);
};
RoundedButtons :
const styles = StyleSheet.create({
container: {
flexDirection: 'row',
marginHorizontal: 15,
height: 40,
alignItems: 'center',
},
btn: {
flex: 1,
borderWidth: 1,
borderColor: colors.very_light_pink,
borderRadius: 6,
paddingVertical: 13,
height: 40,
},
btnTextStyle: {
fontSize: 12,
fontWeight: 'normal',
color: colors.very_light_pink_five,
textAlign: 'center',
},
left: {
borderTopRightRadius: 0,
borderBottomRightRadius: 0,
borderColor: colors.very_light_pink,
},
right: {
borderTopLeftRadius: 0,
borderBottomLeftRadius: 0,
borderLeftWidth: 0,
},
backgroundColor: {
backgroundColor: colors.iris,
},
textColor: {
color: colors.white_two,
},
});
const RoundedButtons = ({ firstBtn, secondBtn, contentStyle, onPress }) => {
const [isClicked, setIsClicked] = useState(true);
return (
<View style={[styles.container, contentStyle]}>
<TouchableOpacity
style={[styles.btn, styles.left, isClicked && styles.backgroundColor]}
onPress={() => setIsClicked(!isClicked)}
>
<Text style={[styles.btnTextStyle, isClicked && styles.textColor]}>
{firstBtn}
</Text>
</TouchableOpacity>
<TouchableOpacity
style={[styles.btn, styles.right]}
onPress={() => setIsClicked()}
>
<Text style={[styles.btnTextStyle]}>{secondBtn}</Text>
</TouchableOpacity>
</View>
);
};
RoundedButtons.propTypes = {
firstBtn: Text.propTypes,
secondBtn: Text.propTypes,
};
export default RoundedButtons;
Should I give index directly to each button? I have got this idea, but the problem is I have no idea how to access..
You can have a simple state to keep track of which button is pressed and use that to apply styles conditionally.
Here is the working example: Expo Snack
import React, { useState } from 'react';
import { Text, View, StyleSheet, TouchableOpacity } from 'react-native';
import Constants from 'expo-constants';
// You can import from local files
import AssetExample from './components/AssetExample';
// or any pure javascript modules available in npm
import { Card } from 'react-native-paper';
const styles = StyleSheet.create({
container: {
flexDirection: 'row',
marginHorizontal: 15,
height: 40,
alignItems: 'center',
},
btn: {
flex: 1,
borderWidth: 1,
borderColor: 'pink',
borderRadius: 6,
paddingVertical: 13,
height: 40,
},
btnTextStyle: {
fontSize: 12,
fontWeight: 'normal',
color: 'pink',
textAlign: 'center',
},
left: {
borderTopRightRadius: 0,
borderBottomRightRadius: 0,
borderColor: 'pink',
},
right: {
borderTopLeftRadius: 0,
borderBottomLeftRadius: 0,
borderLeftWidth: 0,
},
backgroundColor: {
backgroundColor: 'black',
},
textColor: {
color: 'white',
},
});
const RoundedButtons = ({ firstBtn, secondBtn, contentStyle, onPress }) => {
const [clickedBtn, setIsClicked] = useState(null);
React.useEffect(() => {
console.log(clickedBtn);
}, [clickedBtn]);
return (
<View style={[styles.container, contentStyle]}>
<TouchableOpacity
style={[
styles.btn,
styles.left,
clickedBtn == 1 && styles.backgroundColor,
]}
onPress={() => setIsClicked(1)}>
<Text
style={[styles.btnTextStyle, clickedBtn == 1 && styles.textColor]}>
firstBtn
</Text>
</TouchableOpacity>
<TouchableOpacity
style={[
styles.btn,
styles.right,
clickedBtn == 2 && styles.backgroundColor,
]}
onPress={() => setIsClicked(2)}>
<Text
style={[styles.btnTextStyle, clickedBtn == 2 && styles.textColor]}>
secondBtn
</Text>
</TouchableOpacity>
</View>
);
};
RoundedButtons.propTypes = {
firstBtn: Text.propTypes,
secondBtn: Text.propTypes,
};
export default RoundedButtons;