@matiks/rn-stroke-text 0.1.6 → 0.1.7
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.
|
@@ -8,6 +8,7 @@ import android.graphics.Typeface
|
|
|
8
8
|
import android.text.Layout
|
|
9
9
|
import android.text.StaticLayout
|
|
10
10
|
import android.text.TextPaint
|
|
11
|
+
import android.text.TextUtils
|
|
11
12
|
import android.util.TypedValue
|
|
12
13
|
import android.view.View
|
|
13
14
|
import kotlin.math.ceil
|
|
@@ -118,7 +119,17 @@ class StrokeTextView(context: Context) : View(context) {
|
|
|
118
119
|
if (!layoutDirty && textLayout != null && lastLayoutWidth == safeWidth) return
|
|
119
120
|
updatePaints()
|
|
120
121
|
|
|
121
|
-
var displayText: CharSequence =
|
|
122
|
+
var displayText: CharSequence =
|
|
123
|
+
if (ellipsis) {
|
|
124
|
+
TextUtils.ellipsize(
|
|
125
|
+
text,
|
|
126
|
+
textPaint,
|
|
127
|
+
safeWidth.toFloat(),
|
|
128
|
+
TextUtils.TruncateAt.END
|
|
129
|
+
)
|
|
130
|
+
} else {
|
|
131
|
+
text
|
|
132
|
+
}
|
|
122
133
|
|
|
123
134
|
// Use StaticLayout.Builder for API 23+
|
|
124
135
|
val builder =
|
|
@@ -206,7 +217,7 @@ class StrokeTextView(context: Context) : View(context) {
|
|
|
206
217
|
for (line in text.split("\n")) {
|
|
207
218
|
maxWidth = max(maxWidth, textPaint.measureText(line))
|
|
208
219
|
}
|
|
209
|
-
return maxWidth + strokeWidthPx * 2
|
|
220
|
+
return maxWidth + strokeWidthPx * 2 + 4
|
|
210
221
|
}
|
|
211
222
|
|
|
212
223
|
// ─────────────────────────────────────────────
|
package/lib/index.d.ts
CHANGED
|
@@ -6,5 +6,5 @@ interface StrokeTextViewProps extends MatiksStrokeTextProps {
|
|
|
6
6
|
height?: number;
|
|
7
7
|
};
|
|
8
8
|
}
|
|
9
|
-
declare const _default: React.MemoExoticComponent<({ styles, ...props }: StrokeTextViewProps) => React.JSX.Element>;
|
|
9
|
+
declare const _default: React.MemoExoticComponent<({ text, styles, ...props }: StrokeTextViewProps) => React.JSX.Element>;
|
|
10
10
|
export default _default;
|
package/lib/index.js
CHANGED
|
@@ -3,9 +3,10 @@ import { callback, getHostComponent } from "react-native-nitro-modules";
|
|
|
3
3
|
import MatiksKeyboardViewConfig from "../nitrogen/generated/shared/json/MatiksStrokeTextConfig.json";
|
|
4
4
|
import {} from "./specs/Stroke.nitro";
|
|
5
5
|
const StrokeTextViewComponent = getHostComponent('MatiksStrokeText', () => MatiksKeyboardViewConfig);
|
|
6
|
-
const StrokeTextView = ({ styles, ...props }) => {
|
|
6
|
+
const StrokeTextView = ({ text, styles, ...props }) => {
|
|
7
7
|
const ref = useRef(null);
|
|
8
8
|
const [size, setSize] = useState({ width: 0, height: 0 });
|
|
9
|
+
const [isReady, setIsReady] = useState(false);
|
|
9
10
|
useEffect(() => {
|
|
10
11
|
if (!ref.current)
|
|
11
12
|
return;
|
|
@@ -14,10 +15,14 @@ const StrokeTextView = ({ styles, ...props }) => {
|
|
|
14
15
|
}, [
|
|
15
16
|
props.fontFamily,
|
|
16
17
|
props.fontSize,
|
|
17
|
-
|
|
18
|
+
text,
|
|
19
|
+
isReady
|
|
18
20
|
]);
|
|
19
|
-
return (React.createElement(StrokeTextViewComponent, { ...props, style: [{ width: size.width, height: size.height }, styles], hybridRef: callback((_ref) => {
|
|
21
|
+
return (React.createElement(StrokeTextViewComponent, { ...props, text: String(text), style: [{ width: size.width, height: size.height }, styles], hybridRef: callback((_ref) => {
|
|
22
|
+
if (ref.current)
|
|
23
|
+
return;
|
|
20
24
|
ref.current = _ref;
|
|
25
|
+
setIsReady(true);
|
|
21
26
|
}) }));
|
|
22
27
|
};
|
|
23
28
|
export default React.memo(StrokeTextView);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type TextAlign =
|
|
1
|
+
type TextAlign = 'center' | 'left' | 'right';
|
|
2
2
|
import type { HybridView, HybridViewMethods, HybridViewProps } from 'react-native-nitro-modules';
|
|
3
3
|
export interface MatiksStrokeTextProps extends HybridViewProps {
|
|
4
4
|
width?: number;
|
|
@@ -11,6 +11,7 @@ export interface MatiksStrokeTextProps extends HybridViewProps {
|
|
|
11
11
|
align?: TextAlign;
|
|
12
12
|
numberOfLines?: number;
|
|
13
13
|
ellipsis?: boolean;
|
|
14
|
+
onDimensionsChange?: (dimensions: Dimensions) => void;
|
|
14
15
|
}
|
|
15
16
|
export interface Dimensions {
|
|
16
17
|
width: number;
|