APP-2983: Fix RTL post alignment on native (#11600)
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import {describe, expect, it} from '@jest/globals'
|
||||
|
||||
import {isRTLText} from '../text-direction'
|
||||
|
||||
describe('isRTLText', () => {
|
||||
it('recognizes right-to-left text', () => {
|
||||
expect(isRTLText('עברית')).toBe(true)
|
||||
expect(isRTLText('العربية')).toBe(true)
|
||||
})
|
||||
|
||||
it('recognizes left-to-right text', () => {
|
||||
expect(isRTLText('English')).toBe(false)
|
||||
})
|
||||
|
||||
it('uses the first strong directional character', () => {
|
||||
expect(isRTLText(' 123 🦋 עברית English')).toBe(true)
|
||||
expect(isRTLText(' 123 🦋 English עברית')).toBe(false)
|
||||
})
|
||||
|
||||
it('defaults to left-to-right when there are no strong characters', () => {
|
||||
expect(isRTLText('123 🦋 ...')).toBe(false)
|
||||
expect(isRTLText('')).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,17 @@
|
||||
import bidiFactory from 'bidi-js'
|
||||
|
||||
const bidi = bidiFactory()
|
||||
|
||||
/**
|
||||
* Checks the first strong directional character, matching HTML `dir="auto"`.
|
||||
*/
|
||||
export function isRTLText(text: string) {
|
||||
for (const character of text) {
|
||||
const type = bidi.getBidiCharTypeName(character)
|
||||
|
||||
if (type === 'R' || type === 'AL') return true
|
||||
if (type === 'L') return false
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* React Native Web sets `dir="auto"` on root Text elements, so the browser
|
||||
* handles direction detection without JavaScript.
|
||||
*/
|
||||
export function isRTLText(_text: string) {
|
||||
return false
|
||||
}
|
||||
Reference in New Issue
Block a user