react-native-laminar 1.0.2 → 1.2.0
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/README.md +38 -1
- package/lib/commonjs/declarations.d.js +4 -0
- package/lib/commonjs/declarations.d.js.map +1 -0
- package/lib/commonjs/index.js +9 -2
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/view/glyph-run.js +16 -2
- package/lib/commonjs/view/glyph-run.js.map +1 -1
- package/lib/commonjs/view/morph-viewport.js +29 -3
- package/lib/commonjs/view/morph-viewport.js.map +1 -1
- package/lib/commonjs/view/number-lane.js +4 -1
- package/lib/commonjs/view/number-lane.js.map +1 -1
- package/lib/commonjs/view/number-run.js +17 -3
- package/lib/commonjs/view/number-run.js.map +1 -1
- package/lib/commonjs/view/text-run.js +6 -2
- package/lib/commonjs/view/text-run.js.map +1 -1
- package/lib/module/declarations.d.js +4 -0
- package/lib/module/declarations.d.js.map +1 -0
- package/lib/module/index.js +9 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/view/glyph-run.js +16 -2
- package/lib/module/view/glyph-run.js.map +1 -1
- package/lib/module/view/morph-viewport.js +29 -3
- package/lib/module/view/morph-viewport.js.map +1 -1
- package/lib/module/view/number-lane.js +4 -1
- package/lib/module/view/number-lane.js.map +1 -1
- package/lib/module/view/number-run.js +17 -3
- package/lib/module/view/number-run.js.map +1 -1
- package/lib/module/view/text-run.js +6 -2
- package/lib/module/view/text-run.js.map +1 -1
- package/lib/typescript/commonjs/index.d.ts +1 -1
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/types.d.ts +3 -0
- package/lib/typescript/commonjs/types.d.ts.map +1 -1
- package/lib/typescript/commonjs/view/glyph-run.d.ts +4 -2
- package/lib/typescript/commonjs/view/glyph-run.d.ts.map +1 -1
- package/lib/typescript/commonjs/view/morph-viewport.d.ts +3 -1
- package/lib/typescript/commonjs/view/morph-viewport.d.ts.map +1 -1
- package/lib/typescript/commonjs/view/number-lane.d.ts +2 -1
- package/lib/typescript/commonjs/view/number-lane.d.ts.map +1 -1
- package/lib/typescript/commonjs/view/number-run.d.ts +4 -2
- package/lib/typescript/commonjs/view/number-run.d.ts.map +1 -1
- package/lib/typescript/commonjs/view/text-run.d.ts +4 -2
- package/lib/typescript/commonjs/view/text-run.d.ts.map +1 -1
- package/lib/typescript/module/index.d.ts +1 -1
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/types.d.ts +3 -0
- package/lib/typescript/module/types.d.ts.map +1 -1
- package/lib/typescript/module/view/glyph-run.d.ts +4 -2
- package/lib/typescript/module/view/glyph-run.d.ts.map +1 -1
- package/lib/typescript/module/view/morph-viewport.d.ts +3 -1
- package/lib/typescript/module/view/morph-viewport.d.ts.map +1 -1
- package/lib/typescript/module/view/number-lane.d.ts +2 -1
- package/lib/typescript/module/view/number-lane.d.ts.map +1 -1
- package/lib/typescript/module/view/number-run.d.ts +4 -2
- package/lib/typescript/module/view/number-run.d.ts.map +1 -1
- package/lib/typescript/module/view/text-run.d.ts +4 -2
- package/lib/typescript/module/view/text-run.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/declarations.d.ts +7 -0
- package/src/index.tsx +8 -0
- package/src/types.ts +3 -0
- package/src/view/glyph-run.tsx +13 -2
- package/src/view/morph-viewport.tsx +25 -3
- package/src/view/number-lane.tsx +4 -1
- package/src/view/number-run.tsx +13 -2
- package/src/view/text-run.tsx +6 -2
|
@@ -2,6 +2,7 @@ import React, { useMemo } from "react";
|
|
|
2
2
|
import type { StyleProp, ViewStyle } from "react-native";
|
|
3
3
|
import { View } from "react-native";
|
|
4
4
|
import Animated from "react-native-reanimated";
|
|
5
|
+
import type { LaminarAlign } from "../types";
|
|
5
6
|
|
|
6
7
|
const shellStyle = {
|
|
7
8
|
position: "relative",
|
|
@@ -29,9 +30,26 @@ const unclippedViewportStyle: ViewStyle = {
|
|
|
29
30
|
overflow: "visible",
|
|
30
31
|
};
|
|
31
32
|
|
|
33
|
+
const fullWidthViewportStyle: ViewStyle = {
|
|
34
|
+
width: "100%",
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const shellAlignStyles: Record<LaminarAlign, ViewStyle> = {
|
|
38
|
+
left: { alignSelf: "flex-start" },
|
|
39
|
+
center: { alignSelf: "center" },
|
|
40
|
+
right: { alignSelf: "flex-end" },
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const viewportAlignStyles: Record<LaminarAlign, ViewStyle> = {
|
|
44
|
+
left: { alignItems: "flex-start" },
|
|
45
|
+
center: { alignItems: "center" },
|
|
46
|
+
right: { alignItems: "flex-end" },
|
|
47
|
+
};
|
|
48
|
+
|
|
32
49
|
type MorphViewportProps = {
|
|
33
50
|
readonly autoSize: boolean;
|
|
34
51
|
readonly clipToBounds: boolean;
|
|
52
|
+
readonly align: LaminarAlign;
|
|
35
53
|
readonly containerStyle?: StyleProp<ViewStyle>;
|
|
36
54
|
readonly animatedWidthStyle?: React.ComponentProps<typeof Animated.View>["style"];
|
|
37
55
|
readonly measurement?: React.ReactNode;
|
|
@@ -42,6 +60,7 @@ export const MorphViewport = React.memo(
|
|
|
42
60
|
({
|
|
43
61
|
autoSize,
|
|
44
62
|
clipToBounds,
|
|
63
|
+
align,
|
|
45
64
|
containerStyle,
|
|
46
65
|
animatedWidthStyle,
|
|
47
66
|
measurement,
|
|
@@ -50,13 +69,14 @@ export const MorphViewport = React.memo(
|
|
|
50
69
|
const resolvedViewportStyle = useMemo(
|
|
51
70
|
() => [
|
|
52
71
|
viewportStyle,
|
|
72
|
+
viewportAlignStyles[align],
|
|
53
73
|
clipToBounds ? clippedViewportStyle : unclippedViewportStyle,
|
|
54
74
|
],
|
|
55
|
-
[clipToBounds]
|
|
75
|
+
[align, clipToBounds]
|
|
56
76
|
);
|
|
57
77
|
|
|
58
78
|
return (
|
|
59
|
-
<View style={[shellStyle, containerStyle]}>
|
|
79
|
+
<View style={[shellStyle, shellAlignStyles[align], containerStyle]}>
|
|
60
80
|
{autoSize ? (
|
|
61
81
|
<>
|
|
62
82
|
<View
|
|
@@ -73,7 +93,9 @@ export const MorphViewport = React.memo(
|
|
|
73
93
|
</Animated.View>
|
|
74
94
|
</>
|
|
75
95
|
) : (
|
|
76
|
-
<View style={resolvedViewportStyle}>
|
|
96
|
+
<View style={[resolvedViewportStyle, fullWidthViewportStyle]}>
|
|
97
|
+
{children}
|
|
98
|
+
</View>
|
|
77
99
|
)}
|
|
78
100
|
</View>
|
|
79
101
|
);
|
package/src/view/number-lane.tsx
CHANGED
|
@@ -30,6 +30,7 @@ type NumberLaneProps = {
|
|
|
30
30
|
readonly travelDistance: number;
|
|
31
31
|
readonly motionRecipe: MotionRecipe;
|
|
32
32
|
readonly textStyle?: StyleProp<TextStyle>;
|
|
33
|
+
readonly className?: string;
|
|
33
34
|
};
|
|
34
35
|
|
|
35
36
|
export const NumberLane = React.memo(
|
|
@@ -43,6 +44,7 @@ export const NumberLane = React.memo(
|
|
|
43
44
|
travelDistance,
|
|
44
45
|
motionRecipe,
|
|
45
46
|
textStyle,
|
|
47
|
+
className,
|
|
46
48
|
}: NumberLaneProps) => {
|
|
47
49
|
const usesDigitTravel = isAsciiDigit(unit);
|
|
48
50
|
const verticalOffset =
|
|
@@ -97,7 +99,7 @@ export const NumberLane = React.memo(
|
|
|
97
99
|
);
|
|
98
100
|
|
|
99
101
|
if (isLead) {
|
|
100
|
-
return <Text style={textStyle}>{unit}</Text>;
|
|
102
|
+
return <Text style={textStyle} className={className}>{unit}</Text>;
|
|
101
103
|
}
|
|
102
104
|
|
|
103
105
|
return (
|
|
@@ -117,6 +119,7 @@ export const NumberLane = React.memo(
|
|
|
117
119
|
entering={hasAnimated ? enterTransition : undefined}
|
|
118
120
|
exiting={exitTransition}
|
|
119
121
|
style={[textStyle, laneTokenStyle]}
|
|
122
|
+
className={className}
|
|
120
123
|
>
|
|
121
124
|
{unit}
|
|
122
125
|
</Animated.Text>
|
package/src/view/number-run.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useMemo, useRef } from "react";
|
|
2
2
|
import { type StyleProp, type TextStyle, View } from "react-native";
|
|
3
3
|
import { useNumericLanes } from "../hooks/use-numeric-lanes";
|
|
4
|
-
import type { MotionRecipe } from "../types";
|
|
4
|
+
import type { LaminarAlign, MotionRecipe } from "../types";
|
|
5
5
|
import { NumberLane } from "./number-lane";
|
|
6
6
|
|
|
7
7
|
const rowStyle = {
|
|
@@ -10,21 +10,31 @@ const rowStyle = {
|
|
|
10
10
|
alignSelf: "flex-start",
|
|
11
11
|
} as const;
|
|
12
12
|
|
|
13
|
+
const rowAlignStyles = {
|
|
14
|
+
left: { alignSelf: "flex-start" },
|
|
15
|
+
center: { alignSelf: "center" },
|
|
16
|
+
right: { alignSelf: "flex-end" },
|
|
17
|
+
} as const;
|
|
18
|
+
|
|
13
19
|
type NumberRunProps = {
|
|
14
20
|
readonly value: string;
|
|
15
21
|
readonly motionRecipe: MotionRecipe;
|
|
22
|
+
readonly align: LaminarAlign;
|
|
16
23
|
readonly fontSize?: number;
|
|
17
24
|
readonly textStyle?: StyleProp<TextStyle>;
|
|
18
25
|
readonly staggerMs: number;
|
|
26
|
+
readonly className?: string;
|
|
19
27
|
};
|
|
20
28
|
|
|
21
29
|
export const NumberRun = React.memo(
|
|
22
30
|
({
|
|
23
31
|
value,
|
|
24
32
|
motionRecipe,
|
|
33
|
+
align,
|
|
25
34
|
fontSize,
|
|
26
35
|
textStyle,
|
|
27
36
|
staggerMs,
|
|
37
|
+
className,
|
|
28
38
|
}: Readonly<NumberRunProps>) => {
|
|
29
39
|
const { units, laneKeys, direction, leadLength } = useNumericLanes(value);
|
|
30
40
|
const lastValueRef = useRef(value);
|
|
@@ -43,7 +53,7 @@ export const NumberRun = React.memo(
|
|
|
43
53
|
const hasAnimated = hasAnimatedRef.current;
|
|
44
54
|
|
|
45
55
|
return (
|
|
46
|
-
<View style={rowStyle}>
|
|
56
|
+
<View style={[rowStyle, rowAlignStyles[align]]}>
|
|
47
57
|
{units.map((unit, index) => {
|
|
48
58
|
const inLead = index < leadLength;
|
|
49
59
|
const laneKey = inLead
|
|
@@ -62,6 +72,7 @@ export const NumberRun = React.memo(
|
|
|
62
72
|
travelDistance={travelDistance}
|
|
63
73
|
motionRecipe={motionRecipe}
|
|
64
74
|
textStyle={textStyle}
|
|
75
|
+
className={className}
|
|
65
76
|
/>
|
|
66
77
|
);
|
|
67
78
|
})}
|
package/src/view/text-run.tsx
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import React, { useId, useRef } from "react";
|
|
2
2
|
import type { StyleProp, TextStyle } from "react-native";
|
|
3
3
|
import { useTextGlyphs } from "../hooks/use-text-glyphs";
|
|
4
|
-
import type { MotionRecipe } from "../types";
|
|
4
|
+
import type { LaminarAlign, MotionRecipe } from "../types";
|
|
5
5
|
import { GlyphRun } from "./glyph-run";
|
|
6
6
|
|
|
7
7
|
type TextRunProps = {
|
|
8
8
|
readonly value: string;
|
|
9
9
|
readonly motionRecipe: MotionRecipe;
|
|
10
|
+
readonly align: LaminarAlign;
|
|
10
11
|
readonly textStyle?: StyleProp<TextStyle>;
|
|
12
|
+
readonly className?: string;
|
|
11
13
|
};
|
|
12
14
|
|
|
13
15
|
export const TextRun = React.memo(
|
|
14
|
-
({ value, motionRecipe, textStyle }: TextRunProps) => {
|
|
16
|
+
({ value, motionRecipe, align, textStyle, className }: TextRunProps) => {
|
|
15
17
|
// namespace ids per instance so repeated strings do not collide
|
|
16
18
|
const scopeId = useId();
|
|
17
19
|
const glyphs = useTextGlyphs(value, scopeId);
|
|
@@ -31,7 +33,9 @@ export const TextRun = React.memo(
|
|
|
31
33
|
hasAnimatedRef.current ? motionRecipe.enterTransition : undefined
|
|
32
34
|
}
|
|
33
35
|
exitTransition={motionRecipe.exitTransition}
|
|
36
|
+
align={align}
|
|
34
37
|
textStyle={textStyle}
|
|
38
|
+
className={className}
|
|
35
39
|
/>
|
|
36
40
|
);
|
|
37
41
|
}
|