rtl-ios-skill

Expert Right-to-Left (RTL) layout implementation for iOS apps (Swift/SwiftUI/UIKit). Use this skill whenever the user wants to: add RTL support, localize for Arabic/Hebrew/Farsi/Urdu, fix mirrored layouts, handle bidirectional text, implement locale-aware UI, audit an existing project for RTL issues, configure semantic content attributes, handle RTL in UITableView/UICollectionView, fix navigation direction for RTL languages, or ensure proper String Catalog / NSLocalizedString integration with RTL. Trigger even for adjacent topics like "internationalization", "i18n", "Arabic support", "Hebrew layout", "BiDi text", "flipped UI", or "mirror my views" — this skill covers all of it.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "rtl-ios-skill" with this command: npx skills add mohideensheiksulaiman/rtl-ios-agent-skill/mohideensheiksulaiman-rtl-ios-agent-skill-rtl-ios-skill

RTL iOS Skill

You are an iOS RTL specialist. Your job is to help implement production-quality Right-to-Left layout support across SwiftUI, UIKit, and hybrid apps. You understand the nuances of semantic layout, BiDi text, locale detection, and Apple's RTL APIs deeply.


Quick Decision Tree

User wants RTL support?
├── SwiftUI project?         → See: Documentation/SwiftUI-RTL.md
├── UIKit project?           → See: Documentation/UIKit-RTL.md
├── Hybrid (SwiftUI+UIKit)?  → Read both Documentation files
├── Text / BiDi issue?       → See: Documentation/BiDi-Text.md
├── Audit existing project?  → Run: Tools/rtl_audit.sh
└── Full integration setup?  → Follow INTEGRATION CHECKLIST below

Core Principles (Always Apply)

1. Semantic Layout Over Absolute Positioning

Never use .left / .right. Always use .leading / .trailing.

// ❌ Wrong
stackView.alignment = .left

// ✅ Correct
stackView.alignment = .leading

2. Semantic Content Attribute (UIKit)

// RTL: intentionally LTR — map/video/logo views
imageView.semanticContentAttribute = .forceLeftToRight

// Default — always prefer:
imageView.semanticContentAttribute = .unspecified

3. RTL Detection

UIKit — Detection Methods

Pick the right method for the right context. Using the wrong one produces incorrect results when semanticContentAttribute overrides are in play.

// ✅ PREFERRED — view-level (layout code inside layoutSubviews, cells, etc.)
// Most accurate: respects semanticContentAttribute overrides on the view or its ancestors.
let isRTL = someView.effectiveUserInterfaceLayoutDirection == .rightToLeft

// ✅ PREFERRED — trait-based (inside UIViewController or UIView subclasses)
// Safe to call in traitCollectionDidChange(_:). Propagates through the hierarchy.
let isRTL = traitCollection.layoutDirection == .rightToLeft
// Or from any view:
let isRTL = view.traitCollection.layoutDirection == .rightToLeft

// ⚠️ APP-LEVEL ONLY — reflects the global app language setting.
// Does NOT respect per-view semanticContentAttribute overrides.
// Use for app-wide decisions (analytics, initial config) — not inside layout code.
let isRTL = UIApplication.shared.userInterfaceLayoutDirection == .rightToLeft

// ℹ️ LOCALE-BASED — language writing direction, not UI direction.
// Use for text/string logic (e.g. BiDi isolation). Does not guarantee the UI is RTL.
let lang = Locale.current.language.languageCode?.identifier ?? ""
let isRTL = Locale.characterDirection(forLanguage: lang) == .rightToLeft

// ℹ️ TEXT-ONLY — for NSAttributedString / TextKit rendering only, not layout.
let str = "مرحبا بالعالم"
let writingDir = str.dominantLanguageWritingDirection // iOS 16+

Quick rule:

ContextUse
layoutSubviews, cell config, constraint setupview.effectiveUserInterfaceLayoutDirection
Inside UIViewController / UIView subclasstraitCollection.layoutDirection
App-wide checks, logging, feature flagsUIApplication.shared.userInterfaceLayoutDirection
Text/string direction logicLocale.characterDirection(forLanguage:)
NSAttributedString / TextKit renderingNSWritingDirection / dominantLanguageWritingDirection

SwiftUI — Environment-Based Detection

@Environment(\.layoutDirection) var layoutDirection
var isRTL: Bool { layoutDirection == .rightToLeft }

4. Text Alignment

// SwiftUI
Text("مرحبا").multilineTextAlignment(.leading)

// UIKit
label.textAlignment = .natural

5. Image Mirroring

// SwiftUI
Image(systemName: "chevron.right")
    .flipsForRightToLeftLayoutDirection(true)

// UIKit
imageView.image = UIImage(systemName: "chevron.right")?
    .imageFlippedForRightToLeftLayoutDirection()

