-
Notifications
You must be signed in to change notification settings - Fork 0
/
RNTabBarOption.tsx
49 lines (43 loc) · 1.39 KB
/
RNTabBarOption.tsx
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
import React from "react"
import {useEffect, useState} from "react"
import {observer} from "mobx-react-lite"
import {Pressable, View, ViewStyle} from "react-native"
export const RNTabBarOption = observer((
props: {
children: React.JSX.Element[] | React.JSX.Element,
index?: number,
activeIndex?: number,
onActiveChange?: (isActive: boolean) => void,
onActive?: () => void,
onPress?: () => void,
},
) => {
const [isActive, setIsActive] = useState(false)
useEffect(() => {
setIsActive(props.index === props.activeIndex)
}, [props.activeIndex])
useEffect(() => {
isActive && props.onActive && props.onActive()
props.onActiveChange && props.onActiveChange(true)
}, [isActive])
const handlePress = () => {
props.onPress && props.onPress()
}
const styles = {
optionContainer: {
flex: 1,
alignItems: "center",
justifyContent: "center",
borderRadius: 6,
paddingVertical: 6,
} as ViewStyle,
}
return (
<View style={styles.optionContainer}>
<Pressable onPress={handlePress}>
{props.children}
</Pressable>
</View>
)
},
)