Thread list rows for chat sidebars and conversation pickers.
Thread list rows for chat sidebars and conversation pickers.
import { ChatListView } from 'heroui-native-pro' ;
< ChatListView >
< ChatListView.SectionHeader >...</ ChatListView.SectionHeader >
< ChatListView.Item >
< ChatListView.ItemContent >
< ChatListView.Icon >...</ ChatListView.Icon >
< ChatListView.Text >
< ChatListView.Title >...</ ChatListView.Title >
< ChatListView.Preview >...</ ChatListView.Preview >
</ ChatListView.Text >
< ChatListView.Meta >...</ ChatListView.Meta >
</ ChatListView.ItemContent >
</ ChatListView.Item >
< ChatListView.Separator />
</ ChatListView >
ChatListView : Root column with the list role. Sets the row density shared by every item and cascades animation="disable-all". Hosts the rows directly, or a FlatList / SectionList that renders them. Give it an accessibilityLabel such as "Recent chats".
ChatListView.Item : Pressable thread row (heroui-native PressableFeedback) with a press highlight and the button role. Supports isSelected, isUnread, and isDisabled. Rows are at least 44pt tall.
ChatListView.ItemContent : Optional row wrapping the icon, text, and meta columns. The item is a row itself, so you can leave it out.
ChatListView.Icon : Leading slot for an icon or an avatar. Sizes to its content.
ChatListView.Text : Column stacking the title and preview. Takes the remaining width so both truncate before the meta column.
ChatListView.Title : Thread title, truncated to one line by default.
ChatListView.Preview : Last-message preview, truncated to one line by default. Hidden in the compact density.
ChatListView.Meta : Trailing column. The first entry (the time) sits on the title line and a second one (an unread badge or a pin icon) drops to the preview line. Runs of text are wrapped in a Text; other nodes render as-is. Hidden in the compact density.
ChatListView.SectionHeader : Date-group label such as "Today" or "Previous 7 days", with the header role.
ChatListView.Separator : heroui-native Separator inset to the rows' leading content edge.
Native icons do not inherit a text color, so pass the muted color to the icon yourself.
< ChatListView accessibilityLabel = "Recent chats" >
{threads. map ((thread) => (
< ChatListView.Item key ={thread.id} onPress ={() => openThread (thread.id)}>
< ChatListView.ItemContent >
< ChatListView.Icon >
< CommentIcon size ={ 18 } color ={mutedColor} />
</ ChatListView.Icon >
< ChatListView.Text >
< ChatListView.Title >{thread.title}</ ChatListView.Title >
< ChatListView.Preview >{thread.preview}</ ChatListView.Preview >
</ ChatListView.Text >
< ChatListView.Meta >{thread.updatedAt}</ ChatListView.Meta >
</ ChatListView.ItemContent >
</ ChatListView.Item >
))}
</ ChatListView >
Use density="compact" for chat drawers and pickers. Rows show the title only: Preview and Meta render nothing. Mark the open thread with isSelected, which adds a soft accent fill and announces the row as selected. Round the rows with a className when the list is inset from the screen edges.
< ChatListView density = "compact" className = "px-3" >
{threads. map ((thread) => (
< ChatListView.Item
key ={thread.id}
isSelected ={thread.id === activeId}
className = "rounded-2xl"
onPress ={() => setActiveId (thread.id)}
>
< ChatListView.Title >{thread.title}</ ChatListView.Title >
</ ChatListView.Item >
))}
</ ChatListView >
Icon sizes to its content, so it also hosts an Avatar. Set isUnread on the item to use a heavier title, a foreground preview, and an accent time. Put an unread count after the time in Meta. isUnread is visual only, so include the unread state in the row's accessibilityLabel (for example "Design Team, 3 unread messages").
< ChatListView.Item isUnread ={conversation.unreadCount > 0 }>
< ChatListView.Icon >
< Avatar size = "md" alt ={conversation.name}>
< Avatar.Image source ={{ uri: conversation.avatar }} />
< Avatar.Fallback >{conversation.initials}</ Avatar.Fallback >
</ Avatar >
</ ChatListView.Icon >
< ChatListView.Text >
< ChatListView.Title >{conversation.name}</ ChatListView.Title >
< ChatListView.Preview >{conversation.message}</ ChatListView.Preview >
</ ChatListView.Text >
< ChatListView.Meta >
{conversation.time}
{conversation.unreadCount > 0 ? (
< Badge size = "sm" color = "accent" >{conversation.unreadCount}</ Badge >
) : null }
</ ChatListView.Meta >
</ ChatListView.Item >
Separators are opt-in. ChatListView.Separator is inset by the row padding. Widen the inset to line up with the text when rows have an avatar (16px padding + 40px avatar + 12px gap).
< ChatListView >
{conversations. map ((conversation, index) => (
< Fragment key ={conversation.id}>
{index > 0 ? < ChatListView.Separator className = "ms-[68px]" /> : null }
< ConversationRow conversation ={conversation} />
</ Fragment >
))}
</ ChatListView >
For long histories, render a FlatList or SectionList inside the root. Give the root flex-1. Items still read the root density through context. Add bg-background to sticky section headers so rows do not show through them.
< ChatListView density = "compact" className = "flex-1" >
< SectionList
sections ={sections}
keyExtractor ={(thread) => thread.id}
renderSectionHeader ={({ section }) => (
< ChatListView.SectionHeader className = "bg-background" >
{section.title}
</ ChatListView.SectionHeader >
)}
renderItem ={({ item }) => (
< ChatListView.Item onPress ={() => openThread (item.id)}>
< ChatListView.Title >{item.title}</ ChatListView.Title >
</ ChatListView.Item >
)}
ItemSeparatorComponent ={() => < ChatListView.Separator />}
/>
</ ChatListView >
Compose rows with SwipeableRow in its inline variant to pin, rename, or delete threads.
< SwipeableRow variant = "inline" >
< SwipeableRow.Actions side = "end" >
< SwipeableRow.Action variant = "danger" onPress ={() => deleteThread (thread.id)}>
Delete
</ SwipeableRow.Action >
</ SwipeableRow.Actions >
< SwipeableRow.Content >
< ChatListView.Item onPress ={() => openThread (thread.id)}>...</ ChatListView.Item >
</ SwipeableRow.Content >
</ SwipeableRow >
Preview is a Text, so nested Text elements are allowed. Raise numberOfLines for two-line previews.
< ChatListView.Preview numberOfLines ={ 2 }>
< Text className = "font-medium text-foreground" >You: </ Text >
Rewrite this paragraph to sound more concise.
</ ChatListView.Preview >
Rows show a highlight overlay while pressed. They do not scale by default. Opt in with animation.scale, or turn off all press feedback with animation="disable-all" on the root.
< ChatListView.Item animation ={{ scale: true }} />
< ChatListView.Item animation ={{ highlight: { opacity: { value: [ 0 , 0.15 ] } } }} />
< ChatListView animation = "disable-all" >...</ ChatListView >
import { Avatar } from 'heroui-native' ;
import { Badge, ChatListView } from 'heroui-native-pro' ;
import { Fragment } from 'react' ;
import { View } from 'react-native' ;
type Conversation = {
id: string ;
name: string ;
avatar: string ;
time: string ;
message: string ;
unreadCount?: number ;
};
const CONVERSATIONS: Conversation [] = [
{
id: 'design-team' ,
name: 'Design Team' ,
avatar: 'https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/purple.jpg' ,
time: '9:41' ,
message: 'Maya: Pushed the new prototype, take a look' ,
unreadCount: 3 ,
},
{
id: 'ava' ,
name: 'Ava Thompson' ,
avatar: 'https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/blue.jpg' ,
time: '8:15' ,
message: 'Quarterly planning agenda is attached' ,
unreadCount: 1 ,
},
{
id: 'weekend-trip' ,
name: 'Weekend Trip' ,
avatar: 'https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/orange.jpg' ,
time: 'Yesterday' ,
message: 'Liam: Booked the cabin for Saturday' ,
},
{
id: 'noah' ,
name: 'Noah Carter' ,
avatar: 'https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/green.jpg' ,
time: 'Mon' ,
message: 'Thanks, the invoice looks good to me' ,
},
];
function getInitials (name: string ): string {
return name
. split ( ' ' )
. map ((part) => part. charAt ( 0 ))
. slice ( 0 , 2 )
. join ( '' )
. toUpperCase ();
}
const ConversationRow = ({ conversation }: { conversation: Conversation }) => {
const { name, avatar, time, message, unreadCount = 0 } = conversation;
return (
< ChatListView.Item isUnread ={unreadCount > 0 }>
< ChatListView.Icon >
< Avatar size = "md" alt ={name}>
< Avatar.Image source ={{ uri: avatar }} />
< Avatar.Fallback >{ getInitials (name)}</ Avatar.Fallback >
</ Avatar >
</ ChatListView.Icon >
< ChatListView.Text >
< ChatListView.Title >{name}</ ChatListView.Title >
< ChatListView.Preview >{message}</ ChatListView.Preview >
</ ChatListView.Text >
< ChatListView.Meta >
{time}
{unreadCount > 0 ? (
< Badge size = "sm" color = "accent" >
{unreadCount}
</ Badge >
) : null }
</ ChatListView.Meta >
</ ChatListView.Item >
);
};
export default function MessagesExample () {
return (
< View className = "flex-1 justify-center" >
< ChatListView accessibilityLabel = "Messages" >
{CONVERSATIONS. map ((conversation, index) => (
< Fragment key ={conversation.id}>
{index > 0 ? (
< ChatListView.Separator className = "ms-[68px]" />
) : null }
< ConversationRow conversation ={conversation} />
</ Fragment >
))}
</ ChatListView >
</ View >
);
}
prop type default description childrenReactNode- Items, section headers, and separators, or a FlatList / SectionList rendering them density'comfortable' | 'compact''comfortable'Row density shared by every item. compact hides Preview and Meta classNamestring- Additional CSS classes for the root column animationChatListViewRootAnimation- Animation configuration for the root ...ViewPropsViewProps- All standard React Native View props are supported
The root animates nothing itself. Can be:
"disable-all": Disable all animations, including every item's press feedback
undefined: Use default animations
prop type default description childrenReactNode- Row content, usually a ChatListView.ItemContent isSelectedbooleanfalseWhether the row is the active thread. Adds a soft accent fill and is announced isUnreadbooleanfalseHeavier title, foreground preview, and accent meta time. Visual only isDisabledbooleanfalseWhether the row is disabled. Disabled rows cannot be pressed and are dimmed classNamestring- Additional CSS classes for the row. With animation.scale, transform is reserved onPress(event: GestureResponderEvent) => void- Called when the row is pressed onLongPress(event: GestureResponderEvent) => void- Called on long press, for example to open a context menu animationChatListViewItemAnimation- Press highlight and optional scale configuration ...PressableFeedbackPropsPressableFeedbackProps- heroui-native PressableFeedback props except children, animation, asChild, and isAnimatedStyleActive
Animation configuration for the row's press feedback. Can be:
true or undefined: Default press highlight, no press scale
false or "disabled": No press highlight
"disable-all": Disable all animations, including animated children
object: Custom configuration
prop type default description state'disabled' | 'disable-all' | boolean- Disable animations while customizing properties scalePressableFeedbackScaleAnimation- Press scale (heroui-native PressableFeedback). Off unless set highlightPressableFeedbackHighlightAnimation- Highlight overlay (heroui-native PressableFeedback.Highlight)
prop type default description childrenReactNode- Icon, text column, and meta column classNamestring- Additional CSS classes for the content row ...ViewPropsViewProps- All standard React Native View props are supported
prop type default description childrenReactNode- Icon or avatar classNamestring- Additional CSS classes for the icon slot ...ViewPropsViewProps- All standard React Native View props are supported
prop type default description childrenReactNode- Title and preview classNamestring- Additional CSS classes for the text column ...ViewPropsViewProps- All standard React Native View props are supported
prop type default description childrenReactNode- Title text numberOfLinesnumber1Maximum number of lines before truncation classNamestring- Additional CSS classes for the title text ...TextPropsTextProps- All standard React Native Text props are supported
prop type default description childrenReactNode- Preview text. Nested Text elements are allowed numberOfLinesnumber1Maximum number of lines before truncation classNamestring- Additional CSS classes for the preview text ...TextPropsTextProps- All standard React Native Text props are supported
prop type default description childrenReactNode- Text runs are wrapped in a Text; other nodes render as-is classNamestring- Additional CSS classes for the meta column classNamesElementSlots<MetaSlots>- Additional CSS classes for the slots styles{ container?: ViewStyle; text?: TextStyle }- Styles for the slots ...ViewPropsViewProps- All standard React Native View props are supported
prop type description containerstringCustom class name for the trailing column textstringCustom class name for each run of text (the time)
prop type description containerViewStyleStyles for the trailing column textTextStyleStyles for each run of text (the time)
prop type default description childrenReactNode- Section label classNamestring- Additional CSS classes for the section label ...TextPropsTextProps- All standard React Native Text props are supported
prop type default description classNamestring- Additional CSS classes. Use ms-* to change the inset ...SeparatorPropsSeparatorProps- All heroui-native Separator props are supported