Integration Checklist

  • 1. Enable RTL in scheme — Launch arg: -AppleLanguages (ar)
  • 2. Audit layoutTools/rtl_audit.sh /path/to/project
  • 3. Fix hardcoded directions.left/.right.leading/.trailing
  • 4. Fix text alignment.natural UIKit, .leading SwiftUI
  • 5. Mirror directional iconsflipsForRightToLeftLayoutDirection(true) / imageFlippedForRightToLeftLayoutDirection()
  • 6. Navigation stack — Verify back gesture and transition direction
  • 7. Custom transitions — Use RTLPushAnimator from Documentation/UIKit-RTL.md
  • 8. String Catalog — Add ar, he, fa, ur (see Documentation/BiDi-Text.md)
  • 9. Number/Date formatting — Use locale-aware formatters (see Documentation/BiDi-Text.md)
  • 10. Test on simulator — Set region to an RTL locale (e.g., Saudi Arabia ar_SA, UAE ar_AE, Iran fa_IR)

Common Patterns — Quick Reference

RTL-aware HStack (SwiftUI)

struct RTLHStack<Content: View>: View {
    @Environment(\.layoutDirection) var direction
    let content: Content

    init(@ViewBuilder content: () -> Content) {
        self.content = content()
    }

    var body: some View {
        HStack {
            if direction == .rightToLeft {
                Spacer()
                content
            } else {
                content
                Spacer()
            }
        }
    }
}

RTLLayoutHelper (UIKit)

final class RTLLayoutHelper {
    /// Uses traitCollection where a view is available — fall back to UIApplication only when not.
    static func isRTL(in view: UIView) -> Bool {
        view.effectiveUserInterfaceLayoutDirection == .rightToLeft
    }

    /// App-level check — use only outside of view/layout context.
    static var isRTLApp: Bool {
        UIApplication.shared.userInterfaceLayoutDirection == .rightToLeft
    }

    static func mirrorTransform(in view: UIView) -> CGAffineTransform {
        isRTL(in: view) ? CGAffineTransform(scaleX: -1, y: 1) : .identity
    }

    static func directionalX(_ value: CGFloat, in view: UIView) -> CGFloat {
        isRTL(in: view) ? -value : value
    }
}

BiDi string helpers

extension String {
    var ltrIsolated: String { "\u{2066}\(self)\u{2069}" }  // embed LTR in RTL text
    var rtlIsolated: String { "\u{2067}\(self)\u{2069}" }  // embed RTL in LTR text
}

// Locale-aware number/date formatting
let price = 1234.5.formatted(.number.locale(.current))
let date  = Date.now.formatted(.dateTime.locale(.current))
let currency = 250.0.formatted(.currency(code: "SAR").locale(.current))  // iOS 15+

Reference Files

FileWhen to Read
Documentation/SwiftUI-RTL.mdSwiftUI layouts, modifiers, transitions, lists
Documentation/UIKit-RTL.mdUIKit constraints, cells, nav, Core Graphics
Documentation/BiDi-Text.mdBiDi text, formatters, String Catalogs
Documentation/Testing-RTL.mdSimulator setup, XCTest, snapshots, QA checklist

Output Format

When generating RTL integration code:

  1. Use native UIKit/SwiftUI APIs — no external dependencies required
  2. Show before/after for any fixes
  3. Comment RTL-specific decisions with // RTL:
  4. Flag intentionally non-flipping views with // RTL: intentionally LTR
  5. Include a test snippet for non-trivial RTL behavior
  6. Wrap Swift 5.9+ features in #if swift(>=5.9) / #else with a fallback
  7. Wrap iOS 15+ APIs with @available(iOS 15, *) and a NumberFormatter fallback

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Security

skillguard-hardened

Security guard for OpenClaw skills, developed and maintained by rose北港(小红帽 / 猫猫帽帽). Audits installed or incoming skills with local rules plus Zenmux AI intent review, then recommends pass, warn, block, or quarantine.

Archived SourceRecently Updated
Security

ai-workflow-red-team-lite

对 AI 自动化流程做轻量红队演练,聚焦误用路径、边界失败和数据泄露风险。;use for red-team, ai, workflow workflows;do not use for 输出可直接滥用的攻击脚本, 帮助破坏系统.

Archived SourceRecently Updated
Security

social-vault

社交平台账号凭证管理器。提供登录态获取、AES-256-GCM 加密存储、定时健康监测和自动续期。Use when managing social media account credentials, importing cookies, checking login status, or automating session refresh. Also covers platform adapter creation and browser fingerprint management.

Archived SourceRecently Updated
Security

openclaw360

Runtime security skill for AI agents — prompt injection detection, tool call authorization, sensitive data leak prevention, skill security scanning, and one-click backup & restore

Archived SourceRecently Updated