AI Integration Quick Reference
AI Integration Quick Reference
Overview
Languages such as Arabic are read right to left. From UI Kit 6.4.0, in an RTL layout, the UI Kit mirrors its components: avatars, names, buttons, message bubbles, menus and sheets swap sides, and arrows point the other way. Mirroring the layout doesn’t flip the content. The UI Kit keeps every piece of content readable:- Each message reads in its own direction, so an English message in an Arabic chat still reads left to right.
- Names inside sentences the UI Kit writes keep their order.
- Audio and video players and code blocks stay left to right.
Layout Direction and Language
Layout direction and language are two separate settings:
With the default,
AUTO, the UI Kit takes the direction Android gives your app, and Android makes an app RTL when its language is RTL. CometChatLocalize.setLocale changes the UI Kit’s language only, never its direction.
Before You Start
Declare RTL support in your app’s manifest:AndroidManifest.xml
View out left to right. The Kotlin (XML Views) UI Kit can’t mirror at all, and the Jetpack Compose UI Kit can’t follow an Arabic app under AUTO. The UI Kit doesn’t add the flag for you, because it would also mirror your app’s own screens.
Turn On RTL
Follow the app’s language (default)
WithAUTO, the UI Kit uses the direction the app is already in. Set the app’s language with the platform API, and Android makes the whole app RTL, UI Kit included:
- Kotlin
Set it for the whole UI Kit
PasssetLayoutDirection to UIKitSettings to give every UI Kit component a fixed direction, whatever the language:
- Kotlin
Change it at runtime
UseCometChatUIKit.setLayoutDirection to change the direction while the app is running, for example from a settings screen. Read the current value with CometChatUIKit.getLayoutDirection().
- Kotlin
Each component reads the global direction when it is created. A screen that is already open keeps its direction until it is recreated. Calling
init() again keeps the runtime value unless its UIKitSettings sets setLayoutDirection itself.Set It Per Component
Every main UI Kit component takes its own direction. It overrides the global setting for that component and everything inside it.- Kotlin (XML Views)
- Jetpack Compose
AUTO, to inherit the direction from the UI Kit component around it, or from the global setting. In Compose, pass layoutDirection by name.
These components take a direction of their own:
Message bubbles, the reaction list, the create-poll and message-information screens, the sticker keyboard, the media recorder and the AI views take one too.
Base components
Base components (avatar, badge, date, receipts, status indicator, search box, toolbar, list items, popup menus) have no direction setting. Inside a UI Kit component they follow it. Used on their own, they follow the global setting, and underAUTO the app.
Which Setting Wins
When settings disagree, the first rule that gives a direction wins:- Audio and video players, and code blocks, are always left to right.
- The component’s own direction, when it is
LTRorRTL. - The nearest UI Kit component around it that has its own direction.
- The global setting, when it is
LTRorRTL. - The app’s own direction.
LTR or RTL, setting android:layoutDirection on a parent view or providing LocalLayoutDirection around a component doesn’t change it, because each component applies the global setting at its root.
What the UI Kit Does for You
- Overlays follow the component that opens them. Menus, dialogs, bottom sheets and popups a UI Kit component opens use that component’s direction, even though they draw in a window of their own.
- Screens the UI Kit starts keep the direction. The image and video viewers open in the direction of the component that started them. Call screens follow the global setting.
- Short messages follow the component. Messages such as “Message pinned” appear as a snackbar in the component’s direction. In the Compose UI Kit the bar is drawn in Compose, so it mirrors without
supportsRtl. - Your app’s own screens don’t change. The UI Kit never changes the app’s direction or locale.
What Changes in RTL
Layout
Everything that has a side moves to the other one: avatars, titles, subtitles, timestamps, unread badges, receipts, buttons, the composer’s actions, message bubbles, menus, sheets, swipe actions and horizontal lists. Sent messages sit on the left and received messages on the right. Swipe to reply goes toward the left. Labels the UI Kit draws (toolbar titles, dialog titles and text, menu items, search hints, section headers, empty and error states) sit at the component’s start, which is the right in RTL.Icons
Icons you pass into the UI Kit are drawn as you give them. For an arrow that should mirror, use a vector drawable with
android:autoMirrored="true".
What doesn’t mirror
- Audio and video players, including voice notes and the recorder’s playback row: controls and progress bars stay left to right in every language. The card around them follows the component.
- Code blocks and inline code stay left to right.
Text, numbers and dates
- Each text reads in its own direction. Its first letter decides: a message that starts with an English letter reads left to right, one that starts with an Arabic letter reads right to left, in an RTL or an LTR screen. Text with no letters at all, such as
123 + 456 = 579, reads left to right, in message bubbles and while you type it in the composer. - Names keep their place. Sentences the UI Kit writes, such as group action lines (“X added Y”), are translated, and the names, numbers and links inside them can’t scramble the sentence.
- Numbers use the language’s own digits. In Arabic, dates, times, counts, file sizes, recorder timers and media durations use Arabic digits (٠١٢٣٤٥٦٧٨٩), even where the phone’s region uses Western digits. Hindi uses Devanagari digits (०–९), and every other language uses 0–9. An English app set to RTL keeps 0–9.
- Dates follow the app’s language, including after an in-app language switch. Text you supply yourself, for example through a date formatter callback, is shown as given.
Custom Views in RTL
Views you pass into the UI Kit (view slots, custom message templates, custom bubbles) are placed inside the component’s direction. Use direction-aware values so they mirror with the rest of the UI Kit:
Read the direction from the view or the composition, never from the app’s configuration: a UI Kit component can be set the other way from the app.
Your own overlays
A dialog or popup you open from a custom view starts a new window, which follows the app, not the component. Copy the direction across:- Kotlin (XML Views)
- Jetpack Compose
Upgrading From an Earlier Version
Languages
The UI Kit ships Arabic translations. For another RTL language, such as Hebrew, Persian or Urdu, add its strings as described in Localize. With the app’s language set to it,AUTO lays the UI Kit out right to left.
Next Steps
Localize
Set the UI Kit’s language and translations
Methods
UIKitSettings and CometChatUIKit reference
Custom View Slots
Replace parts of a component with your own views
Troubleshooting
Common RTL questions