@glpecile/norph 0.1.0 → 0.1.1
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/package.json +1 -1
- package/src/index.tsx +29 -26
package/package.json
CHANGED
package/src/index.tsx
CHANGED
|
@@ -252,31 +252,30 @@ export function MorphText({ children, className, style, numberOfLines }: MorphTe
|
|
|
252
252
|
}
|
|
253
253
|
};
|
|
254
254
|
|
|
255
|
+
// One line at rest too, so a morph never unwraps the text. While the glyphs
|
|
256
|
+
// move, a copy of it in the sizer is the reader, so the box keeps its baseline.
|
|
257
|
+
const label = (
|
|
258
|
+
<Text className={className} style={[style, RESET, motion && styles.reader]} numberOfLines={1}>
|
|
259
|
+
{shown.text}
|
|
260
|
+
</Text>
|
|
261
|
+
);
|
|
262
|
+
|
|
255
263
|
return (
|
|
256
264
|
<View className={className} style={style}>
|
|
257
265
|
{motion ? (
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
{shown.text}
|
|
272
|
-
</Text>
|
|
273
|
-
</>
|
|
274
|
-
) : (
|
|
275
|
-
// One line at rest too, so a morph never unwraps the text.
|
|
276
|
-
<Text className={className} style={[style, RESET]} numberOfLines={1}>
|
|
277
|
-
{shown.text}
|
|
278
|
-
</Text>
|
|
279
|
-
)}
|
|
266
|
+
<Sizer width={motion.width} height={motion.height}>
|
|
267
|
+
{label}
|
|
268
|
+
{motion.glyphs.map((glyph) => (
|
|
269
|
+
<GlyphView
|
|
270
|
+
key={glyph.key}
|
|
271
|
+
glyph={glyph}
|
|
272
|
+
height={motion.height}
|
|
273
|
+
className={className}
|
|
274
|
+
style={style}
|
|
275
|
+
/>
|
|
276
|
+
))}
|
|
277
|
+
</Sizer>
|
|
278
|
+
) : label}
|
|
280
279
|
{pending ? (
|
|
281
280
|
<View key={text} style={styles.measure} aria-hidden>
|
|
282
281
|
{(['before', 'after'] as const).map((row) => (
|
|
@@ -302,7 +301,7 @@ export function MorphText({ children, className, style, numberOfLines }: MorphTe
|
|
|
302
301
|
function Sizer({ width, height, children }: { width: SharedValue<number>; height: number; children: ReactNode }) {
|
|
303
302
|
const animated = useAnimatedStyle(() => ({ width: width.value }));
|
|
304
303
|
return (
|
|
305
|
-
<Animated.View
|
|
304
|
+
<Animated.View style={[{ height }, animated]}>
|
|
306
305
|
{children}
|
|
307
306
|
</Animated.View>
|
|
308
307
|
);
|
|
@@ -329,7 +328,7 @@ function GlyphView({
|
|
|
329
328
|
}));
|
|
330
329
|
return (
|
|
331
330
|
// One spare point of width, so rounding never wraps the glyph.
|
|
332
|
-
<Animated.View style={[styles.glyph, { width: width + 1, height }, rolls && styles.slot, outer]}>
|
|
331
|
+
<Animated.View aria-hidden style={[styles.glyph, { width: width + 1, height }, rolls && styles.slot, outer]}>
|
|
333
332
|
<Animated.View style={inner}>
|
|
334
333
|
<Text className={className} style={[style, RESET]}>
|
|
335
334
|
{string}
|
|
@@ -366,8 +365,12 @@ const styles = StyleSheet.create({
|
|
|
366
365
|
glyph: { position: 'absolute', left: 0, top: 0 },
|
|
367
366
|
// A rolling digit slides a full line, so its slot clips it.
|
|
368
367
|
slot: { overflow: 'hidden' },
|
|
369
|
-
// The whole string once
|
|
370
|
-
|
|
368
|
+
// The whole string once, unseen, while the glyphs move. Screen readers read
|
|
369
|
+
// it, and it is the box's only text in the layout flow, so it gives the box
|
|
370
|
+
// the baseline the text at rest has. Not `transparent`: Android reads that
|
|
371
|
+
// value as no color and draws the text in the default one. A shadow and an
|
|
372
|
+
// underline keep their own color, so they go too.
|
|
373
|
+
reader: { color: '#00000001', textShadowRadius: 0, textShadowOffset: { width: 0, height: 0 }, textDecorationLine: 'none' },
|
|
371
374
|
// Lays both rows out unconstrained and unseen; the wide row never wraps a word.
|
|
372
375
|
measure: { position: 'absolute', width: 0, height: 0, overflow: 'hidden' },
|
|
373
376
|
row: { position: 'absolute', top: 0, left: 0, width: 10000, flexDirection: 'row', alignItems: 'flex-start' },
|