Skip to content

Commit 1912e26

Browse files
author
tfomkin
committed
fix: use GestureAppPressable instead of AppPressable for modals IconButton
1 parent 7d6327e commit 1912e26

2 files changed

Lines changed: 50 additions & 12 deletions

File tree

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,68 @@
11
import { ReactElement } from 'react';
2+
import { PressableProps as GesturePressableProps } from 'react-native-gesture-handler';
23
import { cn } from '@open-webui-react-native/mobile/shared/ui/styles';
34
import { Icon, IconProps } from '../icon/component';
45
import { IconName } from '../icon/types';
5-
import { AppPressable, AppPressableProps } from '../pressable';
6+
import { AppPressable, AppPressableProps, GestureAppPressable } from '../pressable';
67
import { AppSpinner } from '../spinner';
78

8-
export interface IconButtonProps extends AppPressableProps {
9+
interface BaseIconButtonProps {
910
iconName: IconName;
1011
iconProps?: Omit<IconProps, 'name'>;
1112
isLoading?: boolean;
13+
className?: string;
1214
}
1315

14-
export function IconButton({
15-
className,
16+
export type IconButtonProps =
17+
| (BaseIconButtonProps &
18+
AppPressableProps & {
19+
useGestureHandler?: false;
20+
})
21+
| (BaseIconButtonProps &
22+
GesturePressableProps & {
23+
useGestureHandler: true;
24+
});
25+
26+
const IconButtonContent = ({
27+
isLoading,
1628
iconName,
1729
iconProps,
18-
isLoading,
19-
disabled,
20-
...restProps
21-
}: IconButtonProps): ReactElement {
30+
}: Pick<BaseIconButtonProps, 'isLoading' | 'iconName' | 'iconProps'>): ReactElement =>
31+
isLoading ? <AppSpinner size='small' /> : <Icon name={iconName} {...iconProps} />;
32+
33+
export function IconButton(props: IconButtonProps): ReactElement {
34+
const baseClassName = cn('p-8 disabled:opacity-30 items-center justify-center', props.className);
35+
36+
// NOTE: Pressable from react-native does not work correctly with react-native-modal - https://github.com/react-native-modal/react-native-modal/issues/582#issuecomment-1156723062
37+
if (props.useGestureHandler) {
38+
const { useGestureHandler, iconName, iconProps, isLoading, className, ...gestureProps } = props;
39+
40+
return (
41+
<GestureAppPressable
42+
{...gestureProps}
43+
hitSlop={8}
44+
className={baseClassName}
45+
disabled={gestureProps.disabled || isLoading}>
46+
<IconButtonContent
47+
iconName={iconName}
48+
iconProps={iconProps}
49+
isLoading={isLoading} />
50+
</GestureAppPressable>
51+
);
52+
}
53+
54+
const { useGestureHandler, iconName, iconProps, isLoading, className, ...rnProps } = props;
55+
2256
return (
2357
<AppPressable
58+
{...rnProps}
2459
hitSlop={8}
25-
disabled={disabled || isLoading}
26-
className={cn('p-8 disabled:opacity-30 items-center justify-center', className)}
27-
{...restProps}>
28-
{isLoading ? <AppSpinner size='small' /> : <Icon name={iconName} {...iconProps} />}
60+
className={baseClassName}
61+
disabled={rnProps.disabled || isLoading}>
62+
<IconButtonContent
63+
iconName={iconName}
64+
iconProps={iconProps}
65+
isLoading={isLoading} />
2966
</AppPressable>
3067
);
3168
}

libs/mobile/shared/ui/ui-kit/src/modal/component.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export function AppModal({ modalRef, children, ...modalProps }: AppModalProps):
4343
onPress={close}
4444
className='absolute active:opacity-1 active:bg-background-secondary bg-background-primary border border-text-secondary p-0 rounded-full items-center justify-center w-[24] h-[24] top-4 right-4'
4545
iconProps={{ className: 'color-text-primary', width: 16 }}
46+
useGestureHandler
4647
/>
4748
</View>
4849
)}

0 commit comments

Comments
 (0)