-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUIButtonGroup.js
More file actions
67 lines (65 loc) · 2.02 KB
/
Copy pathUIButtonGroup.js
File metadata and controls
67 lines (65 loc) · 2.02 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
import React, { useState } from "react";
import { View, TouchableOpacity } from "react-native";
import { LinearGradient } from "expo-linear-gradient";
import UIText from "./UIText";
export default function UIButtonGroup(props) {
const [selectedIndex, setSelectedIndex] = useState(props.initIndex || 0);
return (
<LinearGradient
colors={[global.gradientColor1, global.gradientColor2]}
start={[0, 1]}
end={[1, 0]}
style={[
{
width: "100%",
height: 50,
borderRadius: 25,
flexDirection: "row",
alignItems: "center",
justifyContent: "center",
marginTop: 20,
},
props.style,
]}
>
{props.buttons?.map((item, index) => (
<TouchableOpacity
key={item.title + item.index}
style={{
flex: 1,
height: 45,
borderTopLeftRadius: index == 0 ? 22.5 : 0,
borderBottomLeftRadius: index == 0 ? 22.5 : 0,
borderTopRightRadius: index == props.buttons.length - 1 ? 22.5 : 0,
borderBottomRightRadius:
index == props.buttons.length - 1 ? 22.5 : 0,
justifyContent: "center",
backgroundColor:
index == selectedIndex
? "transparent"
: global.dark
? global.backgroundColor
: "white",
marginLeft: index == 0 ? 2.5 : 1.5,
marginRight: index == props.buttons.length - 1 ? 2.5 : 1.5,
}}
onPress={() => {
setSelectedIndex(index);
props.buttons[index].onPress
? props.buttons[index].onPress()
: null;
}}
>
<UIText
text={props.buttons[index].title}
type="button"
color={
index == selectedIndex ? "white" : global.dark ? "white" : "black"
}
style={{ alignSelf: "center" }}
/>
</TouchableOpacity>
))}
</LinearGradient>
);
}