@whetware/react-native-stroke-text 0.0.15 → 0.0.16
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.
package/lib/StrokeText.js
CHANGED
|
@@ -2,6 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { Platform, 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
|
+
import { createNativePropPresenceKey, normalizeNativeOptionalProps, } from './createNativePropPresenceKey';
|
|
5
6
|
import { resolveNativeTextTransform } from './resolveNativeTextTransform';
|
|
6
7
|
const NativeStrokeTextView = getHostComponent('StrokeTextView', () => StrokeTextViewConfig);
|
|
7
8
|
function resolveText(text, children) {
|
|
@@ -122,6 +123,39 @@ export function StrokeText({ text, children, style, hybridRef, ...rest }) {
|
|
|
122
123
|
const nativeOverlayInset = Platform.OS === 'android' && strokeInset > 0 ? strokeInset : 0;
|
|
123
124
|
const nativeOverlayRightInset = nativeOverlayInset > 0 ? nativeOverlayInset * 2 : 0;
|
|
124
125
|
const wrappedHybridRef = React.useMemo(() => (hybridRef ? callback(hybridRef) : undefined), [hybridRef]);
|
|
126
|
+
const nativeOptionalProps = normalizeNativeOptionalProps({
|
|
127
|
+
color: effectiveColor,
|
|
128
|
+
strokeColor: nativeProps.strokeColor,
|
|
129
|
+
strokeWidth,
|
|
130
|
+
fontSize: effectiveFontSize,
|
|
131
|
+
fontWeight: effectiveFontWeight,
|
|
132
|
+
fontFamily: effectiveFontFamily,
|
|
133
|
+
fontStyle: effectiveFontStyle,
|
|
134
|
+
lineHeight: effectiveLineHeight,
|
|
135
|
+
letterSpacing: effectiveLetterSpacing,
|
|
136
|
+
textAlign: effectiveTextAlign,
|
|
137
|
+
textAlignVertical: effectiveTextAlignVertical,
|
|
138
|
+
textDecorationLine: effectiveTextDecorationLine,
|
|
139
|
+
textTransform: nativeTextTransform,
|
|
140
|
+
opacity: nativeProps.opacity ?? toNumber(styleOpacity),
|
|
141
|
+
allowFontScaling: nativeProps.allowFontScaling,
|
|
142
|
+
maxFontSizeMultiplier: nativeProps.maxFontSizeMultiplier,
|
|
143
|
+
includeFontPadding: effectiveIncludeFontPadding,
|
|
144
|
+
numberOfLines: effectiveNumberOfLines ?? 0,
|
|
145
|
+
ellipsizeMode: effectiveEllipsizeMode ?? 'tail',
|
|
146
|
+
padding: undefined,
|
|
147
|
+
paddingVertical: undefined,
|
|
148
|
+
paddingHorizontal: undefined,
|
|
149
|
+
paddingTop: baseTop,
|
|
150
|
+
paddingRight: baseRight,
|
|
151
|
+
paddingBottom: baseBottom,
|
|
152
|
+
paddingLeft: baseLeft,
|
|
153
|
+
hybridRef: wrappedHybridRef,
|
|
154
|
+
});
|
|
155
|
+
// Fabric encodes a removed view prop as null, but Nitro 0.36's optional
|
|
156
|
+
// converter accepts only undefined. Remount the native host when any optional
|
|
157
|
+
// prop changes definedness so Fabric never sends a value-to-null update.
|
|
158
|
+
const nativePropPresenceKey = createNativePropPresenceKey(nativeOptionalProps);
|
|
125
159
|
React.useEffect(() => {
|
|
126
160
|
setMeasuredNativeText(undefined);
|
|
127
161
|
}, [
|
|
@@ -201,7 +235,7 @@ export function StrokeText({ text, children, style, hybridRef, ...rest }) {
|
|
|
201
235
|
},
|
|
202
236
|
styles.hiddenText,
|
|
203
237
|
] }, resolvedText),
|
|
204
|
-
React.createElement(NativeStrokeTextView, {
|
|
238
|
+
React.createElement(NativeStrokeTextView, { key: nativePropPresenceKey, text: nativeText, ...nativeOptionalProps, pointerEvents: "none", style: [
|
|
205
239
|
styles.overlay,
|
|
206
240
|
nativeOverlayInset > 0
|
|
207
241
|
? {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function normalizeNativeOptionalProps(props) {
|
|
2
|
+
return Object.fromEntries(Object.entries(props).map(([propName, value]) => [
|
|
3
|
+
propName,
|
|
4
|
+
value ?? undefined,
|
|
5
|
+
]));
|
|
6
|
+
}
|
|
7
|
+
export function createNativePropPresenceKey(props) {
|
|
8
|
+
return Object.keys(props)
|
|
9
|
+
.sort()
|
|
10
|
+
.map((propName) => (props[propName] == null ? '0' : '1'))
|
|
11
|
+
.join('');
|
|
12
|
+
}
|
package/package.json
CHANGED