@domir/react-native-measure-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.
Files changed (139) hide show
  1. package/.eslintrc.js +5 -0
  2. package/LICENSE +21 -0
  3. package/Readme.md +46 -0
  4. package/android/build.gradle +93 -0
  5. package/android/src/main/AndroidManifest.xml +2 -0
  6. package/android/src/main/java/expo/modules.measuretext/ReactNativeMeasureTextModule.kt +51 -0
  7. package/build/ReactNativeMeasureText.d.ts +6 -0
  8. package/build/ReactNativeMeasureText.d.ts.map +1 -0
  9. package/build/ReactNativeMeasureText.js +5 -0
  10. package/build/ReactNativeMeasureText.js.map +1 -0
  11. package/build/ReactNativeMeasureText.types.d.ts +4 -0
  12. package/build/ReactNativeMeasureText.types.d.ts.map +1 -0
  13. package/build/ReactNativeMeasureText.types.js +2 -0
  14. package/build/ReactNativeMeasureText.types.js.map +1 -0
  15. package/build/ReactNativeMeasureTextModule.d.ts +3 -0
  16. package/build/ReactNativeMeasureTextModule.d.ts.map +1 -0
  17. package/build/ReactNativeMeasureTextModule.js +5 -0
  18. package/build/ReactNativeMeasureTextModule.js.map +1 -0
  19. package/build/ReactNativeMeasureTextModule.web.d.ts +5 -0
  20. package/build/ReactNativeMeasureTextModule.web.d.ts.map +1 -0
  21. package/build/ReactNativeMeasureTextModule.web.js +6 -0
  22. package/build/ReactNativeMeasureTextModule.web.js.map +1 -0
  23. package/example/.expo-shared/assets.json +4 -0
  24. package/example/App.tsx +45 -0
  25. package/example/android/app/BUCK +55 -0
  26. package/example/android/app/build.gradle +376 -0
  27. package/example/android/app/build_defs.bzl +19 -0
  28. package/example/android/app/debug.keystore +0 -0
  29. package/example/android/app/proguard-rules.pro +14 -0
  30. package/example/android/app/src/debug/AndroidManifest.xml +7 -0
  31. package/example/android/app/src/debug/java/expo/modules/measuretext/example/ReactNativeFlipper.java +69 -0
  32. package/example/android/app/src/main/AndroidManifest.xml +34 -0
  33. package/example/android/app/src/main/java/expo/modules/measuretext/example/MainActivity.java +83 -0
  34. package/example/android/app/src/main/java/expo/modules/measuretext/example/MainApplication.java +106 -0
  35. package/example/android/app/src/main/java/expo/modules/measuretext/example/newarchitecture/MainApplicationReactNativeHost.java +117 -0
  36. package/example/android/app/src/main/java/expo/modules/measuretext/example/newarchitecture/components/MainComponentsRegistry.java +36 -0
  37. package/example/android/app/src/main/java/expo/modules/measuretext/example/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate.java +48 -0
  38. package/example/android/app/src/main/jni/Android.mk +48 -0
  39. package/example/android/app/src/main/jni/MainApplicationModuleProvider.cpp +24 -0
  40. package/example/android/app/src/main/jni/MainApplicationModuleProvider.h +16 -0
  41. package/example/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.cpp +45 -0
  42. package/example/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.h +38 -0
  43. package/example/android/app/src/main/jni/MainComponentsRegistry.cpp +61 -0
  44. package/example/android/app/src/main/jni/MainComponentsRegistry.h +32 -0
  45. package/example/android/app/src/main/jni/OnLoad.cpp +11 -0
  46. package/example/android/app/src/main/res/drawable/rn_edit_text_material.xml +36 -0
  47. package/example/android/app/src/main/res/drawable/splashscreen.xml +3 -0
  48. package/example/android/app/src/main/res/drawable-hdpi/splashscreen_image.png +0 -0
  49. package/example/android/app/src/main/res/drawable-mdpi/splashscreen_image.png +0 -0
  50. package/example/android/app/src/main/res/drawable-xhdpi/splashscreen_image.png +0 -0
  51. package/example/android/app/src/main/res/drawable-xxhdpi/splashscreen_image.png +0 -0
  52. package/example/android/app/src/main/res/drawable-xxxhdpi/splashscreen_image.png +0 -0
  53. package/example/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +5 -0
  54. package/example/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +5 -0
  55. package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
  56. package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png +0 -0
  57. package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
  58. package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
  59. package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png +0 -0
  60. package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
  61. package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
  62. package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png +0 -0
  63. package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
  64. package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
  65. package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png +0 -0
  66. package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
  67. package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
  68. package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png +0 -0
  69. package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
  70. package/example/android/app/src/main/res/values/colors.xml +6 -0
  71. package/example/android/app/src/main/res/values/strings.xml +5 -0
  72. package/example/android/app/src/main/res/values/styles.xml +17 -0
  73. package/example/android/app/src/main/res/values-night/colors.xml +1 -0
  74. package/example/android/build.gradle +59 -0
  75. package/example/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  76. package/example/android/gradle/wrapper/gradle-wrapper.properties +5 -0
  77. package/example/android/gradle.properties +53 -0
  78. package/example/android/gradlew +234 -0
  79. package/example/android/gradlew.bat +89 -0
  80. package/example/android/settings.gradle +17 -0
  81. package/example/app.json +35 -0
  82. package/example/assets/adaptive-icon.png +0 -0
  83. package/example/assets/favicon.png +0 -0
  84. package/example/assets/icon.png +0 -0
  85. package/example/assets/splash.png +0 -0
  86. package/example/babel.config.js +19 -0
  87. package/example/index.js +8 -0
  88. package/example/ios/.xcode.env +11 -0
  89. package/example/ios/Podfile +59 -0
  90. package/example/ios/Podfile.lock +482 -0
  91. package/example/ios/Podfile.properties.json +3 -0
  92. package/example/ios/reactnativemeasuretextexample/AppDelegate.h +9 -0
  93. package/example/ios/reactnativemeasuretextexample/AppDelegate.mm +166 -0
  94. package/example/ios/reactnativemeasuretextexample/Images.xcassets/AppIcon.appiconset/App-Icon-20x20@1x.png +0 -0
  95. package/example/ios/reactnativemeasuretextexample/Images.xcassets/AppIcon.appiconset/App-Icon-20x20@2x.png +0 -0
  96. package/example/ios/reactnativemeasuretextexample/Images.xcassets/AppIcon.appiconset/App-Icon-20x20@3x.png +0 -0
  97. package/example/ios/reactnativemeasuretextexample/Images.xcassets/AppIcon.appiconset/App-Icon-29x29@1x.png +0 -0
  98. package/example/ios/reactnativemeasuretextexample/Images.xcassets/AppIcon.appiconset/App-Icon-29x29@2x.png +0 -0
  99. package/example/ios/reactnativemeasuretextexample/Images.xcassets/AppIcon.appiconset/App-Icon-29x29@3x.png +0 -0
  100. package/example/ios/reactnativemeasuretextexample/Images.xcassets/AppIcon.appiconset/App-Icon-40x40@1x.png +0 -0
  101. package/example/ios/reactnativemeasuretextexample/Images.xcassets/AppIcon.appiconset/App-Icon-40x40@2x.png +0 -0
  102. package/example/ios/reactnativemeasuretextexample/Images.xcassets/AppIcon.appiconset/App-Icon-40x40@3x.png +0 -0
  103. package/example/ios/reactnativemeasuretextexample/Images.xcassets/AppIcon.appiconset/App-Icon-60x60@2x.png +0 -0
  104. package/example/ios/reactnativemeasuretextexample/Images.xcassets/AppIcon.appiconset/App-Icon-60x60@3x.png +0 -0
  105. package/example/ios/reactnativemeasuretextexample/Images.xcassets/AppIcon.appiconset/App-Icon-76x76@1x.png +0 -0
  106. package/example/ios/reactnativemeasuretextexample/Images.xcassets/AppIcon.appiconset/App-Icon-76x76@2x.png +0 -0
  107. package/example/ios/reactnativemeasuretextexample/Images.xcassets/AppIcon.appiconset/App-Icon-83.5x83.5@2x.png +0 -0
  108. package/example/ios/reactnativemeasuretextexample/Images.xcassets/AppIcon.appiconset/Contents.json +122 -0
  109. package/example/ios/reactnativemeasuretextexample/Images.xcassets/AppIcon.appiconset/ItunesArtwork@2x.png +0 -0
  110. package/example/ios/reactnativemeasuretextexample/Images.xcassets/Contents.json +6 -0
  111. package/example/ios/reactnativemeasuretextexample/Images.xcassets/SplashScreen.imageset/Contents.json +21 -0
  112. package/example/ios/reactnativemeasuretextexample/Images.xcassets/SplashScreen.imageset/image.png +0 -0
  113. package/example/ios/reactnativemeasuretextexample/Images.xcassets/SplashScreenBackground.imageset/Contents.json +21 -0
  114. package/example/ios/reactnativemeasuretextexample/Images.xcassets/SplashScreenBackground.imageset/image.png +0 -0
  115. package/example/ios/reactnativemeasuretextexample/Info.plist +76 -0
  116. package/example/ios/reactnativemeasuretextexample/SplashScreen.storyboard +51 -0
  117. package/example/ios/reactnativemeasuretextexample/Supporting/Expo.plist +16 -0
  118. package/example/ios/reactnativemeasuretextexample/main.m +10 -0
  119. package/example/ios/reactnativemeasuretextexample/noop-file.swift +4 -0
  120. package/example/ios/reactnativemeasuretextexample/reactnativemeasuretextexample.entitlements +8 -0
  121. package/example/ios/reactnativemeasuretextexample.xcodeproj/project.pbxproj +497 -0
  122. package/example/ios/reactnativemeasuretextexample.xcodeproj/xcshareddata/xcschemes/reactnativemeasuretextexample.xcscheme +88 -0
  123. package/example/ios/reactnativemeasuretextexample.xcworkspace/contents.xcworkspacedata +10 -0
  124. package/example/ios/reactnativemeasuretextexample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  125. package/example/metro.config.js +14 -0
  126. package/example/package-lock.json +21620 -0
  127. package/example/package.json +29 -0
  128. package/example/tsconfig.json +10 -0
  129. package/example/webpack.config.js +20 -0
  130. package/example/yarn.lock +6664 -0
  131. package/expo-module.config.json +9 -0
  132. package/ios/ReactNativeMeasureText.podspec +32 -0
  133. package/ios/ReactNativeMeasureTextModule.swift +33 -0
  134. package/package.json +38 -0
  135. package/src/ReactNativeMeasureText.ts +8 -0
  136. package/src/ReactNativeMeasureText.types.ts +3 -0
  137. package/src/ReactNativeMeasureTextModule.ts +5 -0
  138. package/src/ReactNativeMeasureTextModule.web.ts +5 -0
  139. package/tsconfig.json +9 -0
