@domir/react-native-measure-text 0.1.8 → 0.1.10

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.
@@ -1,29 +1,44 @@
1
1
  apply plugin: 'com.android.library'
2
- apply plugin: 'kotlin-android'
2
+
3
+ // Expo's Gradle helpers. This has to run after `com.android.library` and outside the
4
+ // `buildscript {}` block (which Gradle evaluates before line 1): since Expo SDK 50 the
5
+ // helper tries to apply `kotlin-android` itself, and applying the Kotlin plugin before
6
+ // AGP breaks AGP 9's built-in Kotlin support.
7
+ def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
8
+ if (expoModulesCorePlugin.exists()) {
9
+ apply from: expoModulesCorePlugin
10
+ applyKotlinExpoModulesCorePlugin()
11
+ }
12
+
13
+ // AGP 9 ships built-in Kotlin support and registers the `kotlin` extension
14
+ // itself. Applying the Kotlin plugin on top of it fails configuration with
15
+ // "Cannot add extension with name 'kotlin'". Only apply it when nothing has
16
+ // registered that extension yet.
17
+ if (project.extensions.findByName('kotlin') == null) {
18
+ apply plugin: 'kotlin-android'
19
+ }
20
+
3
21
  apply plugin: 'maven-publish'
4
22
 
5
23
  group = 'expo.modules.measuretext'
6
24
  version = '0.1.0'
7
25
 
8
26
  buildscript {
9
- def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
10
- if (expoModulesCorePlugin.exists()) {
11
- apply from: expoModulesCorePlugin
12
- applyKotlinExpoModulesCorePlugin()
13
- }
14
-
15
27
  // Simple helper that allows the root project to override versions declared by this library.
16
28
  ext.safeExtGet = { prop, fallback ->
17
29
  rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
18
30
  }
19
31
 
20
- // Ensures backward compatibility
32
+ // Kotlin version. Expo's helper (applied above, but only after this block has already
33
+ // run) defines `ext.kotlinVersion` as a closure; a `kotlinVersion` Gradle property
34
+ // (-P or gradle.properties) shows up here as a plain string. Accept both and fall
35
+ // back to the root project's `ext.kotlinVersion`.
21
36
  ext.getKotlinVersion = {
22
- if (ext.has("kotlinVersion")) {
23
- ext.kotlinVersion()
24
- } else {
25
- ext.safeExtGet("kotlinVersion", "1.6.10")
37
+ def kotlinVersion = ext.has("kotlinVersion") ? ext.get("kotlinVersion") : null
38
+ if (kotlinVersion instanceof Closure) {
39
+ kotlinVersion = kotlinVersion()
26
40
  }
41
+ kotlinVersion ?: ext.safeExtGet("kotlinVersion", "1.6.10")
27
42
  }
28
43
 
29
44
  repositories {
@@ -41,7 +41,7 @@ class ReactNativeMeasureTextModule : Module() {
41
41
  val paint = TextPaint(TextPaint.ANTI_ALIAS_FLAG);
42
42
  val fontScale = appContext.reactContext?.resources?.configuration?.fontScale ?: 1.0f;
43
43
  val allowScaledFont = allowFontScaling ?: true;
44
- val usedFontSize = (fontSize ?: 0) * fontScale;
44
+ val usedFontSize = (fontSize ?: 0) * if (allowScaledFont) fontScale else 1.0f;
45
45
  paint.textSize = usedFontSize;
46
46
  val letterSpacingPixels = if (allowScaledFont) PixelUtil.toPixelFromSP(letterSpacing ?: 0f) else PixelUtil.toPixelFromDIP(letterSpacing ?: 0f);
47
47
  val mFontSize = if (allowScaledFont) Math.ceil(PixelUtil.toPixelFromSP(usedFontSize).toDouble()).toInt() else Math.ceil(PixelUtil.toPixelFromDIP(usedFontSize).toDouble()).toInt();
@@ -2,5 +2,7 @@ export declare function measureWidth(text: string, style?: {
2
2
  fontSize?: number;
3
3
  fontFamily?: string;
4
4
  fontWeight?: string;
5
+ letterSpacing?: number;
6
+ allowFontScaling?: boolean;
5
7
  }): number;
6
8
  //# sourceMappingURL=ReactNativeMeasureText.d.ts.map
@@ -1 +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"}
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,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAAC,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAAO,GAC9H,MAAM,CAER"}
@@ -1 +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"]}
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,QAA6H,EAAE;IAE/H,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, letterSpacing?: number, allowFontScaling?: boolean } = {}\n): number {\n return ReactNativeMeasureText.measureWidth(text, style);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domir/react-native-measure-text",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "Measure text width synchronously using JSI",
5
5
  "main": "build/ReactNativeMeasureText.js",
6
6
  "types": "build/ReactNativeMeasureText.d.ts",
Binary file
Binary file
Binary file