Skip to content

Commit

Permalink
Merge pull request Expensify#55347 from software-mansion-labs/feature…
Browse files Browse the repository at this point in the history
…/kuba-nowakowski/fix-tab-switch-smoothness

Tab shift from manual-scan-distance is delayed improvement of existing solution
  • Loading branch information
mountiny authored Jan 29, 2025
2 parents fbe3760 + b67efc4 commit 890b430
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 92 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// eslint-disable-next-line no-restricted-imports
import type {Animated} from 'react-native';
import type GetBackgroudColor from './types';
import type {BackgroundColor, GetBackgroundColorConfig} from './types';

const getBackgroundColor: GetBackgroudColor = ({routesLength, tabIndex, affectedTabs, theme, position, isActive}) => {
function getBackgroundColor({routesLength, tabIndex, affectedTabs, theme, position, isActive}: GetBackgroundColorConfig): BackgroundColor {
if (routesLength > 1) {
const inputRange = Array.from({length: routesLength}, (v, i) => i);
const inputRange = Array.from({length: routesLength}, (_, i) => i);

if (position) {
return position.interpolate({
Expand All @@ -17,7 +17,8 @@ const getBackgroundColor: GetBackgroudColor = ({routesLength, tabIndex, affected

return affectedTabs.includes(tabIndex) && isActive ? theme.border : theme.appBG;
}

return theme.border;
};
}

export default getBackgroundColor;
9 changes: 0 additions & 9 deletions src/components/TabSelector/getBackground/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type GetOpacity from './types';
import type {GetOpacityConfig, Opacity} from './types';

const getOpacity: GetOpacity = ({routesLength, tabIndex, active, affectedTabs, position, isActive}) => {
function getOpacity({routesLength, tabIndex, active, affectedTabs, position, isActive}: GetOpacityConfig): Opacity {
const activeValue = active ? 1 : 0;
const inactiveValue = active ? 0 : 1;

if (routesLength > 1) {
const inputRange = Array.from({length: routesLength}, (v, i) => i);
const inputRange = Array.from({length: routesLength}, (_, i) => i);

if (position) {
return position.interpolate({
Expand All @@ -16,7 +16,8 @@ const getOpacity: GetOpacity = ({routesLength, tabIndex, active, affectedTabs, p

return affectedTabs.includes(tabIndex) && isActive ? activeValue : inactiveValue;
}

return activeValue;
};
}

export default getOpacity;
13 changes: 0 additions & 13 deletions src/components/TabSelector/getOpacity/index.ts

This file was deleted.

46 changes: 0 additions & 46 deletions src/components/TabSelector/getOpacity/types.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
import type {Animated} from 'react-native';
import type {ThemeColors} from '@styles/theme/types';

/**
* Configuration for the getBackgroundColor function.
*/
type GetBackgroudColorConfig = {
type AnimationConfigBase = {
/**
* The number of routes.
*/
Expand All @@ -21,11 +18,6 @@ type GetBackgroudColorConfig = {
*/
affectedTabs: number[];

/**
* The theme colors.
*/
theme: ThemeColors;

/**
* The animated position interpolation.
*/
Expand All @@ -37,11 +29,22 @@ type GetBackgroudColorConfig = {
isActive: boolean;
};

/**
* Function to get the background color.
* @param args - The configuration for the background color.
* @returns The interpolated background color or a string.
*/
type GetBackgroudColor = (args: GetBackgroudColorConfig) => Animated.AnimatedInterpolation<string> | string;
type GetBackgroundColorConfig = AnimationConfigBase & {
/**
* The theme colors.
*/
theme: ThemeColors;
};

type GetOpacityConfig = AnimationConfigBase & {
/**
* Whether we are calculating the opacity for the active tab.
*/
active: boolean;
};

type BackgroundColor = Animated.AnimatedInterpolation<string> | string;

type Opacity = 1 | 0 | Animated.AnimatedInterpolation<number>;

export default GetBackgroudColor;
export type {BackgroundColor, GetBackgroundColorConfig, Opacity, GetOpacityConfig};

0 comments on commit 890b430

Please sign in to comment.