package/.eslintrc.js ADDED
@@ -0,0 +1,5 @@
1
+ module.exports = {
2
+ root: true,
3
+ extends: ['universe/native', 'universe/web'],
4
+ ignorePatterns: ['build'],
5
+ };
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Dominique Rau
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,46 @@
1
+ # react-native-measure-text
2
+
3
+ Measure the size of a string of text in React Native synchronously.
4
+
5
+ This can be useful for calculating the size of a string of text before rendering it, for example for animation targets.
6
+
7
+ # API documentation
8
+
9
+ ### Add the package to your npm dependencies
10
+
11
+ ```
12
+ npm install @domir/react-native-measure-text
13
+ ```
14
+
15
+ ### Configure for iOS
16
+
17
+ Run `npx pod-install` after installing the npm package.
18
+
19
+
20
+ ### Configure for Android
21
+
22
+ No additional configuration is needed.
23
+
24
+ ### Usage
25
+
26
+ ```js
27
+ import * as MeasureText from '@domir/react-native-measure-text';
28
+
29
+ MeasureText.measureWidth('Hello World', {
30
+ fontSize: 20,
31
+ fontFamily: 'Helvetica',
32
+ fontWeight: 'normal',
33
+ // TBD
34
+ // fontStyle: 'normal',
35
+ // fontVariant: ['small-caps'],
36
+ // letterSpacing: 0,
37
+ // lineHeight: 20,
38
+ // textAlign: 'left',
39
+ // textDecorationLine: 'none',
40
+ // textTransform: 'none',
41
+ // includeFontPadding: true,
42
+ // maxWidth: 100,
43
+ // maxHeight: 100,
44
+ // numberOfLines: 1,
45
+ // ellipsizeMode: 'tail',
46
+ })
@@ -0,0 +1,93 @@
1
+ apply plugin: 'com.android.library'
2
+ apply plugin: 'kotlin-android'
3
+ apply plugin: 'kotlin-android-extensions'
4
+ apply plugin: 'maven-publish'
5
+
6
+ group = 'expo.modules.measuretext'
7
+ version = '0.1.0'
8
+
9
+ buildscript {
10
+ def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
11
+ if (expoModulesCorePlugin.exists()) {
12
+ apply from: expoModulesCorePlugin
13
+ applyKotlinExpoModulesCorePlugin()
14
+ }
15
+
16
+ // Simple helper that allows the root project to override versions declared by this library.
17
+ ext.safeExtGet = { prop, fallback ->
18
+ rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
19
+ }
20
+
21
+ // Ensures backward compatibility
22
+ ext.getKotlinVersion = {
23
+ if (ext.has("kotlinVersion")) {
24
+ ext.kotlinVersion()
25
+ } else {
26
+ ext.safeExtGet("kotlinVersion", "1.6.10")
27
+ }
28
+ }
29
+
30
+ repositories {
31
+ mavenCentral()
32
+ }
33
+
34
+ dependencies {
35
+ classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${getKotlinVersion()}")
36
+ }
37
+ }
38
+
39
+ // Creating sources with comments
40
+ task androidSourcesJar(type: Jar) {
41
+ classifier = 'sources'
42
+ from android.sourceSets.main.java.srcDirs
43
+ }
44
+
45
+ afterEvaluate {
46
+ publishing {
47
+ publications {
48
+ release(MavenPublication) {
49
+ from components.release
50
+ // Add additional sourcesJar to artifacts
51
+ artifact(androidSourcesJar)
52
+ }
53
+ }
54
+ repositories {
55
+ maven {
56
+ url = mavenLocal().url
57
+ }
58
+ }
59
+ }
60
+ }
61
+
62
+ android {
63
+ compileSdkVersion safeExtGet("compileSdkVersion", 31)
64
+
65
+ compileOptions {
66
+ sourceCompatibility JavaVersion.VERSION_11
67
+ targetCompatibility JavaVersion.VERSION_11
68
+ }
69
+
70
+ kotlinOptions {
71
+ jvmTarget = JavaVersion.VERSION_11.majorVersion
72
+ }
73
+
74
+ defaultConfig {
75
+ minSdkVersion safeExtGet("minSdkVersion", 21)
76
+ targetSdkVersion safeExtGet("targetSdkVersion", 31)
77
+ versionCode 1
78
+ versionName "0.1.0"
79
+ }
80
+ lintOptions {
81
+ abortOnError false
82
+ }
83
+ }
84
+
85
+ repositories {
86
+ mavenCentral()
87
+ }
88
+
89
+ dependencies {
90
+ implementation project(':expo-modules-core')
91
+ implementation "com.facebook.react:react-native:+"
92
+ implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
93
+ }
@@ -0,0 +1,2 @@
1
+ <manifest package="expo.modules.measuretext">
2
+ </manifest>
@@ -0,0 +1,51 @@
1
+ package expo.modules.measuretext
2
+
3
+ import android.R.attr.fontFamily
4
+ import android.R.attr.fontWeight
5
+ import android.graphics.Typeface
6
+ import android.text.TextPaint
7
+ import com.facebook.react.views.text.ReactFontManager
8
+ import com.facebook.react.views.text.ReactTypefaceUtils.parseFontWeight
9
+ import expo.modules.kotlin.modules.Module
10
+ import expo.modules.kotlin.modules.ModuleDefinition
11
+ import expo.modules.kotlin.records.Field
12
+ import expo.modules.kotlin.records.Record
13
+
14
+
15
+ class StyleOptions : Record {
16
+ @Field
17
+ val fontFamily: String? = null
18
+
19
+ @Field
20
+ val fontWeight: String? = null
21
+
22
+ @Field
23
+ val fontSize: Int? = null
24
+ }
25
+
26
+ class ReactNativeMeasureTextModule : Module() {
27
+ override fun definition() = ModuleDefinition {
28
+ Name("ReactNativeMeasureText")
29
+
30
+ Function("measureWidth") { text: String, style: StyleOptions ->
31
+ val paint = createTextPaint(style.fontSize, style.fontFamily, style.fontWeight);
32
+ return@Function paint.measureText(text);
33
+ }
34
+ }
35
+
36
+ private fun createTextPaint(fontSize: Int?, fontFamily: String?, fontWeight: String?): TextPaint {
37
+ val paint = TextPaint(TextPaint.ANTI_ALIAS_FLAG);
38
+ val fontScale = appContext.reactContext?.resources?.configuration?.fontScale ?: 1.0f;
39
+ val usedFontSize = (fontSize ?: 0) * fontScale;
40
+ paint.textSize = usedFontSize;
41
+ val assetManager = appContext.reactContext?.assets;
42
+
43
+ if (fontFamily == null || assetManager == null || fontWeight == null)
44
+ paint.typeface = Typeface.DEFAULT
45
+ } else {
46
+ paint.typeface ReactFontManager.getInstance().getTypeface(fontFamily, parseFontWeight(fontWeight), assetManager)
47
+ }
48
+
49
+ return paint;
50
+ }
51
+ }
@@ -0,0 +1,6 @@
1
+ export declare function measureWidth(text: string, style?: {
2
+ fontSize?: number;
3
+ fontFamily?: string;
4
+ fontWeight?: string;
5
+ }): number;
6
+ //# sourceMappingURL=ReactNativeMeasureText.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReactNativeMeasureText.d.ts","sourceRoot":"","sources":["../src/ReactNativeMeasureText.ts"],"names":[],"mappings":"AAEA,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,KAAK,GAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAO,GAC1E,MAAM,CAER"}
@@ -0,0 +1,5 @@
1
+ import ReactNativeMeasureText from "./ReactNativeMeasureTextModule";
2
+ export function measureWidth(text, style = {}) {
3
+ return ReactNativeMeasureText.measureWidth(text, style);
4
+ }
5
+ //# sourceMappingURL=ReactNativeMeasureText.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReactNativeMeasureText.js","sourceRoot":"","sources":["../src/ReactNativeMeasureText.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,MAAM,gCAAgC,CAAC;AAEpE,MAAM,UAAU,YAAY,CAC1B,IAAY,EACZ,QAAyE,EAAE;IAE3E,OAAO,sBAAsB,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAC1D,CAAC","sourcesContent":["import ReactNativeMeasureText from \"./ReactNativeMeasureTextModule\";\n\nexport function measureWidth(\n text: string,\n style: { fontSize?: number; fontFamily?: string; fontWeight?: string } = {}\n): number {\n return ReactNativeMeasureText.measureWidth(text, style);\n}\n"]}
@@ -0,0 +1,4 @@
1
+ export declare type ChangeEventPayload = {
2
+ value: string;
3
+ };
4
+ //# sourceMappingURL=ReactNativeMeasureText.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReactNativeMeasureText.types.d.ts","sourceRoot":"","sources":["../src/ReactNativeMeasureText.types.ts"],"names":[],"mappings":"AAAA,oBAAY,kBAAkB,GAAG;IAC/B,KAAK,EAAE,MAAM,CAAC;CACf,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ReactNativeMeasureText.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReactNativeMeasureText.types.js","sourceRoot":"","sources":["../src/ReactNativeMeasureText.types.ts"],"names":[],"mappings":"","sourcesContent":["export type ChangeEventPayload = {\n value: string;\n};\n"]}
@@ -0,0 +1,3 @@
1
+ declare const _default: any;
2
+ export default _default;
3
+ //# sourceMappingURL=ReactNativeMeasureTextModule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReactNativeMeasureTextModule.d.ts","sourceRoot":"","sources":["../src/ReactNativeMeasureTextModule.ts"],"names":[],"mappings":";AAIA,wBAA6D"}
@@ -0,0 +1,5 @@
1
+ import { requireNativeModule } from "expo-modules-core";
2
+ // It loads the native module object from the JSI or falls back to
3
+ // the bridge module (from NativeModulesProxy) if the remote debugger is on.
4
+ export default requireNativeModule("ReactNativeMeasureText");
5
+ //# sourceMappingURL=ReactNativeMeasureTextModule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReactNativeMeasureTextModule.js","sourceRoot":"","sources":["../src/ReactNativeMeasureTextModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,kEAAkE;AAClE,4EAA4E;AAC5E,eAAe,mBAAmB,CAAC,wBAAwB,CAAC,CAAC","sourcesContent":["import { requireNativeModule } from \"expo-modules-core\";\n\n// It loads the native module object from the JSI or falls back to\n// the bridge module (from NativeModulesProxy) if the remote debugger is on.\nexport default requireNativeModule(\"ReactNativeMeasureText\");\n"]}
@@ -0,0 +1,5 @@
1
+ declare const _default: {
2
+ measureWidth(): string;
3
+ };
4
+ export default _default;
5
+ //# sourceMappingURL=ReactNativeMeasureTextModule.web.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReactNativeMeasureTextModule.web.d.ts","sourceRoot":"","sources":["../src/ReactNativeMeasureTextModule.web.ts"],"names":[],"mappings":";;;AAAA,wBAIE"}
@@ -0,0 +1,6 @@
1
+ export default {
2
+ measureWidth() {
3
+ return "Hello world! 👋";
4
+ },
5
+ };
6
+ //# sourceMappingURL=ReactNativeMeasureTextModule.web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReactNativeMeasureTextModule.web.js","sourceRoot":"","sources":["../src/ReactNativeMeasureTextModule.web.ts"],"names":[],"mappings":"AAAA,eAAe;IACb,YAAY;QACV,OAAO,iBAAiB,CAAC;IAC3B,CAAC;CACF,CAAC","sourcesContent":["export default {\n measureWidth() {\n return \"Hello world! 👋\";\n },\n};\n"]}
@@ -0,0 +1,4 @@
1
+ {
2
+ "12bb71342c6255bbf50437ec8f4441c083f47cdb74bd89160c15e4f43e52a1cb": true,
3
+ "40b842e832070c58deac6aa9e08fa459302ee3f9da492c7e77d93d2fbf4a56fd": true
4
+ }
@@ -0,0 +1,45 @@
1
+ import { useState } from "react";
2
+ import { Button, StyleSheet, Text, View } from "react-native";
3
+ import * as ReactNativeMeasureText from "react-native-measure-text";
4
+
5
+ export default function App() {
6
+ const [widthResult, setWidthResult] = useState<number>(0);
7
+ const toMeasure = "Hello world!";
8
+ return (
9
+ <View style={styles.container}>
10
+ <Text>Result: {JSON.stringify(widthResult)}</Text>
11
+ <View
12
+ style={{ borderColor: "black", borderWidth: 1, width: widthResult + 1 }}
13
+ >
14
+ <Text style={{ fontSize: 20 }} numberOfLines={1} ellipsizeMode="clip">
15
+ {toMeasure}
16
+ </Text>
17
+ </View>
18
+ <Button
19
+ onPress={() => {
20
+ setWidthResult(
21
+ Math.ceil(
22
+ ReactNativeMeasureText.measureWidth({
23
+ text: toMeasure,
24
+ // fontSize: 20,
25
+ // fontFamily: 'Helvetica',
26
+ // fontWeight: 'normal',
27
+ // maxHeight: 100,
28
+ })
29
+ )
30
+ );
31
+ }}
32
+ title="Calc width"
33
+ />
34
+ </View>
35
+ );
36
+ }
37
+
38
+ const styles = StyleSheet.create({
39
+ container: {
40
+ flex: 1,
41
+ backgroundColor: "red",
42
+ alignItems: "center",
43
+ justifyContent: "center",
44
+ },
45
+ });
@@ -0,0 +1,55 @@
1
+ # To learn about Buck see [Docs](https://buckbuild.com/).
2
+ # To run your application with Buck:
3
+ # - install Buck
4
+ # - `npm start` - to start the packager
5
+ # - `cd android`
6
+ # - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"`
7
+ # - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck
8
+ # - `buck install -r android/app` - compile, install and run application
9
+ #
10
+
11
+ load(":build_defs.bzl", "create_aar_targets", "create_jar_targets")
12
+
13
+ lib_deps = []
14
+
15
+ create_aar_targets(glob(["libs/*.aar"]))
16
+
17
+ create_jar_targets(glob(["libs/*.jar"]))
18
+
19
+ android_library(
20
+ name = "all-libs",
21
+ exported_deps = lib_deps,
22
+ )
23
+
24
+ android_library(
25
+ name = "app-code",
26
+ srcs = glob([
27
+ "src/main/java/**/*.java",
28
+ ]),
29
+ deps = [
30
+ ":all-libs",
31
+ ":build_config",
32
+ ":res",
33
+ ],
34
+ )
35
+
36
+ android_build_config(
37
+ name = "build_config",
38
+ package = "expo.modules.measuretext.example",
39
+ )
40
+
41
+ android_resource(
42
+ name = "res",
43
+ package = "expo.modules.measuretext.example",
44
+ res = "src/main/res",
45
+ )
46
+
47
+ android_binary(
48
+ name = "app",
49
+ keystore = "//android/keystores:debug",
50
+ manifest = "src/main/AndroidManifest.xml",
51
+ package_type = "debug",
52
+ deps = [
53
+ ":app-code",
54
+ ],
55
+ )