indatastar-styled-autoresizabletext 0.1.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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 InDataStar
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # indatastar-styled-autoresizabletext
2
+ **Text auto-resizes to fit its container in React Native.**
3
+ Highly useful for responsive UI, cards, banners, and dynamic layouts.
4
+
5
+ ## Installation
6
+
7
+
8
+ ```bash
9
+ npm install indatastar-styled-autoresizabletext
10
+ # or
11
+ yarn add indatastar-styled-autoresizabletext
12
+ ```
13
+
14
+
15
+ ## Usage
16
+
17
+
18
+ ```js
19
+ import React from 'react';
20
+ import { View } from 'react-native';
21
+ import { AutoResizeText } from 'indatastar-styled-autoresizabletext';
22
+
23
+ export default function Example() {
24
+ return (
25
+ <View style={{ width: 250, padding: 10, backgroundColor: '#333' }}>
26
+ <AutoResizeText
27
+ text="This is dynamic text that adjusts to fit its container"
28
+ maxFontSize={36}
29
+ minFontSize={12}
30
+ stepSize={0.5}
31
+ numberOfLines={2}
32
+ style={{ color: 'white', fontWeight: 'bold' }}
33
+ />
34
+ </View>
35
+ );
36
+ }
37
+
38
+
39
+ ```
40
+
41
+ ## Props
42
+
43
+ | Prop | Type | Default | Description |
44
+ |-----------------|--------------------|---------|---------------------------------------------------|
45
+ | text | string | "" | Text to display (alternative to children) |
46
+ | maxFontSize | number | 36 | Maximum font size allowed |
47
+ | minFontSize | number | 12 | Minimum font size allowed |
48
+ | stepSize | number | 0.5 | Font resizing step increment/decrement |
49
+ | numberOfLines | number | 1 | Max number of lines before truncation |
50
+ | style | TextStyle | - | Style object passed to Text |
51
+ | ellipsizeMode | `"head" \| "middle" \| "tail"` | "tail" | Truncation mode when text exceeds container width |
52
+
53
+
54
+
55
+ ## Features
56
+ - Automatically resizes text to fit width and number of lines
57
+ - Supports max and min font sizes
58
+ - Smooth step-based resizing
59
+ - Works for single-line and multi-line text
60
+ - Fully customizable styles
61
+ - Supports `text` prop or children
62
+
63
+ ## Contributing
64
+
65
+ - [Development workflow](CONTRIBUTING.md#development-workflow)
66
+ - [Sending a pull request](CONTRIBUTING.md#sending-a-pull-request)
67
+ - [Code of conduct](CODE_OF_CONDUCT.md)
68
+
69
+ ## Tips
70
+
71
+ - Smaller stepSize = smoother resizing, but slightly more computation
72
+ - Set reasonable maxFontSize and minFontSize to prevent overly small or large text
73
+ - Works great for cards, banners, and responsive designs
74
+ - Combine with flex or fixed-width containers for better layout control
75
+
76
+ ## License
77
+
78
+ MIT
79
+
80
+ ---
81
+
82
+ Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+
3
+ import React, { useState, useRef } from 'react';
4
+ import { Animated } from 'react-native';
5
+ import { jsx as _jsx } from "react/jsx-runtime";
6
+ const AutoResizeText = ({
7
+ text,
8
+ children,
9
+ maxFontSize = 36,
10
+ minFontSize = 12,
11
+ stepSize = 0.5,
12
+ numberOfLines = 1,
13
+ style,
14
+ ...rest
15
+ }) => {
16
+ const [fontSize, setFontSize] = useState(maxFontSize);
17
+ const [width, setWidth] = useState(0);
18
+ const [needResize, setNeedResize] = useState(true);
19
+ const animatedFont = useRef(new Animated.Value(maxFontSize)).current;
20
+ const onTextLayout = e => {
21
+ if (!needResize) return;
22
+ const {
23
+ lines
24
+ } = e.nativeEvent;
25
+ if (!lines || lines.length === 0) return;
26
+ let currentFont = fontSize;
27
+ // Use the correct type
28
+ const typedLines = lines;
29
+ let maxLineWidth = Math.max(...typedLines.map(line => line.width));
30
+ while (maxLineWidth > width && currentFont > minFontSize) {
31
+ currentFont = Math.max(currentFont - stepSize, minFontSize);
32
+ maxLineWidth = maxLineWidth * currentFont / fontSize;
33
+ }
34
+ setFontSize(currentFont);
35
+ Animated.timing(animatedFont, {
36
+ toValue: currentFont,
37
+ duration: 150,
38
+ useNativeDriver: false
39
+ }).start();
40
+ setNeedResize(false);
41
+ };
42
+ const onLayout = e => {
43
+ const containerWidth = e.nativeEvent.layout.width;
44
+ if (width !== containerWidth) {
45
+ setWidth(containerWidth);
46
+ setNeedResize(true);
47
+ }
48
+ };
49
+ return /*#__PURE__*/_jsx(Animated.Text, {
50
+ onLayout: onLayout,
51
+ onTextLayout: onTextLayout,
52
+ numberOfLines: numberOfLines,
53
+ ellipsizeMode: "tail",
54
+ style: [style, {
55
+ fontSize: animatedFont
56
+ }],
57
+ ...rest,
58
+ children: text ?? children
59
+ });
60
+ };
61
+ export default AutoResizeText;
62
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","useState","useRef","Animated","jsx","_jsx","AutoResizeText","text","children","maxFontSize","minFontSize","stepSize","numberOfLines","style","rest","fontSize","setFontSize","width","setWidth","needResize","setNeedResize","animatedFont","Value","current","onTextLayout","e","lines","nativeEvent","length","currentFont","typedLines","maxLineWidth","Math","max","map","line","timing","toValue","duration","useNativeDriver","start","onLayout","containerWidth","layout","Text","ellipsizeMode"],"sourceRoot":"../../../src","sources":["AutoResizableText/index.tsx"],"mappings":";;AAAA,OAAOA,KAAK,IAAIC,QAAQ,EAAEC,MAAM,QAAQ,OAAO;AAC/C,SAASC,QAAQ,QAAQ,cAAc;AAAC,SAAAC,GAAA,IAAAC,IAAA;AA6BxC,MAAMC,cAA6C,GAAGA,CAAC;EACrDC,IAAI;EACJC,QAAQ;EACRC,WAAW,GAAG,EAAE;EAChBC,WAAW,GAAG,EAAE;EAChBC,QAAQ,GAAG,GAAG;EACdC,aAAa,GAAG,CAAC;EACjBC,KAAK;EACL,GAAGC;AACL,CAAC,KAAK;EACJ,MAAM,CAACC,QAAQ,EAAEC,WAAW,CAAC,GAAGf,QAAQ,CAACQ,WAAW,CAAC;EACrD,MAAM,CAACQ,KAAK,EAAEC,QAAQ,CAAC,GAAGjB,QAAQ,CAAC,CAAC,CAAC;EACrC,MAAM,CAACkB,UAAU,EAAEC,aAAa,CAAC,GAAGnB,QAAQ,CAAC,IAAI,CAAC;EAClD,MAAMoB,YAAY,GAAGnB,MAAM,CAAC,IAAIC,QAAQ,CAACmB,KAAK,CAACb,WAAW,CAAC,CAAC,CAACc,OAAO;EACtE,MAAMC,YAAY,GAAIC,CAAkB,IAAK;IAC3C,IAAI,CAACN,UAAU,EAAE;IAEjB,MAAM;MAAEO;IAAM,CAAC,GAAGD,CAAC,CAACE,WAAW;IAC/B,IAAI,CAACD,KAAK,IAAIA,KAAK,CAACE,MAAM,KAAK,CAAC,EAAE;IAElC,IAAIC,WAAW,GAAGd,QAAQ;IAC1B;IACA,MAAMe,UAAU,GAAGJ,KAAoC;IACvD,IAAIK,YAAY,GAAGC,IAAI,CAACC,GAAG,CAAC,GAAGH,UAAU,CAACI,GAAG,CAACC,IAAI,IAAIA,IAAI,CAAClB,KAAK,CAAC,CAAC;IAElE,OAAOc,YAAY,GAAGd,KAAK,IAAIY,WAAW,GAAGnB,WAAW,EAAE;MACxDmB,WAAW,GAAGG,IAAI,CAACC,GAAG,CAACJ,WAAW,GAAGlB,QAAQ,EAAED,WAAW,CAAC;MAC3DqB,YAAY,GAAIA,YAAY,GAAGF,WAAW,GAAId,QAAQ;IACxD;IAEAC,WAAW,CAACa,WAAW,CAAC;IAExB1B,QAAQ,CAACiC,MAAM,CAACf,YAAY,EAAE;MAC5BgB,OAAO,EAAER,WAAW;MACpBS,QAAQ,EAAE,GAAG;MACbC,eAAe,EAAE;IACnB,CAAC,CAAC,CAACC,KAAK,CAAC,CAAC;IAEVpB,aAAa,CAAC,KAAK,CAAC;EACtB,CAAC;EAIC,MAAMqB,QAAQ,GAAIhB,CAAoB,IAAK;IACzC,MAAMiB,cAAc,GAAGjB,CAAC,CAACE,WAAW,CAACgB,MAAM,CAAC1B,KAAK;IACjD,IAAIA,KAAK,KAAKyB,cAAc,EAAE;MAC5BxB,QAAQ,CAACwB,cAAc,CAAC;MACxBtB,aAAa,CAAC,IAAI,CAAC;IACrB;EACF,CAAC;EAED,oBACEf,IAAA,CAACF,QAAQ,CAACyC,IAAI;IACZH,QAAQ,EAAEA,QAAS;IACnBjB,YAAY,EAAEA,YAAa;IAC3BZ,aAAa,EAAEA,aAAc;IAC7BiC,aAAa,EAAC,MAAM;IACpBhC,KAAK,EAAE,CAACA,KAAK,EAAE;MAAEE,QAAQ,EAAEM;IAAa,CAAC,CAAE;IAAA,GACvCP,IAAI;IAAAN,QAAA,EAEPD,IAAI,IAAIC;EAAQ,CACJ,CAAC;AAEpB,CAAC;AAED,eAAeF,cAAc","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+
3
+ export { default as AutoResizeText } from "./AutoResizableText/index.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["default","AutoResizeText"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,OAAO,IAAIC,cAAc,QAAQ,8BAAqB","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ import type { TextProps } from 'react-native';
3
+ import type { TextStyle } from 'react-native';
4
+ interface AutoResizeTextProps extends TextProps {
5
+ text?: string;
6
+ maxFontSize?: number;
7
+ minFontSize?: number;
8
+ stepSize?: number;
9
+ numberOfLines?: number;
10
+ style?: TextStyle;
11
+ }
12
+ declare const AutoResizeText: React.FC<AutoResizeTextProps>;
13
+ export default AutoResizeText;
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/AutoResizableText/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2B,MAAM,OAAO,CAAC;AAEhD,OAAQ,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAC,SAAS,EAAE,MAAM,cAAc,CAAC;AAkB7C,UAAU,mBAAoB,SAAQ,SAAS;IAC7C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB;AAED,QAAA,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,mBAAmB,CA+DjD,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { default as AutoResizeText } from "./AutoResizableText";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,qBAAqB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,161 @@
1
+ {
2
+ "name": "indatastar-styled-autoresizabletext",
3
+ "version": "0.1.0",
4
+ "description": "Highly useful for responsive UI, cards, banners, and dynamic layouts.",
5
+ "main": "./lib/module/index.js",
6
+ "types": "./lib/typescript/src/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "source": "./src/index.tsx",
10
+ "types": "./lib/typescript/src/index.d.ts",
11
+ "default": "./lib/module/index.js"
12
+ },
13
+ "./package.json": "./package.json"
14
+ },
15
+ "files": [
16
+ "src",
17
+ "lib",
18
+ "android",
19
+ "ios",
20
+ "cpp",
21
+ "*.podspec",
22
+ "react-native.config.js",
23
+ "!ios/build",
24
+ "!android/build",
25
+ "!android/gradle",
26
+ "!android/gradlew",
27
+ "!android/gradlew.bat",
28
+ "!android/local.properties",
29
+ "!**/__tests__",
30
+ "!**/__fixtures__",
31
+ "!**/__mocks__",
32
+ "!**/.*"
33
+ ],
34
+ "scripts": {
35
+ "example": "yarn workspace indatastar-styled-autoresizabletext-example",
36
+ "clean": "del-cli lib",
37
+ "prepare": "bob build",
38
+ "typecheck": "tsc",
39
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
40
+ "test": "jest",
41
+ "release": "release-it --only-version"
42
+ },
43
+ "keywords": [
44
+ "react-native",
45
+ "ios",
46
+ "android"
47
+ ],
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "git+https://github.com/InDataStar/indatastar-styled-autoresizabletext.git"
51
+ },
52
+ "author": "InDataStar <crawfordlp1@gmail.com> (https://github.com/InDataStar)",
53
+ "license": "MIT",
54
+ "bugs": {
55
+ "url": "https://github.com/InDataStar/indatastar-styled-autoresizabletext/issues"
56
+ },
57
+ "homepage": "https://github.com/InDataStar/indatastar-styled-autoresizabletext#readme",
58
+ "publishConfig": {
59
+ "registry": "https://registry.npmjs.org/"
60
+ },
61
+ "devDependencies": {
62
+ "@commitlint/config-conventional": "^19.8.1",
63
+ "@eslint/compat": "^1.3.2",
64
+ "@eslint/eslintrc": "^3.3.1",
65
+ "@eslint/js": "^9.35.0",
66
+ "@react-native/babel-preset": "0.83.0",
67
+ "@react-native/eslint-config": "0.83.0",
68
+ "@release-it/conventional-changelog": "^10.0.1",
69
+ "@types/jest": "^29.5.14",
70
+ "@types/react": "^19.1.12",
71
+ "commitlint": "^19.8.1",
72
+ "del-cli": "^6.0.0",
73
+ "eslint": "^9.35.0",
74
+ "eslint-config-prettier": "^10.1.8",
75
+ "eslint-plugin-prettier": "^5.5.4",
76
+ "jest": "^29.7.0",
77
+ "lefthook": "^2.0.3",
78
+ "prettier": "^3.8.1",
79
+ "react": "19.1.0",
80
+ "react-native": "0.81.5",
81
+ "react-native-builder-bob": "^0.40.13",
82
+ "release-it": "^19.0.4",
83
+ "turbo": "^2.5.6",
84
+ "typescript": "^5.9.2"
85
+ },
86
+ "peerDependencies": {
87
+ "react": "*",
88
+ "react-native": "*"
89
+ },
90
+ "workspaces": [
91
+ "example"
92
+ ],
93
+ "packageManager": "yarn@4.11.0",
94
+ "react-native-builder-bob": {
95
+ "source": "src",
96
+ "output": "lib",
97
+ "targets": [
98
+ [
99
+ "module",
100
+ {
101
+ "esm": true
102
+ }
103
+ ],
104
+ [
105
+ "typescript",
106
+ {
107
+ "project": "tsconfig.build.json"
108
+ }
109
+ ]
110
+ ]
111
+ },
112
+ "prettier": {
113
+ "quoteProps": "consistent",
114
+ "singleQuote": true,
115
+ "tabWidth": 2,
116
+ "trailingComma": "es5",
117
+ "useTabs": false
118
+ },
119
+ "jest": {
120
+ "preset": "react-native",
121
+ "modulePathIgnorePatterns": [
122
+ "<rootDir>/example/node_modules",
123
+ "<rootDir>/lib/"
124
+ ]
125
+ },
126
+ "commitlint": {
127
+ "extends": [
128
+ "@commitlint/config-conventional"
129
+ ]
130
+ },
131
+ "release-it": {
132
+ "git": {
133
+ "commitMessage": "chore: release ${version}",
134
+ "tagName": "v${version}"
135
+ },
136
+ "npm": {
137
+ "publish": true
138
+ },
139
+ "github": {
140
+ "release": true
141
+ },
142
+ "plugins": {
143
+ "@release-it/conventional-changelog": {
144
+ "preset": {
145
+ "name": "angular"
146
+ }
147
+ }
148
+ }
149
+ },
150
+ "create-react-native-library": {
151
+ "type": "library",
152
+ "languages": "js",
153
+ "tools": [
154
+ "eslint",
155
+ "jest",
156
+ "lefthook",
157
+ "release-it"
158
+ ],
159
+ "version": "0.57.1"
160
+ }
161
+ }
@@ -0,0 +1,96 @@
1
+ import React, { useState, useRef } from 'react';
2
+ import { Animated } from 'react-native';
3
+ import type { TextProps } from 'react-native';
4
+ import type {TextStyle } from 'react-native';
5
+ import type {LayoutChangeEvent } from 'react-native';
6
+ import type {TextLayoutEvent } from 'react-native';
7
+
8
+ type TextLayoutLineRN = {
9
+ x: number;
10
+ y: number;
11
+ width: number;
12
+ height: number;
13
+ ascender: number;
14
+ capHeight: number;
15
+ descender: number;
16
+ text: string;
17
+ xHeight: number;
18
+ };
19
+
20
+
21
+
22
+ interface AutoResizeTextProps extends TextProps {
23
+ text?: string;
24
+ maxFontSize?: number;
25
+ minFontSize?: number;
26
+ stepSize?: number;
27
+ numberOfLines?: number;
28
+ style?: TextStyle;
29
+ }
30
+
31
+ const AutoResizeText: React.FC<AutoResizeTextProps> = ({
32
+ text,
33
+ children,
34
+ maxFontSize = 36,
35
+ minFontSize = 12,
36
+ stepSize = 0.5,
37
+ numberOfLines = 1,
38
+ style,
39
+ ...rest
40
+ }) => {
41
+ const [fontSize, setFontSize] = useState(maxFontSize);
42
+ const [width, setWidth] = useState(0);
43
+ const [needResize, setNeedResize] = useState(true);
44
+ const animatedFont = useRef(new Animated.Value(maxFontSize)).current;
45
+ const onTextLayout = (e: TextLayoutEvent) => {
46
+ if (!needResize) return;
47
+
48
+ const { lines } = e.nativeEvent;
49
+ if (!lines || lines.length === 0) return;
50
+
51
+ let currentFont = fontSize;
52
+ // Use the correct type
53
+ const typedLines = lines as readonly TextLayoutLineRN[];
54
+ let maxLineWidth = Math.max(...typedLines.map(line => line.width));
55
+
56
+ while (maxLineWidth > width && currentFont > minFontSize) {
57
+ currentFont = Math.max(currentFont - stepSize, minFontSize);
58
+ maxLineWidth = (maxLineWidth * currentFont) / fontSize;
59
+ }
60
+
61
+ setFontSize(currentFont);
62
+
63
+ Animated.timing(animatedFont, {
64
+ toValue: currentFont,
65
+ duration: 150,
66
+ useNativeDriver: false,
67
+ }).start();
68
+
69
+ setNeedResize(false);
70
+ };
71
+
72
+
73
+
74
+ const onLayout = (e: LayoutChangeEvent) => {
75
+ const containerWidth = e.nativeEvent.layout.width;
76
+ if (width !== containerWidth) {
77
+ setWidth(containerWidth);
78
+ setNeedResize(true);
79
+ }
80
+ };
81
+
82
+ return (
83
+ <Animated.Text
84
+ onLayout={onLayout}
85
+ onTextLayout={onTextLayout}
86
+ numberOfLines={numberOfLines}
87
+ ellipsizeMode="tail"
88
+ style={[style, { fontSize: animatedFont }]}
89
+ {...rest}
90
+ >
91
+ {text ?? children}
92
+ </Animated.Text>
93
+ );
94
+ };
95
+
96
+ export default AutoResizeText;
package/src/index.tsx ADDED
@@ -0,0 +1 @@
1
+ export { default as AutoResizeText } from "./AutoResizableText";