@onekeyfe/react-native-text 3.0.108

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.
Files changed (35) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +17 -0
  3. package/android/build.gradle +109 -0
  4. package/android/gradle.properties +5 -0
  5. package/android/src/main/AndroidManifest.xml +3 -0
  6. package/android/src/main/AndroidManifestNew.xml +2 -0
  7. package/android/src/main/java/com/onekey/text/OneKeyTextPackage.kt +21 -0
  8. package/android/src/main/java/com/onekey/text/OneKeyTextView.kt +6 -0
  9. package/android/src/main/java/com/onekey/text/OneKeyTextViewManager.kt +34 -0
  10. package/android/src/main/jni/CMakeLists.txt +31 -0
  11. package/android/src/main/jni/react/renderer/components/RNOneKeyTextSpec/ComponentDescriptors.h +45 -0
  12. package/lib/module/OneKeyTextNativeComponent.ts +100 -0
  13. package/lib/module/OneKeyTextNativeHost.js +35 -0
  14. package/lib/module/Text.android.js +335 -0
  15. package/lib/module/Text.js +5 -0
  16. package/lib/module/codegen-types.d.js +2 -0
  17. package/lib/module/index.js +5 -0
  18. package/lib/module/package.json +1 -0
  19. package/lib/module/types.js +4 -0
  20. package/lib/typescript/package.json +1 -0
  21. package/lib/typescript/src/OneKeyTextNativeComponent.d.ts +47 -0
  22. package/lib/typescript/src/OneKeyTextNativeHost.d.ts +32 -0
  23. package/lib/typescript/src/Text.android.d.ts +79 -0
  24. package/lib/typescript/src/Text.d.ts +6 -0
  25. package/lib/typescript/src/index.d.ts +4 -0
  26. package/lib/typescript/src/types.d.ts +3 -0
  27. package/package.json +118 -0
  28. package/react-native.config.js +13 -0
  29. package/src/OneKeyTextNativeComponent.ts +100 -0
  30. package/src/OneKeyTextNativeHost.ts +40 -0
  31. package/src/Text.android.tsx +475 -0
  32. package/src/Text.tsx +3 -0
  33. package/src/codegen-types.d.ts +39 -0
  34. package/src/index.ts +4 -0
  35. package/src/types.ts +3 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 @onekeyfe
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.
package/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # @onekeyfe/react-native-text
2
+
3
+ A React Native `Text`-compatible component with an Android text-clipping guard.
4
+
5
+ ```tsx
6
+ import { Text } from '@onekeyfe/react-native-text';
7
+
8
+ <Text numberOfLines={1} style={{ fontSize: 16 }}>
9
+ Auto
10
+ </Text>;
11
+ ```
12
+
13
+ On Android, root text uses the React Native Paragraph/`ReactTextView` stack and
14
+ adds one physical pixel to intrinsic width when constraints permit. Nested text,
15
+ selection, ellipsizing, text-layout callbacks, press handling, accessibility,
16
+ and refs retain React Native `Text` semantics. Other platforms export React
17
+ Native `Text` directly.
@@ -0,0 +1,109 @@
1
+ buildscript {
2
+ def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["OneKeyText_kotlinVersion"]
3
+
4
+ repositories {
5
+ google()
6
+ mavenCentral()
7
+ }
8
+
9
+ dependencies {
10
+ classpath "com.android.tools.build:gradle:8.7.2"
11
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
12
+ }
13
+ }
14
+
15
+ def isNewArchitectureEnabled() {
16
+ return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
17
+ }
18
+
19
+ apply plugin: "com.android.library"
20
+ apply plugin: "kotlin-android"
21
+
22
+ if (isNewArchitectureEnabled()) {
23
+ apply plugin: "com.facebook.react"
24
+ }
25
+
26
+ def getExtOrDefault(name) {
27
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["OneKeyText_" + name]
28
+ }
29
+
30
+ def getExtOrIntegerDefault(name) {
31
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["OneKeyText_" + name]).toInteger()
32
+ }
33
+
34
+ def supportsNamespace() {
35
+ def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
36
+ def major = parsed[0].toInteger()
37
+ def minor = parsed[1].toInteger()
38
+ return (major == 7 && minor >= 3) || major >= 8
39
+ }
40
+
41
+ android {
42
+ if (supportsNamespace()) {
43
+ namespace "com.onekey.text"
44
+
45
+ sourceSets {
46
+ main {
47
+ manifest.srcFile "src/main/AndroidManifestNew.xml"
48
+ }
49
+ }
50
+ }
51
+
52
+ compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
53
+
54
+ defaultConfig {
55
+ minSdkVersion getExtOrIntegerDefault("minSdkVersion")
56
+ targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
57
+ buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
58
+ }
59
+
60
+ buildFeatures {
61
+ buildConfig true
62
+ }
63
+
64
+ buildTypes {
65
+ release {
66
+ minifyEnabled false
67
+ }
68
+ }
69
+
70
+ lintOptions {
71
+ disable "GradleCompatible"
72
+ }
73
+
74
+ compileOptions {
75
+ sourceCompatibility JavaVersion.VERSION_1_8
76
+ targetCompatibility JavaVersion.VERSION_1_8
77
+ }
78
+
79
+ sourceSets {
80
+ main {
81
+ if (isNewArchitectureEnabled()) {
82
+ java.srcDirs += [
83
+ "generated/java",
84
+ "generated/jni"
85
+ ]
86
+ }
87
+ }
88
+ }
89
+ }
90
+
91
+ repositories {
92
+ google()
93
+ mavenCentral()
94
+ }
95
+
96
+ def kotlin_version = getExtOrDefault("kotlinVersion")
97
+
98
+ dependencies {
99
+ implementation "com.facebook.react:react-android"
100
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
101
+ }
102
+
103
+ if (isNewArchitectureEnabled()) {
104
+ react {
105
+ jsRootDir = file("../src/")
106
+ libraryName = "RNOneKeyTextSpec"
107
+ codegenJavaPackageName = "com.onekey.text"
108
+ }
109
+ }
@@ -0,0 +1,5 @@
1
+ OneKeyText_kotlinVersion=2.1.20
2
+ OneKeyText_minSdkVersion=24
3
+ OneKeyText_targetSdkVersion=36
4
+ OneKeyText_compileSdkVersion=36
5
+ OneKeyText_ndkversion=27.1.12297006
@@ -0,0 +1,3 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
+ package="com.onekey.text">
3
+ </manifest>
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>
@@ -0,0 +1,21 @@
1
+ package com.onekey.text
2
+
3
+ import com.facebook.react.BaseReactPackage
4
+ import com.facebook.react.bridge.NativeModule
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.module.model.ReactModuleInfoProvider
7
+ import com.facebook.react.uimanager.ViewManager
8
+
9
+ class OneKeyTextPackage : BaseReactPackage() {
10
+ override fun getModule(
11
+ name: String,
12
+ reactContext: ReactApplicationContext
13
+ ): NativeModule? = null
14
+
15
+ override fun getReactModuleInfoProvider(): ReactModuleInfoProvider =
16
+ ReactModuleInfoProvider { HashMap() }
17
+
18
+ override fun createViewManagers(
19
+ reactContext: ReactApplicationContext
20
+ ): List<ViewManager<*, *>> = listOf(OneKeyTextViewManager())
21
+ }
@@ -0,0 +1,6 @@
1
+ package com.onekey.text
2
+
3
+ import android.content.Context
4
+ import com.facebook.react.views.text.ReactTextView
5
+
6
+ class OneKeyTextView(context: Context) : ReactTextView(context)
@@ -0,0 +1,34 @@
1
+ package com.onekey.text
2
+
3
+ import com.facebook.react.module.annotations.ReactModule
4
+ import com.facebook.react.uimanager.ReactStylesDiffMap
5
+ import com.facebook.react.uimanager.StateWrapper
6
+ import com.facebook.react.uimanager.ThemedReactContext
7
+ import com.facebook.react.views.text.ReactTextView
8
+ import com.facebook.react.views.text.ReactTextViewManager
9
+
10
+ @ReactModule(name = OneKeyTextViewManager.REACT_CLASS)
11
+ class OneKeyTextViewManager : ReactTextViewManager() {
12
+ override fun getName(): String = REACT_CLASS
13
+
14
+ override fun createViewInstance(context: ThemedReactContext): ReactTextView =
15
+ OneKeyTextView(context)
16
+
17
+ override fun updateState(
18
+ view: ReactTextView,
19
+ props: ReactStylesDiffMap,
20
+ stateWrapper: StateWrapper,
21
+ ): Any? {
22
+ val stateMapBuffer = stateWrapper.stateDataMapBuffer
23
+ // Fabric preallocation sends a default state for custom component names.
24
+ // Real Paragraph state, including empty text, always contains serialized keys.
25
+ if (stateMapBuffer != null && stateMapBuffer.count == 0) {
26
+ return null
27
+ }
28
+ return super.updateState(view, props, stateWrapper)
29
+ }
30
+
31
+ companion object {
32
+ const val REACT_CLASS = "OneKeyText"
33
+ }
34
+ }
@@ -0,0 +1,31 @@
1
+ cmake_minimum_required(VERSION 3.13)
2
+ set(CMAKE_VERBOSE_MAKEFILE ON)
3
+
4
+ set(LIB_TARGET_NAME react_codegen_RNOneKeyTextSpec)
5
+ set(LIB_ANDROID_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
6
+ set(LIB_GENERATED_JNI_DIR ${LIB_ANDROID_DIR}/build/generated/source/codegen/jni)
7
+
8
+ file(GLOB LIB_CODEGEN_SRCS CONFIGURE_DEPENDS ${LIB_GENERATED_JNI_DIR}/*.cpp)
9
+
10
+ add_library(
11
+ ${LIB_TARGET_NAME}
12
+ SHARED
13
+ ${LIB_CODEGEN_SRCS}
14
+ )
15
+
16
+ target_include_directories(
17
+ ${LIB_TARGET_NAME}
18
+ PUBLIC
19
+ .
20
+ ${LIB_GENERATED_JNI_DIR}
21
+ ${REACT_ANDROID_DIR}/../ReactCommon/react/renderer/components/text/platform/android
22
+ )
23
+
24
+ target_link_libraries(
25
+ ${LIB_TARGET_NAME}
26
+ fbjni
27
+ jsi
28
+ reactnative
29
+ )
30
+
31
+ target_compile_reactnative_options(${LIB_TARGET_NAME} PRIVATE)
@@ -0,0 +1,45 @@
1
+ #pragma once
2
+
3
+ #include <algorithm>
4
+
5
+ #include <react/renderer/components/text/BaseParagraphComponentDescriptor.h>
6
+ #include <react/renderer/components/text/ParagraphShadowNode.h>
7
+
8
+ namespace facebook::react {
9
+
10
+ class OneKeyTextShadowNode final : public ParagraphShadowNode {
11
+ public:
12
+ using ParagraphShadowNode::ParagraphShadowNode;
13
+
14
+ static constexpr ComponentName Name() {
15
+ return "OneKeyText";
16
+ }
17
+
18
+ static ComponentHandle Handle() {
19
+ return ComponentHandle(Name());
20
+ }
21
+
22
+ Size measureContent(
23
+ const LayoutContext &layoutContext,
24
+ const LayoutConstraints &layoutConstraints) const override {
25
+ auto size = ParagraphShadowNode::measureContent(
26
+ layoutContext, layoutConstraints);
27
+ if (size.width <= 0 || layoutContext.pointScaleFactor <= 0) {
28
+ return size;
29
+ }
30
+
31
+ const auto onePhysicalPixel = 1.0f / layoutContext.pointScaleFactor;
32
+ size.width = std::min(
33
+ size.width + onePhysicalPixel,
34
+ layoutConstraints.maximumSize.width);
35
+ return size;
36
+ }
37
+ };
38
+
39
+ class OneKeyTextComponentDescriptor final
40
+ : public BaseParagraphComponentDescriptor<OneKeyTextShadowNode> {
41
+ public:
42
+ using BaseParagraphComponentDescriptor::BaseParagraphComponentDescriptor;
43
+ };
44
+
45
+ } // namespace facebook::react
@@ -0,0 +1,100 @@
1
+ import {
2
+ codegenNativeComponent,
3
+ type ColorValue,
4
+ type HostComponent,
5
+ type ViewProps,
6
+ } from 'react-native';
7
+ import type {
8
+ DirectEventHandler,
9
+ Float,
10
+ Int32,
11
+ WithDefault,
12
+ } from 'react-native/Libraries/Types/CodegenTypes';
13
+
14
+ export interface NativeProps extends ViewProps {
15
+ adjustsFontSizeToFit?: WithDefault<boolean, false>;
16
+ allowFontScaling?: WithDefault<boolean, true>;
17
+ android_hyphenationFrequency?: WithDefault<
18
+ 'full' | 'none' | 'normal',
19
+ 'none'
20
+ >;
21
+ color?: ColorValue;
22
+ dataDetectorType?: WithDefault<
23
+ 'all' | 'email' | 'link' | 'none' | 'phoneNumber',
24
+ 'none'
25
+ >;
26
+ disabled?: WithDefault<boolean, false>;
27
+ dynamicTypeRamp?: WithDefault<
28
+ | 'body'
29
+ | 'callout'
30
+ | 'caption1'
31
+ | 'caption2'
32
+ | 'footnote'
33
+ | 'headline'
34
+ | 'largeTitle'
35
+ | 'subheadline'
36
+ | 'title1'
37
+ | 'title2'
38
+ | 'title3',
39
+ 'body'
40
+ >;
41
+ ellipsizeMode?: WithDefault<'clip' | 'head' | 'middle' | 'tail', 'tail'>;
42
+ fontFamily?: string;
43
+ fontSize?: Float;
44
+ fontStyle?: WithDefault<'italic' | 'normal', 'normal'>;
45
+ fontVariant?: ReadonlyArray<string>;
46
+ fontWeight?: string;
47
+ includeFontPadding?: WithDefault<boolean, true>;
48
+ isHighlighted?: WithDefault<boolean, false>;
49
+ isPressable?: WithDefault<boolean, false>;
50
+ letterSpacing?: Float;
51
+ lineBreakModeIOS?: WithDefault<
52
+ 'char' | 'clip' | 'head' | 'middle' | 'tail' | 'word',
53
+ 'tail'
54
+ >;
55
+ lineBreakStrategyIOS?: WithDefault<
56
+ 'hangul-word' | 'none' | 'push-out' | 'standard',
57
+ 'none'
58
+ >;
59
+ lineHeight?: Float;
60
+ maxFontSizeMultiplier?: Float;
61
+ minimumFontScale?: Float;
62
+ numberOfLines?: WithDefault<Int32, 0>;
63
+ // The native descriptor uses ParagraphEventEmitter to supply RN's line payload.
64
+ onTextLayout?: DirectEventHandler<Readonly<{}>>;
65
+ selectable?: WithDefault<boolean, false>;
66
+ selectionColor?: ColorValue;
67
+ textAlign?: WithDefault<
68
+ 'auto' | 'center' | 'justify' | 'left' | 'right',
69
+ 'auto'
70
+ >;
71
+ textAlignVertical?: WithDefault<'auto' | 'bottom' | 'center' | 'top', 'auto'>;
72
+ textBreakStrategy?: WithDefault<
73
+ 'balanced' | 'highQuality' | 'simple',
74
+ 'highQuality'
75
+ >;
76
+ textDecorationColor?: ColorValue;
77
+ textDecorationLine?: WithDefault<
78
+ 'line-through' | 'none' | 'underline' | 'underline line-through',
79
+ 'none'
80
+ >;
81
+ textDecorationStyle?: WithDefault<
82
+ 'dashed' | 'dotted' | 'double' | 'solid',
83
+ 'solid'
84
+ >;
85
+ textShadowColor?: ColorValue;
86
+ textShadowOffset?: Readonly<{
87
+ height: Float;
88
+ width: Float;
89
+ }>;
90
+ textShadowRadius?: Float;
91
+ textTransform?: WithDefault<
92
+ 'capitalize' | 'lowercase' | 'none' | 'uppercase',
93
+ 'none'
94
+ >;
95
+ writingDirection?: WithDefault<'auto' | 'ltr' | 'rtl', 'auto'>;
96
+ }
97
+
98
+ export default codegenNativeComponent<NativeProps>(
99
+ 'OneKeyText'
100
+ ) as HostComponent<NativeProps>;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ /* eslint-disable @react-native/no-deep-imports */
4
+ import { createViewConfig } from 'react-native/Libraries/NativeComponent/ViewConfig';
5
+ import createReactNativeComponentClass from 'react-native/Libraries/Renderer/shims/createReactNativeComponentClass';
6
+ export const ONEKEY_TEXT_VIEW_CONFIG = {
7
+ validAttributes: {
8
+ isHighlighted: true,
9
+ isPressable: true,
10
+ numberOfLines: true,
11
+ ellipsizeMode: true,
12
+ allowFontScaling: true,
13
+ dynamicTypeRamp: true,
14
+ maxFontSizeMultiplier: true,
15
+ disabled: true,
16
+ selectable: true,
17
+ selectionColor: true,
18
+ adjustsFontSizeToFit: true,
19
+ minimumFontScale: true,
20
+ textBreakStrategy: true,
21
+ onTextLayout: true,
22
+ dataDetectorType: true,
23
+ android_hyphenationFrequency: true,
24
+ lineBreakStrategyIOS: true
25
+ },
26
+ directEventTypes: {
27
+ topTextLayout: {
28
+ registrationName: 'onTextLayout'
29
+ }
30
+ },
31
+ uiViewClassName: 'OneKeyText'
32
+ };
33
+ const OneKeyTextNativeHost = createReactNativeComponentClass('OneKeyText', () => createViewConfig(ONEKEY_TEXT_VIEW_CONFIG));
34
+ export default OneKeyTextNativeHost;
35
+ //# sourceMappingURL=OneKeyTextNativeHost.js.map