Skip to content

Design Kits issues #2836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/components/tabController/TabBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {Colors, Spacings, Typography} from '../../style';
import FadedScrollView from '../fadedScrollView';
import {FaderProps} from '../fader';
import useScrollToItem from './useScrollToItem';
import {orientations} from '../../commons/Constants';
import {useDidUpdate} from 'hooks';

const FIX_RTL = Constants.isRTL && Constants.isAndroid;
Expand Down Expand Up @@ -164,7 +163,7 @@ const TabBar = (props: Props) => {
} = props;

const tabBar = useRef<typeof FadedScrollView>();
const [key, setKey] = useState<orientations>(Constants.orientation);
const [key, setKey] = useState<string>(generateKey(Constants.orientation, labelColor, selectedLabelColor));
const context = useContext(TabBarContext);
const {items: contextItems, currentPage, targetPage, containerWidth: contextContainerWidth} = context;
const containerWidth: number = useMemo(() => {
Expand Down Expand Up @@ -286,10 +285,14 @@ const TabBar = (props: Props) => {
focusIndex(currentPage.value);
} else {
reset();
setKey(Constants.orientation);
setKey(generateKey(Constants.orientation, labelColor, selectedLabelColor));
}
}, [containerWidth]);

useDidUpdate(() => {
setKey(generateKey(Constants.orientation, labelColor, selectedLabelColor));
}, [labelColor, selectedLabelColor]);

return (
<View style={_containerStyle} key={key} bg-$backgroundElevated>
<FadedScrollView
Expand Down Expand Up @@ -365,4 +368,7 @@ const styles = StyleSheet.create({
}
});

const generateKey = (orientation: string, labelColor = '', selectedLabelColor = '') =>
`${orientation}_${labelColor}_${selectedLabelColor}`;

export default asBaseComponent<TabControllerBarProps>(forwardRef<Props>(TabBar));
8 changes: 6 additions & 2 deletions src/style/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,15 @@ export class Colors {
const sliced = tints.slice(0, size);
const adjusted = options?.adjustSaturation && adjustSaturation(sliced, color);
return adjusted || sliced;
});
}, generatePaletteCacheResolver);

defaultOptions = {adjustLightness: true, adjustSaturation: true, addDarkestTints: false, avoidReverseOnDark: false};

generateColorPalette = _.memoize((color: string, options?: GeneratePaletteOptions): string[] => {
const _options = {...this.defaultOptions, ...options};
const palette = this.generatePalette(color, _options);
return this.shouldReverseOnDark(_options?.avoidReverseOnDark) ? _.reverse(palette) : palette;
});
}, generatePaletteCacheResolver);

private generateDesignTokens(primaryColor: string, dark?: boolean) {
let colorPalette: string[] = this.generatePalette(primaryColor);
Expand Down Expand Up @@ -371,6 +371,10 @@ function threeDigitHexToSix(value: string) {
return value.replace(/./g, '$&$&');
}

function generatePaletteCacheResolver(color: string, options?: GeneratePaletteOptions) {
return `${color}${options ? '_' + JSON.stringify(options) : ''}`;
}

const TypedColors = Colors as ExtendTypeWith<typeof Colors, typeof colorsPalette & typeof DesignTokens>;
const colorObject = new TypedColors();
colorObject.loadColors(colorsPalette);
Expand Down