react-native-advanced-text 0.2.11 → 0.2.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,10 +15,12 @@ import android.text.style.ClickableSpan
15
15
  import android.util.AttributeSet
16
16
  import android.util.Log
17
17
  import android.view.ActionMode
18
+ import android.view.Gravity
18
19
  import android.view.Menu
19
20
  import android.view.MenuItem
20
21
  import android.view.View
21
22
  import android.view.MotionEvent
23
+ import android.view.accessibility.AccessibilityNodeInfo
22
24
  import android.widget.TextView
23
25
  import com.facebook.react.bridge.Arguments
24
26
  import com.facebook.react.bridge.ReactContext
@@ -39,7 +41,8 @@ class AdvancedTextView : TextView {
39
41
  private var textColor: String = "#000000"
40
42
  private var fontSize: Float = 16f
41
43
  private var fontWeight: String = "normal"
42
- private var textAlign: String = "left"
44
+ // "" = unset: natural alignment (start of the text's own direction).
45
+ private var textAlign: String = ""
43
46
  private var fontFamily: String = "sans-serif"
44
47
  private var lineHeightMultiplier: Float = 1.0f
45
48
  // Value from JS, in dp/points (0 = unset). Converted to em for TextView.
@@ -149,10 +152,24 @@ class AdvancedTextView : TextView {
149
152
  fun setAdvancedTextAlign(align: String) {
150
153
  if (textAlign == align) return
151
154
  textAlign = align
152
- when (align) {
153
- "left" -> textAlignment = View.TEXT_ALIGNMENT_TEXT_START
155
+ applyTextAlign()
156
+ }
157
+
158
+ // "left"/"right" are absolute edges, as on iOS. TEXT_START/TEXT_END follow
159
+ // the paragraph's direction, so RTL text (Arabic) with "right" would land
160
+ // on the left. Only TEXT_ALIGNMENT_GRAVITY with Gravity.LEFT/RIGHT is absolute.
161
+ private fun applyTextAlign() {
162
+ val vertical = gravity and Gravity.VERTICAL_GRAVITY_MASK
163
+ when (textAlign) {
164
+ "left" -> {
165
+ gravity = vertical or Gravity.LEFT
166
+ textAlignment = View.TEXT_ALIGNMENT_GRAVITY
167
+ }
168
+ "right" -> {
169
+ gravity = vertical or Gravity.RIGHT
170
+ textAlignment = View.TEXT_ALIGNMENT_GRAVITY
171
+ }
154
172
  "center" -> textAlignment = View.TEXT_ALIGNMENT_CENTER
155
- "right" -> textAlignment = View.TEXT_ALIGNMENT_TEXT_END
156
173
  else -> textAlignment = View.TEXT_ALIGNMENT_TEXT_START
157
174
  }
158
175
  }
@@ -271,12 +288,7 @@ class AdvancedTextView : TextView {
271
288
  )
272
289
  }
273
290
 
274
- textAlignment = when (textAlign) {
275
- "left" -> View.TEXT_ALIGNMENT_TEXT_START
276
- "center" -> View.TEXT_ALIGNMENT_CENTER
277
- "right" -> View.TEXT_ALIGNMENT_TEXT_END
278
- else -> View.TEXT_ALIGNMENT_TEXT_START
279
- }
291
+ applyTextAlign()
280
292
 
281
293
  setTextSize(fontSize)
282
294
 
@@ -310,6 +322,15 @@ class AdvancedTextView : TextView {
310
322
  Log.d(TAG, "Text updated with ${wordPositions.size} spans")
311
323
  }
312
324
 
325
+ // Every word is a ClickableSpan so a tap can report it, but TalkBack treats
326
+ // each span as a link: it reads the text one word at a time and lists every
327
+ // word under Actions. Plain text keeps it reading as prose; granularity
328
+ // navigation still works since the characters are identical.
329
+ override fun onInitializeAccessibilityNodeInfo(info: AccessibilityNodeInfo) {
330
+ super.onInitializeAccessibilityNodeInfo(info)
331
+ info.text = text?.toString()
332
+ }
333
+
313
334
  override fun onDraw(canvas: Canvas) {
314
335
  drawHighlightedWordBackgrounds(canvas)
315
336
  super.onDraw(canvas)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-advanced-text",
3
- "version": "0.2.11",
3
+ "version": "0.2.13",
4
4
  "description": " Advanced text component for React Native with custom select options.",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",