react-native-highlight-text-view 0.1.31 → 0.1.32
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.
|
@@ -84,7 +84,7 @@ class HighlightTextView : AppCompatEditText {
|
|
|
84
84
|
private fun init() {
|
|
85
85
|
setBackgroundColor(Color.TRANSPARENT)
|
|
86
86
|
setTextSize(TypedValue.COMPLEX_UNIT_SP, 32f)
|
|
87
|
-
gravity = Gravity.
|
|
87
|
+
gravity = Gravity.START or Gravity.CENTER_VERTICAL
|
|
88
88
|
setPadding(20, 20, 20, 20)
|
|
89
89
|
textColorValue = currentTextColor
|
|
90
90
|
|
|
@@ -242,39 +242,131 @@ class HighlightTextView : AppCompatEditText {
|
|
|
242
242
|
val isFirstLineOfParagraph = line == 0 || isLineEmpty(text, layout, line - 1)
|
|
243
243
|
val isLastLineOfParagraph = line == layout.lineCount - 1 || isLineEmpty(text, layout, line + 1)
|
|
244
244
|
|
|
245
|
+
// Detect text alignment from view's gravity
|
|
246
|
+
val horizontalGravity = gravity and Gravity.HORIZONTAL_GRAVITY_MASK
|
|
247
|
+
val isLeftAligned = horizontalGravity == Gravity.START || horizontalGravity == Gravity.LEFT
|
|
248
|
+
val isRightAligned = horizontalGravity == Gravity.END || horizontalGravity == Gravity.RIGHT
|
|
249
|
+
val isCenterAligned = horizontalGravity == Gravity.CENTER_HORIZONTAL
|
|
250
|
+
|
|
245
251
|
var tl = 0f
|
|
246
252
|
var tr = 0f
|
|
247
253
|
var br = 0f
|
|
248
254
|
var bl = 0f
|
|
249
255
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
256
|
+
when {
|
|
257
|
+
isLeftAligned -> {
|
|
258
|
+
// LEFT ALIGNMENT (default behavior)
|
|
259
|
+
// Left Edge Logic
|
|
260
|
+
if (!hasLeftNeighbor) {
|
|
261
|
+
// Top-Left: Round if first line of paragraph
|
|
262
|
+
tl = if (isFirstLineOfParagraph) radius else 0f
|
|
263
|
+
// Bottom-Left: Round if last line of paragraph
|
|
264
|
+
bl = if (isLastLineOfParagraph) radius else 0f
|
|
265
|
+
}
|
|
257
266
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
267
|
+
// Right Edge Logic
|
|
268
|
+
if (!hasRightNeighbor) {
|
|
269
|
+
val currentLineWidth = layout.getLineMax(line)
|
|
270
|
+
|
|
271
|
+
// Top-Right
|
|
272
|
+
if (isFirstLineOfParagraph) {
|
|
273
|
+
tr = radius
|
|
274
|
+
} else {
|
|
275
|
+
val prevLineWidth = layout.getLineMax(line - 1)
|
|
276
|
+
// Round Top-Right if we stick out further than the line above
|
|
277
|
+
tr = if (currentLineWidth > prevLineWidth) radius else 0f
|
|
278
|
+
}
|
|
261
279
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
280
|
+
// Bottom-Right
|
|
281
|
+
if (isLastLineOfParagraph) {
|
|
282
|
+
br = radius
|
|
283
|
+
} else {
|
|
284
|
+
val nextLineWidth = layout.getLineMax(line + 1)
|
|
285
|
+
// Round Bottom-Right if we overhang the line below
|
|
286
|
+
br = if (currentLineWidth > nextLineWidth) radius else 0f
|
|
287
|
+
}
|
|
288
|
+
}
|
|
269
289
|
}
|
|
290
|
+
|
|
291
|
+
isRightAligned -> {
|
|
292
|
+
// RIGHT ALIGNMENT (mirror of left alignment)
|
|
293
|
+
// Right Edge Logic
|
|
294
|
+
if (!hasRightNeighbor) {
|
|
295
|
+
// Top-Right: Round if first line of paragraph
|
|
296
|
+
tr = if (isFirstLineOfParagraph) radius else 0f
|
|
297
|
+
// Bottom-Right: Round if last line of paragraph
|
|
298
|
+
br = if (isLastLineOfParagraph) radius else 0f
|
|
299
|
+
}
|
|
270
300
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
301
|
+
// Left Edge Logic
|
|
302
|
+
if (!hasLeftNeighbor) {
|
|
303
|
+
val currentLineWidth = layout.getLineMax(line)
|
|
304
|
+
|
|
305
|
+
// Top-Left
|
|
306
|
+
if (isFirstLineOfParagraph) {
|
|
307
|
+
tl = radius
|
|
308
|
+
} else {
|
|
309
|
+
val prevLineWidth = layout.getLineMax(line - 1)
|
|
310
|
+
// Round Top-Left if we stick out further than the line above
|
|
311
|
+
tl = if (currentLineWidth > prevLineWidth) radius else 0f
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// Bottom-Left
|
|
315
|
+
if (isLastLineOfParagraph) {
|
|
316
|
+
bl = radius
|
|
317
|
+
} else {
|
|
318
|
+
val nextLineWidth = layout.getLineMax(line + 1)
|
|
319
|
+
// Round Bottom-Left if we overhang the line below
|
|
320
|
+
bl = if (currentLineWidth > nextLineWidth) radius else 0f
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
isCenterAligned -> {
|
|
326
|
+
// CENTER ALIGNMENT
|
|
327
|
+
val currentLineWidth = layout.getLineMax(line)
|
|
328
|
+
|
|
329
|
+
// Left Edge Logic
|
|
330
|
+
if (!hasLeftNeighbor) {
|
|
331
|
+
// Top-Left
|
|
332
|
+
if (isFirstLineOfParagraph) {
|
|
333
|
+
tl = radius
|
|
334
|
+
} else {
|
|
335
|
+
val prevLineWidth = layout.getLineMax(line - 1)
|
|
336
|
+
// Round Top-Left if we stick out further than the line above
|
|
337
|
+
tl = if (currentLineWidth > prevLineWidth) radius else 0f
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// Bottom-Left
|
|
341
|
+
if (isLastLineOfParagraph) {
|
|
342
|
+
bl = radius
|
|
343
|
+
} else {
|
|
344
|
+
val nextLineWidth = layout.getLineMax(line + 1)
|
|
345
|
+
// Round Bottom-Left if we overhang the line below
|
|
346
|
+
bl = if (currentLineWidth > nextLineWidth) radius else 0f
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// Right Edge Logic
|
|
351
|
+
if (!hasRightNeighbor) {
|
|
352
|
+
// Top-Right
|
|
353
|
+
if (isFirstLineOfParagraph) {
|
|
354
|
+
tr = radius
|
|
355
|
+
} else {
|
|
356
|
+
val prevLineWidth = layout.getLineMax(line - 1)
|
|
357
|
+
// Round Top-Right if we stick out further than the line above
|
|
358
|
+
tr = if (currentLineWidth > prevLineWidth) radius else 0f
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// Bottom-Right
|
|
362
|
+
if (isLastLineOfParagraph) {
|
|
363
|
+
br = radius
|
|
364
|
+
} else {
|
|
365
|
+
val nextLineWidth = layout.getLineMax(line + 1)
|
|
366
|
+
// Round Bottom-Right if we overhang the line below
|
|
367
|
+
br = if (currentLineWidth > nextLineWidth) radius else 0f
|
|
368
|
+
}
|
|
369
|
+
}
|
|
278
370
|
}
|
|
279
371
|
}
|
|
280
372
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-highlight-text-view",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.32",
|
|
4
4
|
"description": "A native text input for React Native that supports inline text highlighting",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|