react-native-advanced-text 0.2.12 → 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,6 +15,7 @@ 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
@@ -40,7 +41,8 @@ class AdvancedTextView : TextView {
40
41
  private var textColor: String = "#000000"
41
42
  private var fontSize: Float = 16f
42
43
  private var fontWeight: String = "normal"
43
- private var textAlign: String = "left"
44
+ // "" = unset: natural alignment (start of the text's own direction).
45
+ private var textAlign: String = ""
44
46
  private var fontFamily: String = "sans-serif"
45
47
  private var lineHeightMultiplier: Float = 1.0f
46
48
  // Value from JS, in dp/points (0 = unset). Converted to em for TextView.
@@ -150,10 +152,24 @@ class AdvancedTextView : TextView {
150
152
  fun setAdvancedTextAlign(align: String) {
151
153
  if (textAlign == align) return
152
154
  textAlign = align
153
- when (align) {
154
- "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
+ }
155
172
  "center" -> textAlignment = View.TEXT_ALIGNMENT_CENTER
156
- "right" -> textAlignment = View.TEXT_ALIGNMENT_TEXT_END
157
173
  else -> textAlignment = View.TEXT_ALIGNMENT_TEXT_START
158
174
  }
159
175
  }
@@ -272,12 +288,7 @@ class AdvancedTextView : TextView {
272
288
  )
273
289
  }
274
290
 
275
- textAlignment = when (textAlign) {
276
- "left" -> View.TEXT_ALIGNMENT_TEXT_START
277
- "center" -> View.TEXT_ALIGNMENT_CENTER
278
- "right" -> View.TEXT_ALIGNMENT_TEXT_END
279
- else -> View.TEXT_ALIGNMENT_TEXT_START
280
- }
291
+ applyTextAlign()
281
292
 
282
293
  setTextSize(fontSize)
283
294
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-advanced-text",
3
- "version": "0.2.12",
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",