@whetware/react-native-stroke-text 0.0.8 → 0.0.10

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.
@@ -3,6 +3,7 @@ package com.margelo.nitro.stroketext
3
3
  import android.view.View
4
4
  import com.facebook.jni.HybridData
5
5
  import com.facebook.react.uimanager.ThemedReactContext
6
+ import kotlin.math.ceil
6
7
 
7
8
  class HybridStrokeTextView(context: ThemedReactContext) : HybridStrokeTextViewSpec() {
8
9
  private val strokeTextView = StrokeTextView(context)
@@ -77,12 +78,14 @@ class HybridStrokeTextView(context: ThemedReactContext) : HybridStrokeTextViewSp
77
78
  )
78
79
 
79
80
  strokeTextView.fontSizePx =
80
- StrokeTextView.textToPx(
81
- fontSize ?: 14.0,
82
- resolvedAllowFontScaling,
83
- resolvedMaxFontSizeMultiplier,
84
- displayMetrics,
85
- )
81
+ ceil(
82
+ StrokeTextView.textToPx(
83
+ fontSize ?: 14.0,
84
+ resolvedAllowFontScaling,
85
+ resolvedMaxFontSizeMultiplier,
86
+ displayMetrics,
87
+ ).toDouble()
88
+ ).toFloat()
86
89
  strokeTextView.fontWeight = fontWeight
87
90
  strokeTextView.fontFamily = fontFamily
88
91
  strokeTextView.fontStyle = fontStyle ?: StrokeTextFontStyle.NORMAL
@@ -74,22 +74,20 @@ internal class StrokeTextView(context: ThemedReactContext) : TextView(context) {
74
74
  // Draw stroke behind fill, using TextView's layout so metrics match RN <Text/> as closely as
75
75
  // possible (especially for bold fonts).
76
76
  val layout = layout
77
- if (layout == null || strokeWidthPx <= 0f || strokeColor == Color.TRANSPARENT) {
78
- super.onDraw(canvas)
79
- return
80
- }
77
+ if (layout != null && strokeWidthPx > 0f && strokeColor != Color.TRANSPARENT) {
78
+ val textPaint = paint
79
+ val prevStyle = textPaint.style
80
+ val prevStrokeWidth = textPaint.strokeWidth
81
+ val prevStrokeJoin = textPaint.strokeJoin
82
+ val prevStrokeCap = textPaint.strokeCap
83
+ val prevColor = textPaint.color
84
+ val prevUnderline = textPaint.isUnderlineText
85
+ val prevStrike = textPaint.isStrikeThruText
86
+
87
+ val saveCount = canvas.save()
88
+ val compoundPaddingLeft = compoundPaddingLeft
89
+ val extendedPaddingTop = extendedPaddingTop
81
90
 
82
- val textPaint = paint
83
- val prevStyle = textPaint.style
84
- val prevStrokeWidth = textPaint.strokeWidth
85
- val prevStrokeJoin = textPaint.strokeJoin
86
- val prevStrokeCap = textPaint.strokeCap
87
- val prevColor = textPaint.color
88
- val prevUnderline = textPaint.isUnderlineText
89
- val prevStrike = textPaint.isStrikeThruText
90
-
91
- val saveCount = canvas.save()
92
- try {
93
91
  canvas.translate(compoundPaddingLeft.toFloat(), extendedPaddingTop.toFloat())
94
92
  canvas.translate(-scrollX.toFloat(), -scrollY.toFloat())
95
93
 
@@ -104,12 +102,6 @@ internal class StrokeTextView(context: ThemedReactContext) : TextView(context) {
104
102
  textPaint.color = strokeColor
105
103
  layout.draw(canvas)
106
104
 
107
- textPaint.style = Paint.Style.FILL
108
- textPaint.color = prevColor
109
- textPaint.isUnderlineText = prevUnderline
110
- textPaint.isStrikeThruText = prevStrike
111
- layout.draw(canvas)
112
- } finally {
113
105
  canvas.restoreToCount(saveCount)
114
106
 
115
107
  textPaint.style = prevStyle
@@ -120,6 +112,8 @@ internal class StrokeTextView(context: ThemedReactContext) : TextView(context) {
120
112
  textPaint.isUnderlineText = prevUnderline
121
113
  textPaint.isStrikeThruText = prevStrike
122
114
  }
115
+
116
+ super.onDraw(canvas)
123
117
  }
124
118
 
125
119
  private fun applyProps() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whetware/react-native-stroke-text",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "description": "Stroke/outline text for React Native (New Architecture) on iOS, Android, and Web.",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",