@whetware/react-native-stroke-text 0.0.8 → 0.0.9
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.
|
@@ -74,22 +74,18 @@ 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
|
|
78
|
-
|
|
79
|
-
|
|
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()
|
|
81
88
|
|
|
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
89
|
canvas.translate(compoundPaddingLeft.toFloat(), extendedPaddingTop.toFloat())
|
|
94
90
|
canvas.translate(-scrollX.toFloat(), -scrollY.toFloat())
|
|
95
91
|
|
|
@@ -104,12 +100,6 @@ internal class StrokeTextView(context: ThemedReactContext) : TextView(context) {
|
|
|
104
100
|
textPaint.color = strokeColor
|
|
105
101
|
layout.draw(canvas)
|
|
106
102
|
|
|
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
103
|
canvas.restoreToCount(saveCount)
|
|
114
104
|
|
|
115
105
|
textPaint.style = prevStyle
|
|
@@ -120,6 +110,8 @@ internal class StrokeTextView(context: ThemedReactContext) : TextView(context) {
|
|
|
120
110
|
textPaint.isUnderlineText = prevUnderline
|
|
121
111
|
textPaint.isStrikeThruText = prevStrike
|
|
122
112
|
}
|
|
113
|
+
|
|
114
|
+
super.onDraw(canvas)
|
|
123
115
|
}
|
|
124
116
|
|
|
125
117
|
private fun applyProps() {
|
package/lib/StrokeText.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { StyleSheet, Text, View } from 'react-native';
|
|
2
|
+
import { I18nManager, StyleSheet, Text, View, } from 'react-native';
|
|
3
3
|
import { callback, getHostComponent } from 'react-native-nitro-modules';
|
|
4
4
|
import StrokeTextViewConfig from '../nitrogen/generated/shared/json/StrokeTextViewConfig.json';
|
|
5
5
|
const NativeStrokeTextView = getHostComponent('StrokeTextView', () => StrokeTextViewConfig);
|
|
@@ -71,12 +71,32 @@ export function StrokeText({ text, children, style, hybridRef, ...rest }) {
|
|
|
71
71
|
const baseRight = firstNumber(paddingRight, stylePaddingRight, paddingHorizontal, stylePaddingHorizontal, padding, stylePadding) ?? 0;
|
|
72
72
|
const baseBottom = firstNumber(paddingBottom, stylePaddingBottom, paddingVertical, stylePaddingVertical, padding, stylePadding) ?? 0;
|
|
73
73
|
const baseLeft = firstNumber(paddingLeft, stylePaddingLeft, paddingHorizontal, stylePaddingHorizontal, padding, stylePadding) ?? 0;
|
|
74
|
+
const baseMarginTop = firstNumber(containerStyle.marginTop, containerStyle.marginVertical, containerStyle.margin) ?? 0;
|
|
75
|
+
const baseMarginRight = firstNumber(containerStyle.marginRight, I18nManager.isRTL ? containerStyle.marginStart : containerStyle.marginEnd, containerStyle.marginHorizontal, containerStyle.margin) ?? 0;
|
|
76
|
+
const baseMarginBottom = firstNumber(containerStyle.marginBottom, containerStyle.marginVertical, containerStyle.margin) ?? 0;
|
|
77
|
+
const baseMarginLeft = firstNumber(containerStyle.marginLeft, I18nManager.isRTL ? containerStyle.marginEnd : containerStyle.marginStart, containerStyle.marginHorizontal, containerStyle.margin) ?? 0;
|
|
78
|
+
const baseMarginStart = toNumber(containerStyle.marginStart);
|
|
79
|
+
const baseMarginEnd = toNumber(containerStyle.marginEnd);
|
|
80
|
+
const strokeInsetMarginStyle = strokeInset === 0
|
|
81
|
+
? null
|
|
82
|
+
: {
|
|
83
|
+
marginTop: baseMarginTop - strokeInset,
|
|
84
|
+
marginRight: baseMarginRight - strokeInset,
|
|
85
|
+
marginBottom: baseMarginBottom - strokeInset,
|
|
86
|
+
marginLeft: baseMarginLeft - strokeInset,
|
|
87
|
+
...(baseMarginStart == null
|
|
88
|
+
? {}
|
|
89
|
+
: { marginStart: baseMarginStart - strokeInset }),
|
|
90
|
+
...(baseMarginEnd == null
|
|
91
|
+
? {}
|
|
92
|
+
: { marginEnd: baseMarginEnd - strokeInset }),
|
|
93
|
+
};
|
|
74
94
|
const effectiveNumberOfLines = nativeProps.numberOfLines != null && nativeProps.numberOfLines > 0
|
|
75
95
|
? nativeProps.numberOfLines
|
|
76
96
|
: undefined;
|
|
77
97
|
const effectiveEllipsizeMode = effectiveNumberOfLines == null
|
|
78
98
|
? undefined
|
|
79
|
-
: nativeProps.ellipsizeMode ?? 'tail';
|
|
99
|
+
: (nativeProps.ellipsizeMode ?? 'tail');
|
|
80
100
|
const mappedTextAlignVerticalFromVerticalAlign = styleVerticalAlign === 'middle'
|
|
81
101
|
? 'center'
|
|
82
102
|
: toTextAlignVertical(styleVerticalAlign);
|
|
@@ -122,28 +142,18 @@ export function StrokeText({ text, children, style, hybridRef, ...rest }) {
|
|
|
122
142
|
effectiveTextTransform,
|
|
123
143
|
effectiveIncludeFontPadding,
|
|
124
144
|
]);
|
|
125
|
-
return (React.createElement(View, { style: [styles.container, containerStyle] },
|
|
145
|
+
return (React.createElement(View, { style: [styles.container, containerStyle, strokeInsetMarginStyle] },
|
|
126
146
|
React.createElement(Text, { accessible: false, pointerEvents: "none", numberOfLines: effectiveNumberOfLines, ellipsizeMode: effectiveEllipsizeMode, allowFontScaling: nativeProps.allowFontScaling, maxFontSizeMultiplier: nativeProps.maxFontSizeMultiplier, style: [
|
|
127
147
|
measurerTextStyle,
|
|
128
148
|
{
|
|
129
|
-
paddingTop: baseTop,
|
|
130
|
-
paddingRight: baseRight,
|
|
131
|
-
paddingBottom: baseBottom,
|
|
132
|
-
paddingLeft: baseLeft,
|
|
149
|
+
paddingTop: baseTop + strokeInset,
|
|
150
|
+
paddingRight: baseRight + strokeInset,
|
|
151
|
+
paddingBottom: baseBottom + strokeInset,
|
|
152
|
+
paddingLeft: baseLeft + strokeInset,
|
|
133
153
|
},
|
|
134
154
|
styles.hiddenText,
|
|
135
155
|
] }, resolvedText),
|
|
136
|
-
React.createElement(NativeStrokeTextView, { ...nativeProps, text: resolvedText, color: effectiveColor, fontSize: effectiveFontSize, fontWeight: effectiveFontWeight, fontFamily: effectiveFontFamily, fontStyle: effectiveFontStyle, lineHeight: effectiveLineHeight, letterSpacing: effectiveLetterSpacing, textAlign: effectiveTextAlign, textAlignVertical: effectiveTextAlignVertical, textDecorationLine: effectiveTextDecorationLine, textTransform: effectiveTextTransform, opacity: nativeProps.opacity ?? toNumber(styleOpacity), includeFontPadding: effectiveIncludeFontPadding, numberOfLines: nativeProps.numberOfLines, ellipsizeMode: effectiveEllipsizeMode, paddingTop: baseTop, paddingRight: baseRight, paddingBottom: baseBottom, paddingLeft: baseLeft, hybridRef: wrappedHybridRef, pointerEvents: "none", style:
|
|
137
|
-
styles.overlay,
|
|
138
|
-
strokeInset === 0
|
|
139
|
-
? null
|
|
140
|
-
: {
|
|
141
|
-
top: -strokeInset,
|
|
142
|
-
right: -strokeInset,
|
|
143
|
-
bottom: -strokeInset,
|
|
144
|
-
left: -strokeInset,
|
|
145
|
-
},
|
|
146
|
-
] })));
|
|
156
|
+
React.createElement(NativeStrokeTextView, { ...nativeProps, text: resolvedText, color: effectiveColor, fontSize: effectiveFontSize, fontWeight: effectiveFontWeight, fontFamily: effectiveFontFamily, fontStyle: effectiveFontStyle, lineHeight: effectiveLineHeight, letterSpacing: effectiveLetterSpacing, textAlign: effectiveTextAlign, textAlignVertical: effectiveTextAlignVertical, textDecorationLine: effectiveTextDecorationLine, textTransform: effectiveTextTransform, opacity: nativeProps.opacity ?? toNumber(styleOpacity), includeFontPadding: effectiveIncludeFontPadding, numberOfLines: nativeProps.numberOfLines, ellipsizeMode: effectiveEllipsizeMode, paddingTop: baseTop, paddingRight: baseRight, paddingBottom: baseBottom, paddingLeft: baseLeft, hybridRef: wrappedHybridRef, pointerEvents: "none", style: styles.overlay })));
|
|
147
157
|
}
|
|
148
158
|
const styles = StyleSheet.create({
|
|
149
159
|
container: {},
|
package/package.json
CHANGED