fix for header

This commit is contained in:
Gleidson Daniel 2022-09-19 10:32:36 -03:00 committed by Diego Mello
parent 0f138a7d92
commit b20032bbf5
3 changed files with 43 additions and 5 deletions

View File

@ -1,5 +1,5 @@
import React from 'react'; import React from 'react';
import { Platform, StyleSheet, Text } from 'react-native'; import { Platform, StyleSheet, Text, ViewStyle } from 'react-native';
import { PlatformPressable } from '@react-navigation/elements'; import { PlatformPressable } from '@react-navigation/elements';
import { CustomIcon, ICustomIcon, TIconsName } from '../CustomIcon'; import { CustomIcon, ICustomIcon, TIconsName } from '../CustomIcon';
@ -13,6 +13,7 @@ export interface IHeaderButtonItem extends Omit<ICustomIcon, 'name' | 'size' | '
testID?: string; testID?: string;
badge?(): void; badge?(): void;
color?: string; color?: string;
containerStyle?: ViewStyle;
} }
export const BUTTON_HIT_SLOP = { export const BUTTON_HIT_SLOP = {
@ -39,10 +40,19 @@ const styles = StyleSheet.create({
} }
}); });
const Item = ({ title, iconName, onPress, testID, badge, color, ...props }: IHeaderButtonItem): React.ReactElement => { const Item = ({
title,
iconName,
onPress,
testID,
badge,
color,
containerStyle,
...props
}: IHeaderButtonItem): React.ReactElement => {
const { colors } = useTheme(); const { colors } = useTheme();
return ( return (
<PlatformPressable onPress={onPress} testID={testID} hitSlop={BUTTON_HIT_SLOP} style={styles.container}> <PlatformPressable onPress={onPress} testID={testID} hitSlop={BUTTON_HIT_SLOP} style={[styles.container, containerStyle]}>
<> <>
{iconName ? ( {iconName ? (
<CustomIcon name={iconName} size={24} color={color || colors.headerTintColor} {...props} /> <CustomIcon name={iconName} size={24} color={color || colors.headerTintColor} {...props} />

View File

@ -0,0 +1,21 @@
import React from 'react';
import { Text } from 'react-native';
import { useTheme } from '../../theme';
import Styles from '../../views/Styles';
export default function HeaderTitle({ title }: { title: string }): React.ReactElement {
const { colors } = useTheme();
return (
<Text
numberOfLines={1}
style={{
fontSize: 18,
color: colors.headerTitleColor,
...Styles.textSemibold
}}
>
{title}
</Text>
);
}

View File

@ -20,6 +20,7 @@ import SearchBox from '../containers/SearchBox';
import sharedStyles from './Styles'; import sharedStyles from './Styles';
import { IApplicationState } from '../definitions'; import { IApplicationState } from '../definitions';
import { TDataSelect } from '../definitions/IDataSelect'; import { TDataSelect } from '../definitions/IDataSelect';
import HeaderTitle from '../containers/HeaderTitle';
const styles = StyleSheet.create({ const styles = StyleSheet.create({
buttonText: { buttonText: {
@ -82,7 +83,8 @@ class SelectListView extends React.Component<ISelectListViewProps, ISelectListVi
const { selected } = this.state; const { selected } = this.state;
const options: StackNavigationOptions = { const options: StackNavigationOptions = {
headerTitle: I18n.t(this.title) headerTitle: () => <HeaderTitle title={I18n.t(this.title)} />,
headerRightContainerStyle: { paddingRight: 6 }
}; };
if (isMasterDetail) { if (isMasterDetail) {
@ -90,7 +92,12 @@ class SelectListView extends React.Component<ISelectListViewProps, ISelectListVi
} }
options.headerRight = () => ( options.headerRight = () => (
<HeaderButton.Item title={I18n.t('Next')} onPress={() => this.nextAction(selected)} testID='select-list-view-submit' /> <HeaderButton.Item
title={I18n.t('Next')}
onPress={() => this.nextAction(selected)}
testID='select-list-view-submit'
containerStyle={{ padding: 0 }}
/>
); );
navigation.setOptions(options); navigation.setOptions(options);