Skip to main content

Overview

From UI Kit 5.4.0, CometChat UI Kit supports layouts for right-to-left (RTL) languages such as Arabic. In an RTL layout the kit mirrors its components: avatars, names, buttons, message bubbles, menus and sheets swap sides, and arrows point the other way. You choose the layout direction of the kit’s components with set(layoutDirection:), either for the whole kit or for a single component.
Already using the UI Kit? Make sure your project resolves CometChatUIKitSwift 5.4.0 or later. In Xcode, choose File → Packages → Update to Latest Package Versions.
The direction is a UIUserInterfaceLayoutDirection? value: A direction you set applies to the kit’s components only. Your app’s own screens do not change.
With no direction set, the kit follows your app, as any other UIKit view does. iOS lays out an app right to left when the app runs in a right-to-left language, which requires your app to include that localization, or when your app sets UIView.appearance().semanticContentAttribute.

Language and Direction Are Separate

Language and layout direction are two independent settings: Combine them to get the result you need:
See Localization for the language setting.

Set the Direction

You can set the direction at three levels.

1. Kit Level

CometChatUIKit.set(layoutDirection:) sets the direction for every component the kit creates after the call. Pass nil to go back to following your app.

2. At Start-Up

UIKitSettings.set(layoutDirection:) gives the direction with the rest of your settings. The kit applies it when CometChatUIKit.init(uiKitSettings:) succeeds. If the initialization fails, the direction is not applied. Create the kit’s screens after the initialization succeeds, for example in the .success case. A screen created before then keeps following your app, even after the direction from the settings is applied.
UIKitSettings.set(layoutDirection:) takes .rightToLeft or .leftToRight. To follow your app, leave it out.

3. Component Level

A component’s own set(layoutDirection:) sets the direction of that component only, and wins over the kit-level value. Pass nil to inherit again.
A component-level value takes effect at once, including on a component that is already on screen. set(layoutDirection:) is available on every list screen built on CometChatListBase, and on the other components below: Base views such as avatars, message bubbles, receipts, dates and badges do not have their own set(layoutDirection:). Inside a component they take that component’s direction. Used on their own, they follow the kit-level value.

How the Direction Is Resolved

For each view, the kit uses the first of these that applies:
  1. Audio and video players, and the other parts listed in What Stays Left to Right, are always left to right
  2. The component’s own set(layoutDirection:) value
  3. The direction of the nearest enclosing kit component
  4. The kit-level value
  5. Your app’s layout direction
Screens, alerts and sheets that a component opens take that component’s direction.

Changes Apply to New Components

A component reads the kit-level value once, when it is created. A change made with CometChatUIKit.set(layoutDirection:) applies to components created afterwards. Components that already exist keep the direction they were created with. After you change the kit-level direction, build your open screens again:

Order of Calls Around Init

CometChatUIKit.init(uiKitSettings:) applies the direction from its settings when the initialization succeeds. This affects a kit-level call made around it:
If you set the direction before you initialize the kit, give it with UIKitSettings.set(layoutDirection:). A CometChatUIKit.set(layoutDirection:) call made before CometChatUIKit.init(uiKitSettings:) is replaced when the initialization succeeds.

What Changes in RTL

Everything that has a side moves to the other one: avatars, titles, subtitles, timestamps, unread badges, receipts, buttons, the composer’s actions and attachment tray, the rich text toolbar, context menus, action sheets, reactions and horizontal lists. Sent messages sit on the left and received messages on the right. Swipe to reply goes toward the left. This covers conversation, user and group lists, the message header, message list and composer, polls, search, calls, call logs, the AI assistant views and the notification feed.

What Stays Left to Right

Media playback reads left to right, as in system players. The following parts do not mirror under any direction setting, including when your app itself runs right to left: The rest of the voice recorder does mirror. In a right-to-left layout, the row of controls is reversed: the send button is on the left, and the delete button is on the right.

Message Text and Icons

Message Text Follows Its Own Language

The kit does not force a direction on message text. Each paragraph is aligned and read from its own language: an English message in a right-to-left chat still reads left to right, and an Arabic message in a left-to-right chat still reads right to left.

Names, Numbers and Dates

  • Names keep their place. In text the kit builds, such as group action lines and the last message preview, names, counts and file names are wrapped in Unicode directional isolates (U+2068 and U+2069), so they can’t reorder the words around them. Text the kit returns to you, such as the result of getLastConversationMessage, can contain these invisible characters.
  • Numbers and dates follow the kit’s language. When the language is Arabic, dates, times, counts and durations use Arabic digits (٠١٢٣٤٥٦٧٨٩). Every other language uses 0–9. The last seen date in the message header uses each language’s own date and time format.

Message Composer

A paragraph in the composer takes the direction of the first letter typed: English starts at the left, Arabic at the right. While a line is empty, the cursor sits on the side of the active keyboard’s language. Switching keyboards does not flip a line that already has text.

Directional Icons Mirror

The kit’s built-in icons that point in a direction mirror in a right-to-left layout. Examples are the back button of the message header, the send button of the composer, the reply and thread icons, and the call direction arrows. An icon you supply through a style is drawn as you provide it. To make your own icon mirror, use UIKit’s imageFlippedForRightToLeftLayoutDirection():

Custom Views in RTL

Views you pass into the kit, such as custom list item views, header views and message templates, are placed inside the component and take its direction. Build them with direction-aware values so they mirror with the rest of the kit: Read the direction from the view, not from the app: a kit component can be set the other way from your app.

Next Steps

Localization

Set the language of the UI Kit and override its strings

Theme Introduction

Customize the visual appearance of UI components

Component Styling

Apply custom styles to individual components