-
Notifications
You must be signed in to change notification settings - Fork 9
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
feat: Conversation requests screen UI components #1608
Conversation
features/conversation-requests-list/conversation-requests-list.screen-header.tsx
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Can we refactor the
Chip
component to not havename
oravatarUri
and showAvatar? And make it more composable?
Here's some code I generated with AI. Maybe need to verify but something like this would be amazing.
import { Avatar as RNAvatar } from "@/components/Avatar";
import { Center } from "@/design-system/Center";
import { Text as RNText } from "@/design-system/Text";
import { useAppTheme } from "@/theme/useAppTheme";
import React from "react";
import { Pressable, StyleProp, ViewStyle, TextStyle } from "react-native";
const ChipContext = React.createContext<{
size: "sm" | "md";
disabled?: boolean;
isSelected?: boolean;
} | null>(null);
function useChipContext() {
const context = React.useContext(ChipContext);
if (!context) {
throw new Error("Chip components must be used within a Chip");
}
return context;
}
type ChipProps = {
isSelected?: boolean;
onPress?: () => void;
size?: "sm" | "md";
disabled?: boolean;
variant?: "filled" | "outlined";
children: React.ReactNode;
};
export function Chip({
children,
isSelected,
onPress,
size = "sm",
disabled,
variant = "outlined",
}: ChipProps) {
const styles = useChipStyles({ variant });
return (
<ChipContext.Provider value={{ size, disabled, isSelected }}>
<Pressable
onPress={onPress}
disabled={disabled}
style={({ pressed }) => [
styles.$container,
isSelected && styles.$selectedContainer,
disabled && styles.$disabledContainer,
pressed && styles.$pressedContainer,
]}
>
<Center style={styles.$content}>{children}</Center>
</Pressable>
</ChipContext.Provider>
);
}
type ChipTextProps = {
children: string;
style?: StyleProp<TextStyle>;
};
export function ChipText({ children, style }: ChipTextProps) {
const { size, disabled, isSelected } = useChipContext();
const styles = useChipStyles({ variant: "outlined" });
return (
<RNText
preset={size === "sm" ? "small" : "body"}
style={[
style,
disabled && styles.$disabledText,
isSelected && styles.$selectedText,
]}
>
{children}
</RNText>
);
}
type ChipIconProps = {
children: React.ReactNode;
};
export function ChipIcon({ children }: ChipIconProps) {
return children;
}
type ChipAvatarProps = {
uri?: string;
name: string;
};
export function ChipAvatar({ uri, name }: ChipAvatarProps) {
const { theme } = useAppTheme();
return <RNAvatar uri={uri} name={name} size={theme.avatarSize.xs} />;
}
// Usage:
{
/*
<Chip size="sm">
<ChipAvatar uri={avatarUri} name={name} />
<ChipText>{name}</ChipText>
</Chip>
*/
}
export function useChipStyles({ variant }: { variant: "filled" | "outlined" }) {
const { theme } = useAppTheme();
const $container = {
borderRadius: theme.spacing.xs,
borderWidth: variant === "outlined" ? theme.borderWidth.sm : 0,
borderColor: theme.colors.border.subtle,
backgroundColor:
variant === "outlined"
? theme.colors.background.surface
: theme.colors.fill.minimal,
paddingVertical:
theme.spacing.xxs -
(variant === "outlined" ? theme.borderWidth.sm * 2 : 0),
paddingHorizontal: theme.spacing.xs,
} satisfies StyleProp<ViewStyle>;
const $content = {
columnGap: theme.spacing.xxxs,
height: theme.spacing.md,
} satisfies StyleProp<ViewStyle>;
return {
constants: {
chipHeight: $container.paddingVertical * 2 + $content.height,
},
$container,
$selectedContainer: {
backgroundColor: theme.colors.fill.minimal,
borderColor:
variant === "outlined" ? theme.colors.fill.minimal : "transparent",
},
$content,
$disabledContainer: {
opacity: 0.5,
},
$pressedContainer: {
opacity: 0.8,
},
$disabledText: {
color: theme.colors.text.muted,
},
$selectedText: {
color: theme.colors.text.accent,
},
} as const;
}
const { theme } = useAppTheme(); | ||
|
||
return ( | ||
<View |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use HStack and no need flexDireciton: row
Yes @thierryskoda great idea for |
design-system/chip.tsx
Outdated
import { Center } from "@/design-system/Center"; | ||
import { Text } from "@/design-system/Text"; | ||
import { Text as RNText } from "@/design-system/Text"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why Text as RNText
? Why not just Text? same with RNAvatar
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed! That should not have been there :)
design-system/chip.tsx
Outdated
name: string; | ||
avatarUri?: string; | ||
const ChipContext = React.createContext<{ | ||
size: "sm" | "md"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should have type IChipSize = 'sm' | 'md'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
Replace Segmented Controller with new toggle design
Add delete all button to header
Linked to #1589
Screen recording