Skip to content

Commit

Permalink
Merge pull request #28357 from wildan-m/wildan/fix/26648-3-tab-hover
Browse files Browse the repository at this point in the history
Add Hover to TabItem
  • Loading branch information
MariaHCD authored Oct 9, 2023
2 parents b2cbd26 + e2f3650 commit 7c7fa65
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/components/TabSelector/TabSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ const getBackgroundColor = (position, routesLength, tabIndex) => {

function TabSelector({state, navigation, onTabPress, position}) {
const {translate} = useLocalize();

return (
<View style={styles.tabSelector}>
{_.map(state.routes, (route, index) => {
Expand Down Expand Up @@ -120,6 +119,7 @@ function TabSelector({state, navigation, onTabPress, position}) {
activeOpacity={activeOpacity}
inactiveOpacity={inactiveOpacity}
backgroundColor={backgroundColor}
isFocused={isFocused}
/>
);
})}
Expand Down
40 changes: 23 additions & 17 deletions src/components/TabSelector/TabSelectorItem.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Animated} from 'react-native';
import {Animated, StyleSheet} from 'react-native';
import React from 'react';
import PropTypes from 'prop-types';
import styles from '../../styles/styles';
Expand Down Expand Up @@ -27,6 +27,9 @@ const propTypes = {
/** Animated opacity value while the label is in active state */
// eslint-disable-next-line
activeOpacity: PropTypes.any,

/** Whether this tab is active */
isFocused: PropTypes.bool,
};

const defaultProps = {
Expand All @@ -36,29 +39,32 @@ const defaultProps = {
backgroundColor: '',
inactiveOpacity: 1,
activeOpacity: 0,
isFocused: false,
};

const AnimatedPressableWithFeedback = Animated.createAnimatedComponent(PressableWithFeedback);

function TabSelectorItem({icon, title, onPress, backgroundColor, activeOpacity, inactiveOpacity}) {
function TabSelectorItem({icon, title, onPress, backgroundColor, activeOpacity, inactiveOpacity, isFocused}) {
return (
<AnimatedPressableWithFeedback
<PressableWithFeedback
accessibilityLabel={title}
style={[styles.tabSelectorButton, {backgroundColor}]}
style={[styles.tabSelectorButton]}
wrapperStyle={[styles.flex1]}
onPress={onPress}
>
<TabIcon
icon={icon}
activeOpacity={activeOpacity}
inactiveOpacity={inactiveOpacity}
/>
<TabLabel
title={title}
activeOpacity={activeOpacity}
inactiveOpacity={inactiveOpacity}
/>
</AnimatedPressableWithFeedback>
{({hovered}) => (
<Animated.View style={[styles.tabSelectorButton, StyleSheet.absoluteFill, styles.tabBackground(hovered, isFocused, backgroundColor)]}>
<TabIcon
icon={icon}
activeOpacity={styles.tabOpacity(hovered, isFocused, activeOpacity, inactiveOpacity)}
inactiveOpacity={styles.tabOpacity(hovered, isFocused, inactiveOpacity, activeOpacity)}
/>
<TabLabel
title={title}
activeOpacity={styles.tabOpacity(hovered, isFocused, activeOpacity, inactiveOpacity)}
inactiveOpacity={styles.tabOpacity(hovered, isFocused, inactiveOpacity, activeOpacity)}
/>
</Animated.View>
)}
</PressableWithFeedback>
);
}

Expand Down
10 changes: 8 additions & 2 deletions src/styles/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -3486,11 +3486,17 @@ const styles = (theme) => ({

tabText: (isSelected) => ({
marginLeft: 8,
fontFamily: isSelected ? fontFamily.EXP_NEUE_BOLD : fontFamily.EXP_NEUE,
fontWeight: isSelected ? fontWeightBold : 400,
fontFamily: fontFamily.EXP_NEUE_BOLD,
fontWeight: fontWeightBold,
color: isSelected ? theme.textLight : theme.textSupporting,
}),

tabBackground: (hovered, isFocused, background) => ({
backgroundColor: hovered && !isFocused ? theme.highlightBG : background,
}),

tabOpacity: (hovered, isFocused, activeOpacityValue, inactiveOpacityValue) => (hovered && !isFocused ? inactiveOpacityValue : activeOpacityValue),

/**
* @param {String} backgroundColor
* @param {Number} height
Expand Down

0 comments on commit 7c7fa65

Please sign in to comment.