change touch

This commit is contained in:
GleidsonDaniel 2022-04-28 17:10:31 -03:00
parent b9e230fcc8
commit 0c0d9b8946
4 changed files with 34 additions and 24 deletions

View File

@ -61,7 +61,6 @@ interface IListItemContent {
right?: () => JSX.Element | null; right?: () => JSX.Element | null;
disabled?: boolean; disabled?: boolean;
theme: TSupportedThemes; theme: TSupportedThemes;
testID?: string;
color?: string; color?: string;
translateTitle?: boolean; translateTitle?: boolean;
translateSubtitle?: boolean; translateSubtitle?: boolean;
@ -76,7 +75,6 @@ const Content = React.memo(
title, title,
subtitle, subtitle,
disabled, disabled,
testID,
left, left,
right, right,
color, color,
@ -91,9 +89,7 @@ const Content = React.memo(
const { fontScale } = useDimensions(); const { fontScale } = useDimensions();
return ( return (
<View <View style={[styles.container, disabled && styles.disabled, { height: (heightContainer || BASE_HEIGHT) * fontScale }]}>
style={[styles.container, disabled && styles.disabled, { height: (heightContainer || BASE_HEIGHT) * fontScale }]}
{...testProps(testID || '')}>
{left ? <View style={styles.leftContainer}>{left()}</View> : null} {left ? <View style={styles.leftContainer}>{left()}</View> : null}
<View style={styles.textContainer}> <View style={styles.textContainer}>
<View style={styles.textAlertContainer}> <View style={styles.textAlertContainer}>
@ -121,25 +117,28 @@ const Content = React.memo(
} }
); );
interface IListButtonPress extends IListItemButton {
onPress: Function;
}
interface IListItemButton { interface IListItemButton {
title?: string; title?: string;
disabled?: boolean; disabled?: boolean;
theme: TSupportedThemes; theme: TSupportedThemes;
backgroundColor?: string; backgroundColor?: string;
testID?: string;
underlayColor?: string; underlayColor?: string;
} }
interface IListButtonPress extends IListItemButton {
onPress: Function;
}
const Button = React.memo(({ onPress, backgroundColor, underlayColor, ...props }: IListButtonPress) => ( const Button = React.memo(({ onPress, backgroundColor, underlayColor, ...props }: IListButtonPress) => (
<Touch <Touch
onPress={() => onPress(props.title)} onPress={() => onPress(props.title)}
style={{ backgroundColor: backgroundColor || themes[props.theme].backgroundColor }} style={{ backgroundColor: backgroundColor || themes[props.theme].backgroundColor }}
underlayColor={underlayColor} underlayColor={underlayColor}
enabled={!props.disabled} enabled={!props.disabled}
theme={props.theme}> theme={props.theme}
{...testProps(props.testID)}
touchable>
<Content {...props} /> <Content {...props} />
</Touch> </Touch>
)); ));

View File

@ -1,5 +1,5 @@
import React from 'react'; import React from 'react';
import { RectButton, RectButtonProps } from 'react-native-gesture-handler'; import { RectButton, RectButtonProps, TouchableOpacity } from 'react-native-gesture-handler';
import { TSupportedThemes } from '../theme'; import { TSupportedThemes } from '../theme';
import { themes } from '../lib/constants'; import { themes } from '../lib/constants';
@ -9,6 +9,7 @@ interface ITouchProps extends RectButtonProps {
theme: TSupportedThemes; theme: TSupportedThemes;
accessibilityLabel?: string; accessibilityLabel?: string;
testID?: string; testID?: string;
touchable?: boolean;
} }
class Touch extends React.Component<ITouchProps> { class Touch extends React.Component<ITouchProps> {
@ -23,8 +24,15 @@ class Touch extends React.Component<ITouchProps> {
}; };
render(): JSX.Element { render(): JSX.Element {
const { children, onPress, theme, underlayColor, ...props } = this.props; const { children, onPress, theme, underlayColor, touchable, ...props } = this.props;
if (touchable) {
return (
<TouchableOpacity onPress={onPress as () => void} {...(props as any)}>
{children}
</TouchableOpacity>
);
}
return ( return (
<RectButton <RectButton
ref={this.getRef} ref={this.getRef}

View File

@ -13,17 +13,18 @@ interface SidebarItemProps {
text: string; text: string;
current?: boolean; current?: boolean;
onPress(): void; onPress(): void;
testID: string; test: string;
theme: TSupportedThemes; theme: TSupportedThemes;
} }
const Item = React.memo(({ left, right, text, onPress, testID, current, theme }: SidebarItemProps) => ( const Item = React.memo(({ left, right, text, onPress, test, current, theme }: SidebarItemProps) => (
<Touch <Touch
key={testID} key={test}
{...testProps(testID)} {...testProps(test)}
onPress={onPress} onPress={onPress}
theme={theme} theme={theme}
style={[styles.item, current && { backgroundColor: themes[theme].borderColor }]}> style={[styles.item, current && { backgroundColor: themes[theme].borderColor }]}
touchable>
<View style={styles.itemHorizontal}>{left}</View> <View style={styles.itemHorizontal}>{left}</View>
<View style={styles.itemCenter}> <View style={styles.itemCenter}>
<Text style={[styles.itemText, { color: themes[theme].titleText }]} numberOfLines={1} accessibilityLabel={text}> <Text style={[styles.itemText, { color: themes[theme].titleText }]} numberOfLines={1} accessibilityLabel={text}>

View File

@ -146,8 +146,10 @@ class Sidebar extends Component<ISidebarProps, ISidebarState> {
} }
sidebarNavigate = (route: string) => { sidebarNavigate = (route: string) => {
const { navigation } = this.props;
// @ts-ignore // @ts-ignore
logEvent(events[`SIDEBAR_GO_${route.replace('StackNavigator', '').replace('View', '').toUpperCase()}`]); logEvent(events[`SIDEBAR_GO_${route.replace('StackNavigator', '').replace('View', '').toUpperCase()}`]);
navigation.closeDrawer();
Navigation.navigate(route); Navigation.navigate(route);
}; };
@ -177,7 +179,7 @@ class Sidebar extends Component<ISidebarProps, ISidebarState> {
text={I18n.t('Admin_Panel')} text={I18n.t('Admin_Panel')}
left={<CustomIcon name='settings' size={20} color={themes[theme!].titleText} />} left={<CustomIcon name='settings' size={20} color={themes[theme!].titleText} />}
onPress={() => this.sidebarNavigate(routeName)} onPress={() => this.sidebarNavigate(routeName)}
testID='sidebar-admin' test='sidebar-admin'
theme={theme!} theme={theme!}
current={this.currentItemKey === routeName} current={this.currentItemKey === routeName}
/> />
@ -188,12 +190,12 @@ class Sidebar extends Component<ISidebarProps, ISidebarState> {
renderNavigation = () => { renderNavigation = () => {
const { theme } = this.props; const { theme } = this.props;
return ( return (
<> <View>
<SidebarItem <SidebarItem
text={I18n.t('Chats')} text={I18n.t('Chats')}
left={<CustomIcon name='message' size={20} color={themes[theme!].titleText} />} left={<CustomIcon name='message' size={20} color={themes[theme!].titleText} />}
onPress={() => this.sidebarNavigate('ChatsStackNavigator')} onPress={() => this.sidebarNavigate('ChatsStackNavigator')}
testID='sidebar-chats' test='sidebar-chats'
theme={theme!} theme={theme!}
current={this.currentItemKey === 'ChatsStackNavigator'} current={this.currentItemKey === 'ChatsStackNavigator'}
/> />
@ -201,7 +203,7 @@ class Sidebar extends Component<ISidebarProps, ISidebarState> {
text={I18n.t('Profile')} text={I18n.t('Profile')}
left={<CustomIcon name='user' size={20} color={themes[theme!].titleText} />} left={<CustomIcon name='user' size={20} color={themes[theme!].titleText} />}
onPress={() => this.sidebarNavigate('ProfileStackNavigator')} onPress={() => this.sidebarNavigate('ProfileStackNavigator')}
testID='sidebar-profile' test='sidebar-profile'
theme={theme!} theme={theme!}
current={this.currentItemKey === 'ProfileStackNavigator'} current={this.currentItemKey === 'ProfileStackNavigator'}
/> />
@ -209,7 +211,7 @@ class Sidebar extends Component<ISidebarProps, ISidebarState> {
text={I18n.t('Display')} text={I18n.t('Display')}
left={<CustomIcon name='sort' size={20} color={themes[theme!].titleText} />} left={<CustomIcon name='sort' size={20} color={themes[theme!].titleText} />}
onPress={() => this.sidebarNavigate('DisplayPrefStackNavigator')} onPress={() => this.sidebarNavigate('DisplayPrefStackNavigator')}
testID='sidebar-display' test='sidebar-display'
theme={theme!} theme={theme!}
current={this.currentItemKey === 'DisplayPrefStackNavigator'} current={this.currentItemKey === 'DisplayPrefStackNavigator'}
/> />
@ -217,12 +219,12 @@ class Sidebar extends Component<ISidebarProps, ISidebarState> {
text={I18n.t('Settings')} text={I18n.t('Settings')}
left={<CustomIcon name='administration' size={20} color={themes[theme!].titleText} />} left={<CustomIcon name='administration' size={20} color={themes[theme!].titleText} />}
onPress={() => this.sidebarNavigate('SettingsStackNavigator')} onPress={() => this.sidebarNavigate('SettingsStackNavigator')}
testID='sidebar-settings' test='sidebar-settings'
theme={theme!} theme={theme!}
current={this.currentItemKey === 'SettingsStackNavigator'} current={this.currentItemKey === 'SettingsStackNavigator'}
/> />
{this.renderAdmin()} {this.renderAdmin()}
</> </View>
); );
}; };