@studiokico/react-native-stroke-text 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) 2025 studiokico
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,79 @@
1
+ # @studiokico/react-native-stroke-text
2
+
3
+ React Native Stroke Text (New Arch Only)
4
+
5
+ ## Installation
6
+
7
+
8
+ ```sh
9
+ npm install @studiokico/react-native-stroke-text
10
+ ```
11
+
12
+
13
+ ## Usage
14
+
15
+
16
+ ```js
17
+ import React from "react";
18
+ import { StrokeText } from "@studiokico/react-native-stroke-text";
19
+ import { View } from "react-native";
20
+
21
+ export default function Screen() {
22
+ return (
23
+ <View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
24
+ <StrokeText
25
+ text="Test"
26
+ fontSize={50}
27
+ color="#000000"
28
+ strokeColor="#c334eb"
29
+ strokeWidth={20}
30
+ fontFamily="Nunito-Black"
31
+ />
32
+ </View>
33
+ );
34
+ }
35
+
36
+ ```
37
+
38
+ ### Props
39
+
40
+ The following table outlines the props available for the `StrokeText` component:
41
+
42
+ | Prop | Type | Description |
43
+ |-----------------|---------|-----------------------------------------------------------------|
44
+ | `text` | string | The text content you want to display. |
45
+ | `fontSize` | number | Size of the text font, defining how large the text will be. |
46
+ | `color` | string | Color of the text, can use any valid color format. |
47
+ | `strokeColor` | string | Color of the stroke (outline) around the text. |
48
+ | `strokeWidth` | number | Width of the stroke, determining the thickness of the outline. |
49
+ | `fontFamily` | string | Font family for the text, should match available project fonts. |
50
+ | `align` | string | Text alignment (default: `center`) |
51
+ | `numberOfLines` | number | Number of lines (default: `0`) |
52
+ | `ellipsis` | boolean | Ellipsis (...) (default: `false`) |
53
+ | `width` | number | Text width to enable ellipsis (default: `undefined`) |
54
+
55
+ ## Ellipsis
56
+
57
+ ```jsx
58
+ <StrokeText
59
+ text="Lorem ipsum"
60
+ width={150} // +
61
+ ellipsis={true} // +
62
+ numberOfLines={1} // +
63
+ fontSize={32}
64
+ color="#FFFFFF"
65
+ strokeColor="#000000"
66
+ strokeWidth={2}
67
+ fontFamily="Nunito-Black"
68
+ align="center"
69
+ />
70
+
71
+ ```
72
+
73
+ ## License
74
+
75
+ MIT
76
+
77
+ ---
78
+
79
+ Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
@@ -0,0 +1,77 @@
1
+ buildscript {
2
+ ext.getExtOrDefault = {name ->
3
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['StrokeText_' + name]
4
+ }
5
+
6
+ repositories {
7
+ google()
8
+ mavenCentral()
9
+ }
10
+
11
+ dependencies {
12
+ classpath "com.android.tools.build:gradle:8.7.2"
13
+ // noinspection DifferentKotlinGradleVersion
14
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
15
+ }
16
+ }
17
+
18
+
19
+ apply plugin: "com.android.library"
20
+ apply plugin: "kotlin-android"
21
+
22
+ apply plugin: "com.facebook.react"
23
+
24
+ def getExtOrIntegerDefault(name) {
25
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["StrokeText_" + name]).toInteger()
26
+ }
27
+
28
+ android {
29
+ namespace "com.studiokico.stroketext"
30
+
31
+ compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
32
+
33
+ defaultConfig {
34
+ minSdkVersion getExtOrIntegerDefault("minSdkVersion")
35
+ targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
36
+ }
37
+
38
+ buildFeatures {
39
+ buildConfig true
40
+ }
41
+
42
+ buildTypes {
43
+ release {
44
+ minifyEnabled false
45
+ }
46
+ }
47
+
48
+ lintOptions {
49
+ disable "GradleCompatible"
50
+ }
51
+
52
+ compileOptions {
53
+ sourceCompatibility JavaVersion.VERSION_1_8
54
+ targetCompatibility JavaVersion.VERSION_1_8
55
+ }
56
+
57
+ sourceSets {
58
+ main {
59
+ java.srcDirs += [
60
+ "generated/java",
61
+ "generated/jni"
62
+ ]
63
+ }
64
+ }
65
+ }
66
+
67
+ repositories {
68
+ mavenCentral()
69
+ google()
70
+ }
71
+
72
+ def kotlin_version = getExtOrDefault("kotlinVersion")
73
+
74
+ dependencies {
75
+ implementation "com.facebook.react:react-android"
76
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
77
+ }
@@ -0,0 +1,5 @@
1
+ ReactNativeStrokeText_kotlinVersion=2.0.21
2
+ ReactNativeStrokeText_minSdkVersion=24
3
+ ReactNativeStrokeText_targetSdkVersion=34
4
+ ReactNativeStrokeText_compileSdkVersion=35
5
+ ReactNativeStrokeText_ndkVersion=27.1.12297006
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>
@@ -0,0 +1,75 @@
1
+ package com.studiokico.stroketext
2
+
3
+ import android.content.Context
4
+ import android.content.res.AssetManager
5
+ import android.graphics.Typeface
6
+ import com.facebook.react.views.text.ReactFontManager
7
+ import java.util.Locale
8
+ import java.util.concurrent.ConcurrentHashMap
9
+
10
+ object FontUtil {
11
+ private val CACHE = ConcurrentHashMap<String, Typeface>()
12
+ @Volatile
13
+ private var ASSET_INDEX: Map<String, String>? = null
14
+
15
+ fun getFont(context: Context, family: String?, style: Int = Typeface.NORMAL): Typeface {
16
+ if (family.isNullOrEmpty()) return Typeface.defaultFromStyle(style)
17
+
18
+ val appCtx = context.applicationContext
19
+ val am = appCtx.assets
20
+ val key = normalizeKey(family, style)
21
+
22
+ CACHE[key]?.let { return it }
23
+
24
+ ReactFontManager.getInstance().getTypeface(family, style, am)?.let {
25
+ CACHE[key] = it
26
+ return it
27
+ }
28
+
29
+ resolveAssetPath(am, family)?.let { path ->
30
+ try {
31
+ var tf = Typeface.createFromAsset(am, path)
32
+ if (style != Typeface.NORMAL) {
33
+ tf = Typeface.create(tf, style)
34
+ }
35
+ CACHE[key] = tf
36
+ return tf
37
+ } catch (e: Exception) {
38
+ }
39
+ }
40
+
41
+ val defaultTf = Typeface.defaultFromStyle(style)
42
+ CACHE[key] = defaultTf
43
+ return defaultTf
44
+ }
45
+
46
+ private fun resolveAssetPath(am: AssetManager, family: String): String? {
47
+ if (ASSET_INDEX == null) {
48
+ synchronized(this) {
49
+ if (ASSET_INDEX == null) {
50
+ ASSET_INDEX = buildAssetIndex(am, "fonts")
51
+ }
52
+ }
53
+ }
54
+ return ASSET_INDEX?.get(family.lowercase(Locale.US))
55
+ }
56
+
57
+ private fun buildAssetIndex(am: AssetManager, folder: String): Map<String, String> {
58
+ val map = HashMap<String, String>()
59
+ try {
60
+ val files = am.list(folder)
61
+ files?.forEach { filename ->
62
+ val lower = filename.lowercase(Locale.US)
63
+ if (lower.endsWith(".ttf") || lower.endsWith(".otf")) {
64
+ val base = lower.replace(Regex("\\.(ttf|otf)$"), "")
65
+ map[base] = "$folder/$filename"
66
+ }
67
+ }
68
+ } catch (ignored: Exception) { }
69
+ return map
70
+ }
71
+
72
+ private fun normalizeKey(family: String, style: Int): String {
73
+ return "${family.lowercase(Locale.US)}|$style"
74
+ }
75
+ }
@@ -0,0 +1,24 @@
1
+ package com.studiokico.stroketext
2
+
3
+ import com.facebook.react.TurboReactPackage
4
+ import com.facebook.react.bridge.NativeModule
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.module.model.ReactModuleInfo
7
+ import com.facebook.react.module.model.ReactModuleInfoProvider
8
+ import com.facebook.react.uimanager.ViewManager
9
+
10
+ class StrokeTextPackage : TurboReactPackage() {
11
+ override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
12
+ return null
13
+ }
14
+
15
+ override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
16
+ return ReactModuleInfoProvider {
17
+ emptyMap<String, ReactModuleInfo>()
18
+ }
19
+ }
20
+
21
+ override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
22
+ return listOf(StrokeTextViewManager())
23
+ }
24
+ }
@@ -0,0 +1,164 @@
1
+ package com.studiokico.stroketext
2
+
3
+ import android.content.Context
4
+ import android.graphics.Canvas
5
+ import android.graphics.Paint
6
+ import android.graphics.Typeface
7
+ import android.text.Layout
8
+ import android.text.StaticLayout
9
+ import android.text.TextPaint
10
+ import android.text.TextUtils
11
+ import android.util.TypedValue
12
+ import android.view.View
13
+ import kotlin.math.ceil
14
+ import android.os.Build
15
+
16
+ class StrokeTextView(context: Context) : View(context) {
17
+ var text: String = ""
18
+ set(value) { if (field != value) { field = value; requestLayout(); invalidate() } }
19
+
20
+ var fontSize: Float = 14f
21
+ set(value) { if (field != value) { field = value; requestLayout(); invalidate() } }
22
+
23
+ var textColor: Int = 0xFF000000.toInt()
24
+ set(value) { if (field != value) { field = value; invalidate() } }
25
+
26
+ var strokeColor: Int = 0xFFFFFFFF.toInt()
27
+ set(value) { if (field != value) { field = value; invalidate() } }
28
+
29
+ var strokeWidth: Float = 0f
30
+ set(value) { if (field != value) { field = value; requestLayout(); invalidate() } }
31
+
32
+ var fontFamily: String = ""
33
+ set(value) {
34
+ if (field != value) {
35
+ field = value
36
+ cachedTypeface = FontUtil.getFont(context, value)
37
+ requestLayout()
38
+ invalidate()
39
+ }
40
+ }
41
+
42
+ var align: String = "left"
43
+ set(value) { if (field != value) { field = value; requestLayout(); invalidate() } }
44
+
45
+ var numberOfLines: Int = 0
46
+ set(value) { if (field != value) { field = value; requestLayout(); invalidate() } }
47
+
48
+ var ellipsis: Boolean = false
49
+ set(value) { if (field != value) { field = value; requestLayout(); invalidate() } }
50
+
51
+ var customWidth: Float = 0f
52
+ set(value) { if (field != value) { field = value; requestLayout(); invalidate() } }
53
+
54
+
55
+ private val textPaint = TextPaint(Paint.ANTI_ALIAS_FLAG)
56
+ private var cachedTypeface: Typeface? = null
57
+ private var textLayout: StaticLayout? = null // 여기가 핵심: 텍스트 레이아웃 엔진
58
+
59
+ private fun createLayout(width: Int): StaticLayout? {
60
+ if (text.isEmpty() || width <= 0) return null
61
+
62
+ val scaledFontSize = getScaledSize(fontSize)
63
+ textPaint.textSize = scaledFontSize
64
+ textPaint.typeface = cachedTypeface ?: Typeface.DEFAULT
65
+
66
+ val alignment = when (align) {
67
+ "center" -> Layout.Alignment.ALIGN_CENTER
68
+ "right" -> Layout.Alignment.ALIGN_OPPOSITE
69
+ else -> Layout.Alignment.ALIGN_NORMAL
70
+ }
71
+
72
+ val builder = StaticLayout.Builder.obtain(text, 0, text.length, textPaint, width)
73
+ .setAlignment(alignment)
74
+ .setLineSpacing(0f, 1f)
75
+ .setIncludePad(true)
76
+
77
+ if (numberOfLines > 0) {
78
+ builder.setMaxLines(numberOfLines)
79
+ if (ellipsis) {
80
+ builder.setEllipsize(TextUtils.TruncateAt.END)
81
+ }
82
+ }
83
+
84
+ return builder.build()
85
+ }
86
+
87
+ override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
88
+ val widthMode = MeasureSpec.getMode(widthMeasureSpec)
89
+ val widthSize = MeasureSpec.getSize(widthMeasureSpec)
90
+
91
+ val availableWidth = if (customWidth > 0) {
92
+ getScaledSize(customWidth).toInt()
93
+ } else if (widthMode != MeasureSpec.UNSPECIFIED) {
94
+ widthSize
95
+ } else {
96
+ resources.displayMetrics.widthPixels // fallback
97
+ }
98
+
99
+ val scaledStrokeWidth = getScaledSize(strokeWidth)
100
+ val contentWidth = (availableWidth - paddingLeft - paddingRight - (scaledStrokeWidth * 2)).toInt()
101
+
102
+ if (textLayout == null || textLayout?.width != contentWidth) {
103
+ textLayout = createLayout(contentWidth.coerceAtLeast(0))
104
+ }
105
+
106
+ val layout = textLayout
107
+
108
+ var finalWidth = 0
109
+ var finalHeight = 0
110
+
111
+ if (layout != null) {
112
+ finalHeight = (layout.height + paddingTop + paddingBottom + (scaledStrokeWidth * 2)).toInt()
113
+
114
+ if (widthMode == MeasureSpec.EXACTLY) {
115
+ finalWidth = widthSize
116
+ } else {
117
+ var maxLineWidth = 0f
118
+ for (i in 0 until layout.lineCount) {
119
+ maxLineWidth = maxOf(maxLineWidth, layout.getLineWidth(i))
120
+ }
121
+ finalWidth = (ceil(maxLineWidth) + paddingLeft + paddingRight + (scaledStrokeWidth * 2)).toInt()
122
+
123
+ if (widthMode == MeasureSpec.AT_MOST) {
124
+ finalWidth = minOf(finalWidth, widthSize)
125
+ }
126
+ }
127
+ }
128
+
129
+ setMeasuredDimension(finalWidth, finalHeight)
130
+ }
131
+
132
+ override fun onDraw(canvas: Canvas) {
133
+ super.onDraw(canvas)
134
+ val layout = textLayout ?: return
135
+ val scaledStrokeWidth = getScaledSize(strokeWidth)
136
+
137
+ canvas.save()
138
+
139
+ val translateX = paddingLeft + scaledStrokeWidth
140
+ val translateY = paddingTop + scaledStrokeWidth
141
+ canvas.translate(translateX, translateY)
142
+
143
+ if (strokeWidth > 0) {
144
+ textPaint.style = Paint.Style.STROKE
145
+ textPaint.strokeWidth = scaledStrokeWidth
146
+ textPaint.color = strokeColor
147
+ layout.draw(canvas)
148
+ }
149
+
150
+ textPaint.style = Paint.Style.FILL
151
+ textPaint.color = textColor
152
+ layout.draw(canvas)
153
+
154
+ canvas.restore()
155
+ }
156
+
157
+ private fun getScaledSize(size: Float): Float {
158
+ return TypedValue.applyDimension(
159
+ TypedValue.COMPLEX_UNIT_SP,
160
+ size,
161
+ resources.displayMetrics
162
+ )
163
+ }
164
+ }
@@ -0,0 +1,77 @@
1
+ package com.studiokico.stroketext
2
+
3
+ import com.facebook.react.module.annotations.ReactModule
4
+ import com.facebook.react.uimanager.SimpleViewManager
5
+ import com.facebook.react.uimanager.ThemedReactContext
6
+ import com.facebook.react.uimanager.ViewManagerDelegate
7
+ import com.facebook.react.uimanager.annotations.ReactProp
8
+ import com.facebook.react.viewmanagers.RNStrokeTextViewManagerDelegate
9
+ import com.facebook.react.viewmanagers.RNStrokeTextViewManagerInterface
10
+
11
+ @ReactModule(name = StrokeTextViewManager.REACT_CLASS)
12
+ class StrokeTextViewManager : SimpleViewManager<StrokeTextView>(), RNStrokeTextViewManagerInterface<StrokeTextView> {
13
+
14
+ companion object {
15
+ const val REACT_CLASS = "RNStrokeTextView"
16
+ }
17
+
18
+ private val delegate: ViewManagerDelegate<StrokeTextView> = RNStrokeTextViewManagerDelegate(this)
19
+
20
+ override fun getDelegate(): ViewManagerDelegate<StrokeTextView> = delegate
21
+
22
+ override fun getName(): String = REACT_CLASS
23
+
24
+ override fun createViewInstance(context: ThemedReactContext): StrokeTextView {
25
+ return StrokeTextView(context)
26
+ }
27
+
28
+ @ReactProp(name = "text")
29
+ override fun setText(view: StrokeTextView, text: String?) {
30
+ view.text = text ?: ""
31
+ }
32
+
33
+ @ReactProp(name = "fontSize")
34
+ override fun setFontSize(view: StrokeTextView, fontSize: Float) {
35
+ view.fontSize = fontSize
36
+ }
37
+
38
+ @ReactProp(name = "color", customType = "Color")
39
+ override fun setColor(view: StrokeTextView, color: Int?) {
40
+ view.textColor = color ?: 0xFF000000.toInt()
41
+ }
42
+
43
+ @ReactProp(name = "strokeColor", customType = "Color")
44
+ override fun setStrokeColor(view: StrokeTextView, color: Int?) {
45
+ view.strokeColor = color ?: 0xFFFFFFFF.toInt()
46
+ }
47
+
48
+ @ReactProp(name = "strokeWidth")
49
+ override fun setStrokeWidth(view: StrokeTextView, width: Float) {
50
+ view.strokeWidth = width
51
+ }
52
+
53
+ @ReactProp(name = "fontFamily")
54
+ override fun setFontFamily(view: StrokeTextView, fontFamily: String?) {
55
+ view.fontFamily = fontFamily ?: ""
56
+ }
57
+
58
+ @ReactProp(name = "width")
59
+ override fun setWidth(view: StrokeTextView, width: Float) {
60
+ view.customWidth = width
61
+ }
62
+
63
+ @ReactProp(name = "align")
64
+ override fun setAlign(view: StrokeTextView, align: String?) {
65
+ view.align = align ?: "left"
66
+ }
67
+
68
+ @ReactProp(name = "numberOfLines", defaultInt = 0)
69
+ override fun setNumberOfLines(view: StrokeTextView, numberOfLines: Int) {
70
+ view.numberOfLines = numberOfLines
71
+ }
72
+
73
+ @ReactProp(name = "ellipsis")
74
+ override fun setEllipsis(view: StrokeTextView, ellipsis: Boolean) {
75
+ view.ellipsis = ellipsis
76
+ }
77
+ }
@@ -0,0 +1,9 @@
1
+ #import <React/RCTViewComponentView.h>
2
+ #import <UIKit/UIKit.h>
3
+
4
+ NS_ASSUME_NONNULL_BEGIN
5
+
6
+ @interface RNStrokeTextView : RCTViewComponentView
7
+ @end
8
+
9
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,110 @@
1
+ #import "RNStrokeTextView.h"
2
+
3
+ #import <react/renderer/components/RNStrokeTextSpec/ComponentDescriptors.h>
4
+ #import <react/renderer/components/RNStrokeTextSpec/EventEmitters.h>
5
+ #import <react/renderer/components/RNStrokeTextSpec/Props.h>
6
+ #import <react/renderer/components/RNStrokeTextSpec/RCTComponentViewHelpers.h>
7
+
8
+ #import <React/RCTFabricComponentsPlugins.h>
9
+ #import <React/RCTConversions.h>
10
+
11
+ // 2. Swift 클래스 import (프로젝트 설정에 따라 이름이 다를 수 있음)
12
+ // 라이브러리 개발 중이라면 보통 "라이브러리이름-Swift.h" 입니다.
13
+ // 예: react-native-stroke-text -> react_native_stroke_text-Swift.h
14
+ #if __has_include("StrokeText-Swift.h")
15
+ #import "StrokeText-Swift.h"
16
+ #else
17
+ #import <StrokeText/StrokeText-Swift.h>
18
+ #endif
19
+
20
+ using namespace facebook::react;
21
+
22
+ @interface RNStrokeTextView () <RCTRNStrokeTextViewViewProtocol>
23
+ @end
24
+
25
+ @implementation RNStrokeTextView {
26
+ StrokeTextView *_view;
27
+ }
28
+
29
+ + (ComponentDescriptorProvider)componentDescriptorProvider {
30
+ return concreteComponentDescriptorProvider<RNStrokeTextViewComponentDescriptor>();
31
+ }
32
+
33
+ - (instancetype)initWithFrame:(CGRect)frame {
34
+ if (self = [super initWithFrame:frame]) {
35
+ static const auto defaultProps = std::make_shared<const RNStrokeTextViewProps>();
36
+ _props = defaultProps;
37
+
38
+ _view = [[StrokeTextView alloc] initWithFrame:self.bounds];
39
+
40
+ self.contentView = _view;
41
+ }
42
+ return self;
43
+ }
44
+
45
+ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps {
46
+ const auto &oldViewProps = *std::static_pointer_cast<const RNStrokeTextViewProps>(_props);
47
+ const auto &newViewProps = *std::static_pointer_cast<const RNStrokeTextViewProps>(props);
48
+
49
+ if (oldViewProps.text != newViewProps.text) {
50
+ _view.text = RCTNSStringFromString(newViewProps.text);
51
+ }
52
+
53
+ if (oldViewProps.fontFamily != newViewProps.fontFamily || oldViewProps.fontSize != newViewProps.fontSize) {
54
+ NSString *fontName = RCTNSStringFromString(newViewProps.fontFamily);
55
+ CGFloat fontSize = newViewProps.fontSize; // Float -> CGFloat
56
+
57
+ UIFont *font = [UIFont fontWithName:fontName size:fontSize];
58
+ if (!font) {
59
+ font = [UIFont systemFontOfSize:fontSize];
60
+ }
61
+ _view.font = font;
62
+ }
63
+
64
+ if (oldViewProps.color != newViewProps.color) {
65
+ _view.textColor = RCTUIColorFromSharedColor(newViewProps.color);
66
+ }
67
+ if (oldViewProps.strokeColor != newViewProps.strokeColor) {
68
+ _view.strokeColor = RCTUIColorFromSharedColor(newViewProps.strokeColor);
69
+ }
70
+
71
+ if (oldViewProps.strokeWidth != newViewProps.strokeWidth) {
72
+ _view.strokeWidth = newViewProps.strokeWidth;
73
+ }
74
+
75
+ if (oldViewProps.align != newViewProps.align) {
76
+ switch (newViewProps.align) {
77
+ case RNStrokeTextViewAlign::Center:
78
+ _view.textAlignment = NSTextAlignmentCenter;
79
+ break;
80
+ case RNStrokeTextViewAlign::Right:
81
+ _view.textAlignment = NSTextAlignmentRight;
82
+ break;
83
+ case RNStrokeTextViewAlign::Left:
84
+ default:
85
+ _view.textAlignment = NSTextAlignmentLeft;
86
+ break;
87
+ }
88
+ }
89
+
90
+ if (oldViewProps.numberOfLines != newViewProps.numberOfLines) {
91
+ _view.numberOfLines = newViewProps.numberOfLines;
92
+ }
93
+
94
+ if (oldViewProps.ellipsis != newViewProps.ellipsis) {
95
+ _view.lineBreakMode = newViewProps.ellipsis ? NSLineBreakByTruncatingTail : NSLineBreakByWordWrapping;
96
+ }
97
+
98
+ if (oldViewProps.width != newViewProps.width) {
99
+ _view.customWidth = newViewProps.width;
100
+ }
101
+
102
+ [super updateProps:props oldProps:oldProps];
103
+ }
104
+
105
+ @end
106
+
107
+ Class<RCTComponentViewProtocol> RNStrokeTextViewCls(void)
108
+ {
109
+ return RNStrokeTextView.class;
110
+ }
@@ -0,0 +1,65 @@
1
+ import UIKit
2
+
3
+ @objc(StrokeTextView)
4
+ public class StrokeTextView: UILabel {
5
+ @objc public var strokeColor: UIColor = .white {
6
+ didSet { setNeedsDisplay() }
7
+ }
8
+
9
+ @objc public var strokeWidth: CGFloat = 0 {
10
+ didSet {
11
+ invalidateIntrinsicContentSize()
12
+ setNeedsDisplay()
13
+ }
14
+ }
15
+
16
+ @objc public var customWidth: CGFloat = 0 {
17
+ didSet { invalidateIntrinsicContentSize() }
18
+ }
19
+
20
+ public override init(frame: CGRect) {
21
+ super.init(frame: frame)
22
+ self.commonInit()
23
+ }
24
+
25
+ public required init?(coder: NSCoder) {
26
+ super.init(coder: coder)
27
+ self.commonInit()
28
+ }
29
+
30
+ private func commonInit() {
31
+ self.numberOfLines = 0
32
+ self.clipsToBounds = false
33
+ self.backgroundColor = .clear
34
+ }
35
+
36
+ public override func drawText(in rect: CGRect) {
37
+ let shadowOffset = self.shadowOffset
38
+ let originalTextColor = self.textColor
39
+
40
+ let context = UIGraphicsGetCurrentContext()
41
+ context?.saveGState()
42
+
43
+ if strokeWidth > 0 {
44
+ context?.setLineWidth(strokeWidth)
45
+ context?.setLineJoin(.round)
46
+ context?.setTextDrawingMode(.stroke)
47
+ self.textColor = strokeColor
48
+ super.drawText(in: rect)
49
+ }
50
+
51
+ context?.setTextDrawingMode(.fill)
52
+ self.textColor = originalTextColor
53
+ self.shadowOffset = CGSize.zero
54
+ super.drawText(in: rect)
55
+
56
+ self.shadowOffset = shadowOffset
57
+ context?.restoreGState()
58
+ }
59
+
60
+ public override var intrinsicContentSize: CGSize {
61
+ let size = super.intrinsicContentSize
62
+ let extra = strokeWidth
63
+ return CGSize(width: size.width + extra, height: size.height + extra)
64
+ }
65
+ }
@@ -0,0 +1,27 @@
1
+ import {
2
+ codegenNativeComponent,
3
+ type ColorValue,
4
+ type ViewProps,
5
+ } from 'react-native';
6
+ import type {
7
+ WithDefault,
8
+ Float,
9
+ Int32,
10
+ } from 'react-native/Libraries/Types/CodegenTypesNamespace';
11
+
12
+ type TextAlign = 'center' | 'left' | 'right';
13
+
14
+ export interface NativeProps extends ViewProps {
15
+ width?: Float;
16
+ text: string;
17
+ fontSize?: Float;
18
+ color?: ColorValue;
19
+ strokeColor?: ColorValue;
20
+ strokeWidth?: Float;
21
+ fontFamily?: string;
22
+ align?: WithDefault<TextAlign, 'left'>;
23
+ numberOfLines?: Int32;
24
+ ellipsis?: boolean;
25
+ }
26
+
27
+ export default codegenNativeComponent<NativeProps>('RNStrokeTextView');
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ export { default as StrokeText } from './StrokeTextViewNativeComponent';
4
+ export * from './StrokeTextViewNativeComponent';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["default","StrokeText"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,OAAO,IAAIC,UAAU,QAAQ,iCAAiC;AACvE,cAAc,iCAAiC","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,18 @@
1
+ import { type ColorValue, type ViewProps } from 'react-native';
2
+ import type { WithDefault, Float, Int32 } from 'react-native/Libraries/Types/CodegenTypesNamespace';
3
+ type TextAlign = 'center' | 'left' | 'right';
4
+ export interface NativeProps extends ViewProps {
5
+ width?: Float;
6
+ text: string;
7
+ fontSize?: Float;
8
+ color?: ColorValue;
9
+ strokeColor?: ColorValue;
10
+ strokeWidth?: Float;
11
+ fontFamily?: string;
12
+ align?: WithDefault<TextAlign, 'left'>;
13
+ numberOfLines?: Int32;
14
+ ellipsis?: boolean;
15
+ }
16
+ declare const _default: import("react-native/types_generated/Libraries/Utilities/codegenNativeComponent").NativeComponentType<NativeProps>;
17
+ export default _default;
18
+ //# sourceMappingURL=StrokeTextViewNativeComponent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StrokeTextViewNativeComponent.d.ts","sourceRoot":"","sources":["../../../src/StrokeTextViewNativeComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,UAAU,EACf,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EACV,WAAW,EACX,KAAK,EACL,KAAK,EACN,MAAM,oDAAoD,CAAC;AAE5D,KAAK,SAAS,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;AAE7C,MAAM,WAAW,WAAY,SAAQ,SAAS;IAC5C,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,KAAK,CAAC;IACjB,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,WAAW,CAAC,EAAE,UAAU,CAAC;IACzB,WAAW,CAAC,EAAE,KAAK,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,WAAW,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IACvC,aAAa,CAAC,EAAE,KAAK,CAAC;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;;AAED,wBAAuE"}
@@ -0,0 +1,3 @@
1
+ export { default as StrokeText } from './StrokeTextViewNativeComponent';
2
+ export * from './StrokeTextViewNativeComponent';
3
+ //# 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,UAAU,EAAE,MAAM,iCAAiC,CAAC;AACxE,cAAc,iCAAiC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,172 @@
1
+ {
2
+ "name": "@studiokico/react-native-stroke-text",
3
+ "version": "0.1.0",
4
+ "description": "React Native Stroke Text (New Arch Only)",
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 @studiokico/react-native-stroke-text-example",
36
+ "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build 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
+ "stroke",
46
+ "text"
47
+ ],
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "git+https://github.com/studiokico/react-native-stroke-text.git"
51
+ },
52
+ "author": "studiokico <dohyun@studiokico.co.kr> (https://github.com/studiokico)",
53
+ "license": "MIT",
54
+ "bugs": {
55
+ "url": "https://github.com/studiokico/react-native-stroke-text/issues"
56
+ },
57
+ "homepage": "https://github.com/studiokico/react-native-stroke-text#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.82.1",
67
+ "@react-native/eslint-config": "0.82.1",
68
+ "@release-it/conventional-changelog": "^10.0.1",
69
+ "@types/jest": "^29.5.14",
70
+ "@types/react": "^19.1.1",
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
+ "prettier": "^2.8.8",
78
+ "react": "19.1.1",
79
+ "react-native": "0.82.1",
80
+ "react-native-builder-bob": "^0.40.17",
81
+ "release-it": "^19.0.4",
82
+ "turbo": "^2.5.6",
83
+ "typescript": "^5.9.2"
84
+ },
85
+ "peerDependencies": {
86
+ "react": "*",
87
+ "react-native": "*"
88
+ },
89
+ "workspaces": [
90
+ "example"
91
+ ],
92
+ "packageManager": "yarn@4.11.0",
93
+ "react-native-builder-bob": {
94
+ "source": "src",
95
+ "output": "lib",
96
+ "targets": [
97
+ [
98
+ "module",
99
+ {
100
+ "esm": true
101
+ }
102
+ ],
103
+ [
104
+ "typescript",
105
+ {
106
+ "project": "tsconfig.build.json"
107
+ }
108
+ ]
109
+ ]
110
+ },
111
+ "codegenConfig": {
112
+ "name": "RNStrokeTextSpec",
113
+ "type": "all",
114
+ "jsSrcsDir": "src",
115
+ "android": {
116
+ "javaPackageName": "com.studiokico.stroketext"
117
+ },
118
+ "ios": {
119
+ "componentProvider": {
120
+ "RNStrokeTextView": "RNStrokeTextView"
121
+ }
122
+ }
123
+ },
124
+ "prettier": {
125
+ "quoteProps": "consistent",
126
+ "singleQuote": true,
127
+ "tabWidth": 2,
128
+ "trailingComma": "es5",
129
+ "useTabs": false
130
+ },
131
+ "jest": {
132
+ "preset": "react-native",
133
+ "modulePathIgnorePatterns": [
134
+ "<rootDir>/example/node_modules",
135
+ "<rootDir>/lib/"
136
+ ]
137
+ },
138
+ "commitlint": {
139
+ "extends": [
140
+ "@commitlint/config-conventional"
141
+ ]
142
+ },
143
+ "release-it": {
144
+ "git": {
145
+ "commitMessage": "chore: release ${version}",
146
+ "tagName": "v${version}"
147
+ },
148
+ "npm": {
149
+ "publish": true
150
+ },
151
+ "github": {
152
+ "release": true
153
+ },
154
+ "plugins": {
155
+ "@release-it/conventional-changelog": {
156
+ "preset": {
157
+ "name": "angular"
158
+ }
159
+ }
160
+ }
161
+ },
162
+ "create-react-native-library": {
163
+ "type": "fabric-view",
164
+ "languages": "kotlin-objc",
165
+ "tools": [
166
+ "eslint",
167
+ "jest",
168
+ "release-it"
169
+ ],
170
+ "version": "0.56.0"
171
+ }
172
+ }
@@ -0,0 +1,36 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+ folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
5
+
6
+ Pod::Spec.new do |s|
7
+ s.name = "react-native-stroke-text"
8
+ s.module_name = "StrokeText"
9
+ s.version = package["version"]
10
+ s.summary = package["description"]
11
+ s.homepage = package["homepage"]
12
+ s.license = package["license"]
13
+ s.authors = package["author"]
14
+
15
+ s.platforms = { :ios => min_ios_version_supported }
16
+ s.source = { :git => "https://github.com/studiokico/react-native-stroke-text.git", :tag => "#{s.version}" }
17
+
18
+ s.source_files = "ios/**/*.{h,m,mm,swift,cpp}"
19
+ s.private_header_files = "ios/**/*.h"
20
+
21
+ install_modules_dependencies(s)
22
+
23
+ s.dependency "React-Core"
24
+ s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
25
+ s.pod_target_xcconfig = {
26
+ 'HEADER_SEARCH_PATHS' => '"$(PODS_ROOT)/boost" "$(PODS_ROOT)/boost-for-react-native" "$(PODS_ROOT)/RCT-Folly" "$(PODS_ROOT)/Headers/Private/Yoga"',
27
+ "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -DFOLLY_CFG_NO_COROUTINES=1",
28
+ "CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
29
+ }
30
+ s.dependency "React-RCTFabric"
31
+ s.dependency "React-Codegen"
32
+ s.dependency "RCT-Folly"
33
+ s.dependency "RCTRequired"
34
+ s.dependency "RCTTypeSafety"
35
+ s.dependency "ReactCommon/turbomodule/core"
36
+ end
@@ -0,0 +1,27 @@
1
+ import {
2
+ codegenNativeComponent,
3
+ type ColorValue,
4
+ type ViewProps,
5
+ } from 'react-native';
6
+ import type {
7
+ WithDefault,
8
+ Float,
9
+ Int32,
10
+ } from 'react-native/Libraries/Types/CodegenTypesNamespace';
11
+
12
+ type TextAlign = 'center' | 'left' | 'right';
13
+
14
+ export interface NativeProps extends ViewProps {
15
+ width?: Float;
16
+ text: string;
17
+ fontSize?: Float;
18
+ color?: ColorValue;
19
+ strokeColor?: ColorValue;
20
+ strokeWidth?: Float;
21
+ fontFamily?: string;
22
+ align?: WithDefault<TextAlign, 'left'>;
23
+ numberOfLines?: Int32;
24
+ ellipsis?: boolean;
25
+ }
26
+
27
+ export default codegenNativeComponent<NativeProps>('RNStrokeTextView');
package/src/index.tsx ADDED
@@ -0,0 +1,2 @@
1
+ export { default as StrokeText } from './StrokeTextViewNativeComponent';
2
+ export * from './StrokeTextViewNativeComponent';