@whetware/react-native-stroke-text 0.0.9 → 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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
|
@@ -85,6 +85,8 @@ internal class StrokeTextView(context: ThemedReactContext) : TextView(context) {
|
|
|
85
85
|
val prevStrike = textPaint.isStrikeThruText
|
|
86
86
|
|
|
87
87
|
val saveCount = canvas.save()
|
|
88
|
+
val compoundPaddingLeft = compoundPaddingLeft
|
|
89
|
+
val extendedPaddingTop = extendedPaddingTop
|
|
88
90
|
|
|
89
91
|
canvas.translate(compoundPaddingLeft.toFloat(), extendedPaddingTop.toFloat())
|
|
90
92
|
canvas.translate(-scrollX.toFloat(), -scrollY.toFloat())
|
package/lib/StrokeText.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { 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,32 +71,12 @@ 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
|
-
};
|
|
94
74
|
const effectiveNumberOfLines = nativeProps.numberOfLines != null && nativeProps.numberOfLines > 0
|
|
95
75
|
? nativeProps.numberOfLines
|
|
96
76
|
: undefined;
|
|
97
77
|
const effectiveEllipsizeMode = effectiveNumberOfLines == null
|
|
98
78
|
? undefined
|
|
99
|
-
:
|
|
79
|
+
: nativeProps.ellipsizeMode ?? 'tail';
|
|
100
80
|
const mappedTextAlignVerticalFromVerticalAlign = styleVerticalAlign === 'middle'
|
|
101
81
|
? 'center'
|
|
102
82
|
: toTextAlignVertical(styleVerticalAlign);
|
|
@@ -142,18 +122,28 @@ export function StrokeText({ text, children, style, hybridRef, ...rest }) {
|
|
|
142
122
|
effectiveTextTransform,
|
|
143
123
|
effectiveIncludeFontPadding,
|
|
144
124
|
]);
|
|
145
|
-
return (React.createElement(View, { style: [styles.container, containerStyle
|
|
125
|
+
return (React.createElement(View, { style: [styles.container, containerStyle] },
|
|
146
126
|
React.createElement(Text, { accessible: false, pointerEvents: "none", numberOfLines: effectiveNumberOfLines, ellipsizeMode: effectiveEllipsizeMode, allowFontScaling: nativeProps.allowFontScaling, maxFontSizeMultiplier: nativeProps.maxFontSizeMultiplier, style: [
|
|
147
127
|
measurerTextStyle,
|
|
148
128
|
{
|
|
149
|
-
paddingTop: baseTop
|
|
150
|
-
paddingRight: baseRight
|
|
151
|
-
paddingBottom: baseBottom
|
|
152
|
-
paddingLeft: baseLeft
|
|
129
|
+
paddingTop: baseTop,
|
|
130
|
+
paddingRight: baseRight,
|
|
131
|
+
paddingBottom: baseBottom,
|
|
132
|
+
paddingLeft: baseLeft,
|
|
153
133
|
},
|
|
154
134
|
styles.hiddenText,
|
|
155
135
|
] }, resolvedText),
|
|
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:
|
|
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
|
+
] })));
|
|
157
147
|
}
|
|
158
148
|
const styles = StyleSheet.create({
|
|
159
149
|
container: {},
|
package/package.json
CHANGED