@whetware/react-native-stroke-text 0.0.2
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/CHANGELOG.md +7 -0
- package/LICENSE.md +21 -0
- package/NitroStrokeText.podspec +31 -0
- package/README.md +45 -0
- package/android/CMakeLists.txt +29 -0
- package/android/build.gradle +142 -0
- package/android/fix-prefab.gradle +51 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/cpp-adapter.cpp +6 -0
- package/android/src/main/java/com/margelo/nitro/stroketext/HybridStrokeTextView.kt +107 -0
- package/android/src/main/java/com/margelo/nitro/stroketext/NitroStrokeTextPackage.kt +39 -0
- package/android/src/main/java/com/margelo/nitro/stroketext/StrokeTextView.kt +429 -0
- package/ios/Bridge.h +8 -0
- package/ios/HybridStrokeTextView.swift +114 -0
- package/ios/StrokeTextColor.swift +120 -0
- package/ios/StrokeTextView.swift +326 -0
- package/ios/StrokedTextLabel.swift +72 -0
- package/lib/StrokeText.d.ts +3 -0
- package/lib/StrokeText.js +109 -0
- package/lib/StrokeText.web.d.ts +3 -0
- package/lib/StrokeText.web.js +106 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +1 -0
- package/lib/index.web.d.ts +2 -0
- package/lib/index.web.js +1 -0
- package/lib/specs/StrokeTextView.nitro.d.ts +37 -0
- package/lib/specs/StrokeTextView.nitro.js +1 -0
- package/lib/types.d.ts +17 -0
- package/lib/types.js +1 -0
- package/nitro.json +24 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/NitroStrokeText+autolinking.cmake +83 -0
- package/nitrogen/generated/android/NitroStrokeText+autolinking.gradle +27 -0
- package/nitrogen/generated/android/NitroStrokeTextOnLoad.cpp +46 -0
- package/nitrogen/generated/android/NitroStrokeTextOnLoad.hpp +25 -0
- package/nitrogen/generated/android/c++/JHybridStrokeTextViewSpec.cpp +308 -0
- package/nitrogen/generated/android/c++/JHybridStrokeTextViewSpec.hpp +117 -0
- package/nitrogen/generated/android/c++/JStrokeTextAlign.hpp +67 -0
- package/nitrogen/generated/android/c++/JStrokeTextDecorationLine.hpp +64 -0
- package/nitrogen/generated/android/c++/JStrokeTextEllipsizeMode.hpp +64 -0
- package/nitrogen/generated/android/c++/JStrokeTextFontStyle.hpp +58 -0
- package/nitrogen/generated/android/c++/JStrokeTextTransform.hpp +64 -0
- package/nitrogen/generated/android/c++/views/JHybridStrokeTextViewStateUpdater.cpp +156 -0
- package/nitrogen/generated/android/c++/views/JHybridStrokeTextViewStateUpdater.hpp +49 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/stroketext/HybridStrokeTextViewSpec.kt +209 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/stroketext/NitroStrokeTextOnLoad.kt +35 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/stroketext/StrokeTextAlign.kt +26 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/stroketext/StrokeTextDecorationLine.kt +25 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/stroketext/StrokeTextEllipsizeMode.kt +25 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/stroketext/StrokeTextFontStyle.kt +23 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/stroketext/StrokeTextTransform.kt +25 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/stroketext/views/HybridStrokeTextViewManager.kt +70 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/stroketext/views/HybridStrokeTextViewStateUpdater.kt +23 -0
- package/nitrogen/generated/ios/NitroStrokeText+autolinking.rb +60 -0
- package/nitrogen/generated/ios/NitroStrokeText-Swift-Cxx-Bridge.cpp +33 -0
- package/nitrogen/generated/ios/NitroStrokeText-Swift-Cxx-Bridge.hpp +177 -0
- package/nitrogen/generated/ios/NitroStrokeText-Swift-Cxx-Umbrella.hpp +58 -0
- package/nitrogen/generated/ios/NitroStrokeTextAutolinking.mm +33 -0
- package/nitrogen/generated/ios/NitroStrokeTextAutolinking.swift +26 -0
- package/nitrogen/generated/ios/c++/HybridStrokeTextViewSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridStrokeTextViewSpecSwift.hpp +271 -0
- package/nitrogen/generated/ios/c++/views/HybridStrokeTextViewComponent.mm +232 -0
- package/nitrogen/generated/ios/swift/HybridStrokeTextViewSpec.swift +81 -0
- package/nitrogen/generated/ios/swift/HybridStrokeTextViewSpec_cxx.swift +620 -0
- package/nitrogen/generated/ios/swift/StrokeTextAlign.swift +52 -0
- package/nitrogen/generated/ios/swift/StrokeTextDecorationLine.swift +48 -0
- package/nitrogen/generated/ios/swift/StrokeTextEllipsizeMode.swift +48 -0
- package/nitrogen/generated/ios/swift/StrokeTextFontStyle.swift +40 -0
- package/nitrogen/generated/ios/swift/StrokeTextTransform.swift +48 -0
- package/nitrogen/generated/shared/c++/HybridStrokeTextViewSpec.cpp +72 -0
- package/nitrogen/generated/shared/c++/HybridStrokeTextViewSpec.hpp +128 -0
- package/nitrogen/generated/shared/c++/StrokeTextAlign.hpp +88 -0
- package/nitrogen/generated/shared/c++/StrokeTextDecorationLine.hpp +84 -0
- package/nitrogen/generated/shared/c++/StrokeTextEllipsizeMode.hpp +84 -0
- package/nitrogen/generated/shared/c++/StrokeTextFontStyle.hpp +76 -0
- package/nitrogen/generated/shared/c++/StrokeTextTransform.hpp +84 -0
- package/nitrogen/generated/shared/c++/views/HybridStrokeTextViewComponent.cpp +388 -0
- package/nitrogen/generated/shared/c++/views/HybridStrokeTextViewComponent.hpp +138 -0
- package/nitrogen/generated/shared/json/StrokeTextViewConfig.json +35 -0
- package/package.json +124 -0
- package/react-native.config.js +16 -0
package/CHANGELOG.md
ADDED
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Patrick Kabwe
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = "NitroStrokeText"
|
|
7
|
+
s.version = package["version"]
|
|
8
|
+
s.summary = package["description"]
|
|
9
|
+
s.homepage = package["homepage"]
|
|
10
|
+
s.license = package["license"]
|
|
11
|
+
s.authors = package["author"]
|
|
12
|
+
|
|
13
|
+
s.platforms = { :ios => min_ios_version_supported, :visionos => 1.0 }
|
|
14
|
+
s.source = { :git => "https://github.com/whetware/react-native-stroke-text.git", :tag => "v#{s.version}" }
|
|
15
|
+
|
|
16
|
+
s.source_files = [
|
|
17
|
+
# Implementation (Swift)
|
|
18
|
+
"ios/**/*.{swift}",
|
|
19
|
+
# Autolinking/Registration (Objective-C++)
|
|
20
|
+
"ios/**/*.{m,mm}",
|
|
21
|
+
# Implementation (C++ objects)
|
|
22
|
+
"cpp/**/*.{hpp,cpp}",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
load 'nitrogen/generated/ios/NitroStrokeText+autolinking.rb'
|
|
26
|
+
add_nitrogen_files(s)
|
|
27
|
+
|
|
28
|
+
s.dependency 'React-jsi'
|
|
29
|
+
s.dependency 'React-callinvoker'
|
|
30
|
+
install_modules_dependencies(s)
|
|
31
|
+
end
|
package/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# `@whetware/react-native-stroke-text`
|
|
2
|
+
|
|
3
|
+
Stroke/outline text for React Native, implemented as a **Nitro Hybrid View** (Fabric / New Architecture only).
|
|
4
|
+
|
|
5
|
+
## Support
|
|
6
|
+
|
|
7
|
+
- iOS: ✅ (Swift)
|
|
8
|
+
- Android: ✅ (Kotlin)
|
|
9
|
+
- Web: ✅ (JS fallback)
|
|
10
|
+
- Old architecture: ❌ (not supported)
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
pnpm add @whetware/react-native-stroke-text react-native-nitro-modules
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
### Expo (managed)
|
|
19
|
+
|
|
20
|
+
This package requires the **New Architecture**. Ensure it’s enabled in your app before installing.
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
import { StrokeText } from '@whetware/react-native-stroke-text'
|
|
26
|
+
|
|
27
|
+
export function Example() {
|
|
28
|
+
return (
|
|
29
|
+
<StrokeText
|
|
30
|
+
strokeWidth={4}
|
|
31
|
+
strokeColor="#000"
|
|
32
|
+
numberOfLines={1}
|
|
33
|
+
ellipsizeMode="tail"
|
|
34
|
+
style={{ fontSize: 48, fontWeight: '800', color: '#fff' }}
|
|
35
|
+
>
|
|
36
|
+
Hello
|
|
37
|
+
</StrokeText>
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Development
|
|
43
|
+
|
|
44
|
+
- Generate Nitro bindings: `pnpm specs`
|
|
45
|
+
- Typecheck: `pnpm typecheck`
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
project(NitroStrokeText)
|
|
2
|
+
cmake_minimum_required(VERSION 3.9.0)
|
|
3
|
+
|
|
4
|
+
set (PACKAGE_NAME NitroStrokeText)
|
|
5
|
+
set (CMAKE_VERBOSE_MAKEFILE ON)
|
|
6
|
+
set (CMAKE_CXX_STANDARD 20)
|
|
7
|
+
|
|
8
|
+
# Define C++ library and add all sources
|
|
9
|
+
add_library(${PACKAGE_NAME} SHARED
|
|
10
|
+
src/main/cpp/cpp-adapter.cpp
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
# Add Nitrogen specs :)
|
|
14
|
+
include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/NitroStrokeText+autolinking.cmake)
|
|
15
|
+
|
|
16
|
+
# Set up local includes
|
|
17
|
+
include_directories(
|
|
18
|
+
"src/main/cpp"
|
|
19
|
+
"../cpp"
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
find_library(LOG_LIB log)
|
|
23
|
+
|
|
24
|
+
# Link all libraries together
|
|
25
|
+
target_link_libraries(
|
|
26
|
+
${PACKAGE_NAME}
|
|
27
|
+
${LOG_LIB}
|
|
28
|
+
android # <-- Android core
|
|
29
|
+
)
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
repositories {
|
|
3
|
+
google()
|
|
4
|
+
mavenCentral()
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
dependencies {
|
|
8
|
+
classpath "com.android.tools.build:gradle:9.0.0"
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
def reactNativeArchitectures() {
|
|
13
|
+
def value = rootProject.getProperties().get("reactNativeArchitectures")
|
|
14
|
+
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
def isNewArchitectureEnabled() {
|
|
18
|
+
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
apply plugin: "com.android.library"
|
|
22
|
+
apply plugin: 'org.jetbrains.kotlin.android'
|
|
23
|
+
apply from: '../nitrogen/generated/android/NitroStrokeText+autolinking.gradle'
|
|
24
|
+
apply from: "./fix-prefab.gradle"
|
|
25
|
+
|
|
26
|
+
if (isNewArchitectureEnabled()) {
|
|
27
|
+
apply plugin: "com.facebook.react"
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
def getExtOrDefault(name) {
|
|
31
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["NitroStrokeText_" + name]
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
def getExtOrIntegerDefault(name) {
|
|
35
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["NitroStrokeText_" + name]).toInteger()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
android {
|
|
39
|
+
namespace "com.margelo.nitro.stroketext"
|
|
40
|
+
|
|
41
|
+
ndkVersion getExtOrDefault("ndkVersion")
|
|
42
|
+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
43
|
+
|
|
44
|
+
defaultConfig {
|
|
45
|
+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
46
|
+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
47
|
+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
|
48
|
+
|
|
49
|
+
externalNativeBuild {
|
|
50
|
+
cmake {
|
|
51
|
+
cppFlags "-frtti -fexceptions -Wall -Wextra -fstack-protector-all"
|
|
52
|
+
arguments "-DANDROID_STL=c++_shared", "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
|
|
53
|
+
abiFilters (*reactNativeArchitectures())
|
|
54
|
+
|
|
55
|
+
buildTypes {
|
|
56
|
+
debug {
|
|
57
|
+
cppFlags "-O1 -g"
|
|
58
|
+
}
|
|
59
|
+
release {
|
|
60
|
+
cppFlags "-O2"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
externalNativeBuild {
|
|
68
|
+
cmake {
|
|
69
|
+
path "CMakeLists.txt"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
packagingOptions {
|
|
74
|
+
excludes = [
|
|
75
|
+
"META-INF",
|
|
76
|
+
"META-INF/**",
|
|
77
|
+
"**/libc++_shared.so",
|
|
78
|
+
"**/libNitroModules.so",
|
|
79
|
+
"**/libfbjni.so",
|
|
80
|
+
"**/libjsi.so",
|
|
81
|
+
"**/libfolly_json.so",
|
|
82
|
+
"**/libfolly_runtime.so",
|
|
83
|
+
"**/libglog.so",
|
|
84
|
+
"**/libhermes.so",
|
|
85
|
+
"**/libhermes-executor-debug.so",
|
|
86
|
+
"**/libhermes_executor.so",
|
|
87
|
+
"**/libreactnative.so",
|
|
88
|
+
"**/libreactnativejni.so",
|
|
89
|
+
"**/libturbomodulejsijni.so",
|
|
90
|
+
"**/libreact_nativemodule_core.so",
|
|
91
|
+
"**/libjscexecutor.so"
|
|
92
|
+
]
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
buildFeatures {
|
|
96
|
+
buildConfig true
|
|
97
|
+
prefab true
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
buildTypes {
|
|
101
|
+
release {
|
|
102
|
+
minifyEnabled false
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
lintOptions {
|
|
107
|
+
disable "GradleCompatible"
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
compileOptions {
|
|
111
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
112
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
sourceSets {
|
|
116
|
+
main {
|
|
117
|
+
if (isNewArchitectureEnabled()) {
|
|
118
|
+
java.srcDirs += [
|
|
119
|
+
// React Codegen files
|
|
120
|
+
"${project.buildDir}/generated/source/codegen/java"
|
|
121
|
+
]
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
repositories {
|
|
128
|
+
mavenCentral()
|
|
129
|
+
google()
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
dependencies {
|
|
134
|
+
// For < 0.71, this will be from the local maven repo
|
|
135
|
+
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
|
|
136
|
+
//noinspection GradleDynamicVersion
|
|
137
|
+
implementation "com.facebook.react:react-native:+"
|
|
138
|
+
|
|
139
|
+
// Add a dependency on NitroModules
|
|
140
|
+
implementation project(":react-native-nitro-modules")
|
|
141
|
+
}
|
|
142
|
+
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
tasks.configureEach { task ->
|
|
2
|
+
// Make sure that we generate our prefab publication file only after having built the native library
|
|
3
|
+
// so that not a header publication file, but a full configuration publication will be generated, which
|
|
4
|
+
// will include the .so file
|
|
5
|
+
|
|
6
|
+
def prefabConfigurePattern = ~/^prefab(.+)ConfigurePackage$/
|
|
7
|
+
def matcher = task.name =~ prefabConfigurePattern
|
|
8
|
+
if (matcher.matches()) {
|
|
9
|
+
def variantName = matcher[0][1]
|
|
10
|
+
task.outputs.upToDateWhen { false }
|
|
11
|
+
task.dependsOn("externalNativeBuild${variantName}")
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
afterEvaluate {
|
|
16
|
+
def abis = reactNativeArchitectures()
|
|
17
|
+
rootProject.allprojects.each { proj ->
|
|
18
|
+
if (proj === rootProject) return
|
|
19
|
+
|
|
20
|
+
def dependsOnThisLib = proj.configurations.findAll { it.canBeResolved }.any { config ->
|
|
21
|
+
config.dependencies.any { dep ->
|
|
22
|
+
dep.group == project.group && dep.name == project.name
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (!dependsOnThisLib && proj != project) return
|
|
26
|
+
|
|
27
|
+
if (!proj.plugins.hasPlugin('com.android.application') && !proj.plugins.hasPlugin('com.android.library')) {
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
def variants = proj.android.hasProperty('applicationVariants') ? proj.android.applicationVariants : proj.android.libraryVariants
|
|
32
|
+
// Touch the prefab_config.json files to ensure that in ExternalNativeJsonGenerator.kt we will re-trigger the prefab CLI to
|
|
33
|
+
// generate a libnameConfig.cmake file that will contain our native library (.so).
|
|
34
|
+
// See this condition: https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:build-system/gradle-core/src/main/java/com/android/build/gradle/tasks/ExternalNativeJsonGenerator.kt;l=207-219?q=createPrefabBuildSystemGlue
|
|
35
|
+
variants.all { variant ->
|
|
36
|
+
def variantName = variant.name
|
|
37
|
+
abis.each { abi ->
|
|
38
|
+
def searchDir = new File(proj.projectDir, ".cxx/${variantName}")
|
|
39
|
+
if (!searchDir.exists()) return
|
|
40
|
+
def matches = []
|
|
41
|
+
searchDir.eachDir { randomDir ->
|
|
42
|
+
def prefabFile = new File(randomDir, "${abi}/prefab_config.json")
|
|
43
|
+
if (prefabFile.exists()) matches << prefabFile
|
|
44
|
+
}
|
|
45
|
+
matches.each { prefabConfig ->
|
|
46
|
+
prefabConfig.setLastModified(System.currentTimeMillis())
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
package com.margelo.nitro.stroketext
|
|
2
|
+
|
|
3
|
+
import android.view.View
|
|
4
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
5
|
+
|
|
6
|
+
class HybridStrokeTextView(context: ThemedReactContext) : HybridStrokeTextViewSpec() {
|
|
7
|
+
private val strokeTextView = StrokeTextView(context)
|
|
8
|
+
override val view: View = strokeTextView
|
|
9
|
+
|
|
10
|
+
override var text: String = ""
|
|
11
|
+
override var color: String? = null
|
|
12
|
+
override var strokeColor: String? = null
|
|
13
|
+
override var strokeWidth: Double? = null
|
|
14
|
+
override var fontSize: Double? = null
|
|
15
|
+
override var fontWeight: String? = null
|
|
16
|
+
override var fontFamily: String? = null
|
|
17
|
+
override var fontStyle: StrokeTextFontStyle? = null
|
|
18
|
+
override var lineHeight: Double? = null
|
|
19
|
+
override var letterSpacing: Double? = null
|
|
20
|
+
override var textAlign: StrokeTextAlign? = null
|
|
21
|
+
override var textDecorationLine: StrokeTextDecorationLine? = null
|
|
22
|
+
override var textTransform: StrokeTextTransform? = null
|
|
23
|
+
override var opacity: Double? = null
|
|
24
|
+
override var allowFontScaling: Boolean? = null
|
|
25
|
+
override var maxFontSizeMultiplier: Double? = null
|
|
26
|
+
override var includeFontPadding: Boolean? = null
|
|
27
|
+
override var numberOfLines: Double? = null
|
|
28
|
+
override var ellipsizeMode: StrokeTextEllipsizeMode? = null
|
|
29
|
+
override var padding: Double? = null
|
|
30
|
+
override var paddingVertical: Double? = null
|
|
31
|
+
override var paddingHorizontal: Double? = null
|
|
32
|
+
override var paddingTop: Double? = null
|
|
33
|
+
override var paddingRight: Double? = null
|
|
34
|
+
override var paddingBottom: Double? = null
|
|
35
|
+
override var paddingLeft: Double? = null
|
|
36
|
+
|
|
37
|
+
override fun afterUpdate() {
|
|
38
|
+
val displayMetrics = strokeTextView.resources.displayMetrics
|
|
39
|
+
val resolvedAllowFontScaling = allowFontScaling ?: true
|
|
40
|
+
val resolvedMaxFontSizeMultiplier =
|
|
41
|
+
maxFontSizeMultiplier
|
|
42
|
+
?.toFloat()
|
|
43
|
+
?.takeIf { it.isFinite() && it >= 1f }
|
|
44
|
+
|
|
45
|
+
strokeTextView.rawText = text
|
|
46
|
+
|
|
47
|
+
strokeTextView.color =
|
|
48
|
+
StrokeTextView.parseColor(color) ?: strokeTextView.resolvedDefaultTextColor()
|
|
49
|
+
strokeTextView.strokeColor = StrokeTextView.parseColor(strokeColor) ?: android.graphics.Color.TRANSPARENT
|
|
50
|
+
val resolvedStrokeWidth = (strokeWidth ?: 0.0).coerceAtLeast(0.0)
|
|
51
|
+
strokeTextView.strokeWidthDp = resolvedStrokeWidth
|
|
52
|
+
strokeTextView.strokeWidthPx =
|
|
53
|
+
StrokeTextView.dpToPx(
|
|
54
|
+
resolvedStrokeWidth.toFloat(),
|
|
55
|
+
displayMetrics,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
strokeTextView.fontSizePx =
|
|
59
|
+
StrokeTextView.textToPx(
|
|
60
|
+
fontSize ?: 14.0,
|
|
61
|
+
resolvedAllowFontScaling,
|
|
62
|
+
resolvedMaxFontSizeMultiplier,
|
|
63
|
+
displayMetrics,
|
|
64
|
+
)
|
|
65
|
+
strokeTextView.fontWeight = fontWeight
|
|
66
|
+
strokeTextView.fontFamily = fontFamily
|
|
67
|
+
strokeTextView.fontStyle = fontStyle ?: StrokeTextFontStyle.NORMAL
|
|
68
|
+
strokeTextView.lineHeightPx =
|
|
69
|
+
lineHeight?.let {
|
|
70
|
+
StrokeTextView.textToPx(
|
|
71
|
+
it,
|
|
72
|
+
resolvedAllowFontScaling,
|
|
73
|
+
resolvedMaxFontSizeMultiplier,
|
|
74
|
+
displayMetrics,
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
strokeTextView.letterSpacingPx =
|
|
78
|
+
letterSpacing?.let {
|
|
79
|
+
StrokeTextView.textToPx(
|
|
80
|
+
it,
|
|
81
|
+
resolvedAllowFontScaling,
|
|
82
|
+
resolvedMaxFontSizeMultiplier,
|
|
83
|
+
displayMetrics,
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
strokeTextView.textAlign = textAlign ?: StrokeTextAlign.AUTO
|
|
88
|
+
strokeTextView.textDecorationLine = textDecorationLine ?: StrokeTextDecorationLine.NONE
|
|
89
|
+
strokeTextView.textTransform = textTransform ?: StrokeTextTransform.NONE
|
|
90
|
+
|
|
91
|
+
strokeTextView.includeFontPadding = includeFontPadding ?: false
|
|
92
|
+
strokeTextView.numberOfLines = (numberOfLines ?: 0.0).toInt()
|
|
93
|
+
strokeTextView.ellipsizeMode = ellipsizeMode
|
|
94
|
+
|
|
95
|
+
strokeTextView.paddingAllPx = padding?.let { StrokeTextView.dpToPx(it.toFloat(), displayMetrics) }
|
|
96
|
+
strokeTextView.paddingVerticalPx = paddingVertical?.let { StrokeTextView.dpToPx(it.toFloat(), displayMetrics) }
|
|
97
|
+
strokeTextView.paddingHorizontalPx = paddingHorizontal?.let { StrokeTextView.dpToPx(it.toFloat(), displayMetrics) }
|
|
98
|
+
strokeTextView.paddingTopPx = paddingTop?.let { StrokeTextView.dpToPx(it.toFloat(), displayMetrics) }
|
|
99
|
+
strokeTextView.paddingRightPx = paddingRight?.let { StrokeTextView.dpToPx(it.toFloat(), displayMetrics) }
|
|
100
|
+
strokeTextView.paddingBottomPx = paddingBottom?.let { StrokeTextView.dpToPx(it.toFloat(), displayMetrics) }
|
|
101
|
+
strokeTextView.paddingLeftPx = paddingLeft?.let { StrokeTextView.dpToPx(it.toFloat(), displayMetrics) }
|
|
102
|
+
|
|
103
|
+
strokeTextView.alpha = (opacity ?: 1.0).toFloat()
|
|
104
|
+
|
|
105
|
+
strokeTextView.invalidateTextLayout()
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
package com.margelo.nitro.stroketext
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.NativeModule
|
|
4
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
5
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
6
|
+
import com.facebook.react.BaseReactPackage
|
|
7
|
+
import com.facebook.react.ViewManagerOnDemandReactPackage
|
|
8
|
+
import com.facebook.react.bridge.ModuleSpec
|
|
9
|
+
import com.facebook.react.uimanager.ViewManager
|
|
10
|
+
import com.margelo.nitro.stroketext.views.HybridStrokeTextViewManager
|
|
11
|
+
|
|
12
|
+
class NitroStrokeTextPackage : BaseReactPackage(), ViewManagerOnDemandReactPackage {
|
|
13
|
+
private val viewManagers: Map<String, ModuleSpec> by lazy {
|
|
14
|
+
mapOf(
|
|
15
|
+
"StrokeTextView" to ModuleSpec.viewManagerSpec { HybridStrokeTextViewManager() }
|
|
16
|
+
)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? = null
|
|
20
|
+
|
|
21
|
+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider = ReactModuleInfoProvider { HashMap() }
|
|
22
|
+
|
|
23
|
+
override fun getViewManagers(reactContext: ReactApplicationContext): List<ModuleSpec> {
|
|
24
|
+
return viewManagers.values.toList()
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
override fun getViewManagerNames(reactContext: ReactApplicationContext): Collection<String> {
|
|
28
|
+
return viewManagers.keys
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
override fun createViewManager(reactContext: ReactApplicationContext, viewManagerName: String) =
|
|
32
|
+
viewManagers[viewManagerName]?.provider?.get() as? ViewManager<*, *>
|
|
33
|
+
|
|
34
|
+
companion object {
|
|
35
|
+
init {
|
|
36
|
+
NitroStrokeTextOnLoad.initializeNative()
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|