-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/3.0.0' into ar/bump-210
- Loading branch information
Showing
11 changed files
with
290 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { VStack } from "@/design-system/VStack"; | ||
import { memo, ReactElement } from "react"; | ||
import { TextStyle, ViewStyle } from "react-native"; | ||
import { ThemedStyle, useAppTheme } from "@/theme/useAppTheme"; | ||
import { HStack } from "@/design-system/HStack"; | ||
import { Text } from "@/design-system/Text"; | ||
import { Pressable } from "@/design-system/Pressable"; | ||
import { Icon } from "@/design-system/Icon/Icon"; | ||
import { IIconName } from "@/design-system/Icon/Icon.types"; | ||
import { iconSize } from "@/theme/icon"; | ||
|
||
export type ContextMenuItem = { | ||
id: string; | ||
title: string; | ||
action?: () => void; | ||
leftView?: ReactElement; | ||
rightView?: ReactElement; | ||
style?: ViewStyle; | ||
titleStyle?: TextStyle; | ||
}; | ||
|
||
export type ContextMenuItemsProps = { | ||
items: ContextMenuItem[]; | ||
containerStyle?: ViewStyle; | ||
}; | ||
|
||
export const ContextMenuIcon = ({ | ||
icon, | ||
color, | ||
}: { | ||
icon: IIconName; | ||
color?: string; | ||
}) => { | ||
return <Icon icon={icon} size={iconSize.sm} color={color} />; | ||
}; | ||
|
||
export const ContextMenuItems = memo( | ||
({ items, containerStyle }: ContextMenuItemsProps) => { | ||
const { themed } = useAppTheme(); | ||
|
||
const sectionContent = items.map((i, index) => ( | ||
<Pressable key={i.id} onPress={i.action}> | ||
<HStack | ||
style={[ | ||
themed($defaultRowStyle), | ||
index === items.length - 1 ? undefined : themed($borderStyle), | ||
i.style, | ||
]} | ||
> | ||
{i.leftView} | ||
<Text | ||
preset="body" | ||
style={[themed($defaultTitleStyle), i.titleStyle]} | ||
> | ||
{i.title} | ||
</Text> | ||
{i.rightView} | ||
</HStack> | ||
</Pressable> | ||
)); | ||
return ( | ||
<VStack style={themed($defaultContainerStyle)}>{sectionContent}</VStack> | ||
); | ||
} | ||
); | ||
|
||
const $borderStyle: ThemedStyle<ViewStyle> = (theme) => ({ | ||
borderBottomWidth: theme.borderWidth.sm, | ||
borderBottomColor: theme.colors.border.subtle, | ||
}); | ||
|
||
const $defaultRowStyle: ThemedStyle<ViewStyle> = (theme) => ({ | ||
paddingHorizontal: theme.spacing.sm, | ||
paddingVertical: theme.spacing.xxs, | ||
alignItems: "center", | ||
}); | ||
|
||
const $defaultContainerStyle: ThemedStyle<ViewStyle> = (theme) => ({ | ||
marginVertical: theme.spacing.xxs, | ||
backgroundColor: theme.colors.background.raised, | ||
borderRadius: theme.borderRadius.sm, | ||
width: 180, | ||
}); | ||
|
||
const $defaultTitleStyle: ThemedStyle<TextStyle> = (theme) => ({ | ||
flex: 1, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { HStack } from "@/design-system/HStack"; | ||
import { Text } from "@/design-system/Text"; | ||
import { ThemedStyle, useAppTheme } from "@/theme/useAppTheme"; | ||
import { DecodedMessageWithCodecsType } from "@/utils/xmtpRN/client"; | ||
import { useMemo } from "react"; | ||
import { ViewStyle } from "react-native"; | ||
import { isTextMessage } from "../Chat/Message/message-utils"; | ||
|
||
export type PinnedMessagePreviewProps = { | ||
message: DecodedMessageWithCodecsType; | ||
}; | ||
|
||
export const PinnedMessagePreview = (props: PinnedMessagePreviewProps) => { | ||
const { message } = props; | ||
|
||
if (!isTextMessage(message)) { | ||
throw new Error( | ||
"Pinned message preview can only be used for text messages" | ||
); | ||
} | ||
|
||
const { themed } = useAppTheme(); | ||
|
||
const content = useMemo(() => { | ||
return message.content() as string; | ||
}, [message]); | ||
|
||
return ( | ||
<HStack style={themed($containerStyle)}> | ||
<Text numberOfLines={2} preset="smaller"> | ||
{content} | ||
</Text> | ||
</HStack> | ||
); | ||
}; | ||
|
||
const $containerStyle: ThemedStyle<ViewStyle> = ({ | ||
colors, | ||
borderRadius, | ||
borderWidth, | ||
spacing, | ||
}) => ({ | ||
backgroundColor: colors.background.raised, | ||
position: "absolute", | ||
top: 0, | ||
paddingHorizontal: spacing.xs, | ||
paddingVertical: spacing.xxs, | ||
alignSelf: "center", | ||
justifyContent: "center", | ||
alignItems: "center", | ||
borderRadius: borderRadius.sm, | ||
borderWidth: borderWidth.sm, | ||
borderColor: colors.border.subtle, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.