-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create tabbar component, replace navbar tabs with it
- Loading branch information
1 parent
6602b85
commit a2c4b8d
Showing
6 changed files
with
135 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { useContext } from "react"; | ||
import { StyleSheet, TouchableOpacity, View } from "react-native"; | ||
import { ThemeContext } from "../contexts/theme"; | ||
import Icon from "./Icon"; | ||
import Text from "./Text"; | ||
|
||
interface IProps { | ||
onChange: (type: string) => void; | ||
list: { | ||
icon?: string; | ||
label: string; | ||
type: string; | ||
}[]; | ||
selected: string; | ||
} | ||
|
||
const TabBar = (props: IProps) => { | ||
const { theme } = useContext(ThemeContext); | ||
|
||
return ( | ||
<View style={styles.listing}> | ||
{props.list.map((item) => { | ||
const selected = props.selected === item.type; | ||
return ( | ||
<View | ||
key={"list-type-" + item.type} | ||
style={{ | ||
overflow: "hidden", | ||
height: 34, | ||
top: 2, | ||
}} | ||
> | ||
<TouchableOpacity | ||
disabled={selected} | ||
style={[ | ||
styles.listItem, | ||
selected | ||
? { | ||
shadowColor: theme.primary, | ||
shadowOffset: { | ||
width: 0, | ||
height: 0, | ||
}, | ||
shadowOpacity: 0.45, | ||
shadowRadius: 5.84, | ||
borderColor: theme.textSelected, | ||
} | ||
: {}, | ||
]} | ||
onPress={() => { | ||
if (props.selected !== item.type) { | ||
props.onChange(item.type); | ||
} | ||
}} | ||
> | ||
{item.icon && ( | ||
<Icon | ||
image={item.icon} | ||
size={15} | ||
style={{ marginRight: 5, opacity: selected ? 1 : 0.5 }} | ||
/> | ||
)} | ||
<Text | ||
semibold={selected} | ||
size={1} | ||
color={selected ? theme.textSelected : theme.textPrimary} | ||
style={ | ||
selected | ||
? { | ||
textShadowColor: "rgba(132, 119, 183, 0.5)", | ||
textShadowOffset: { width: 0, height: 0 }, | ||
textShadowRadius: 4, | ||
} | ||
: {} | ||
} | ||
> | ||
{item.label} | ||
</Text> | ||
</TouchableOpacity> | ||
</View> | ||
); | ||
})} | ||
</View> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
listing: { | ||
height: "100%", | ||
flexDirection: "row", | ||
alignItems: "center", | ||
marginLeft: -0.5, | ||
}, | ||
listItem: { | ||
height: 30, | ||
paddingHorizontal: 10, | ||
justifyContent: "center", | ||
alignItems: "center", | ||
flexDirection: "row", | ||
}, | ||
}); | ||
|
||
export default TabBar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters