@react-navigation/native 8.0.0-alpha.16 → 8.0.0-alpha.17
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/android/src/main/java/org/reactnavigation/MaterialSymbolModule.kt +20 -9
- package/android/src/main/java/org/reactnavigation/MaterialSymbolTypeface.kt +2 -1
- package/lib/module/native/MaterialSymbol.android.js +1 -9
- package/lib/module/native/MaterialSymbol.android.js.map +1 -1
- package/lib/typescript/src/native/MaterialSymbol.android.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/native/MaterialSymbol.android.tsx +1 -14
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
package org.reactnavigation
|
|
2
2
|
|
|
3
|
+
import android.net.Uri
|
|
3
4
|
import android.graphics.Bitmap
|
|
4
5
|
import android.graphics.Canvas
|
|
5
6
|
import android.graphics.Paint
|
|
@@ -15,6 +16,7 @@ import kotlinx.coroutines.SupervisorJob
|
|
|
15
16
|
import kotlinx.coroutines.launch
|
|
16
17
|
import java.io.File
|
|
17
18
|
import java.io.FileOutputStream
|
|
19
|
+
import java.util.concurrent.ConcurrentHashMap
|
|
18
20
|
import kotlin.math.roundToInt
|
|
19
21
|
|
|
20
22
|
class MaterialSymbolModule(reactContext: ReactApplicationContext) :
|
|
@@ -24,6 +26,7 @@ class MaterialSymbolModule(reactContext: ReactApplicationContext) :
|
|
|
24
26
|
const val NAME = NativeMaterialSymbolModuleSpec.NAME
|
|
25
27
|
|
|
26
28
|
private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
|
|
29
|
+
private val cleanedCacheDirs = ConcurrentHashMap.newKeySet<String>()
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
private val fontHash: String by lazy {
|
|
@@ -42,8 +45,9 @@ class MaterialSymbolModule(reactContext: ReactApplicationContext) :
|
|
|
42
45
|
}
|
|
43
46
|
}
|
|
44
47
|
|
|
45
|
-
val resolvedColor = ColorPropConverter.getColor(
|
|
46
|
-
|
|
48
|
+
val resolvedColor = ColorPropConverter.getColor(
|
|
49
|
+
colorValue, currentActivity ?: reactApplicationContext
|
|
50
|
+
) ?: throw IllegalArgumentException("Could not resolve color")
|
|
47
51
|
|
|
48
52
|
val density = reactApplicationContext.resources.displayMetrics.density
|
|
49
53
|
val scaledSize = (size * density).roundToInt().coerceAtLeast(1)
|
|
@@ -57,16 +61,23 @@ class MaterialSymbolModule(reactContext: ReactApplicationContext) :
|
|
|
57
61
|
"react_navigation/material_symbols/$typefaceSuffix/$fontHash"
|
|
58
62
|
)
|
|
59
63
|
|
|
60
|
-
val
|
|
61
|
-
|
|
64
|
+
val cacheFile = File(
|
|
65
|
+
cacheDir, "${Uri.encode(name)}_${scaledSize}_$resolvedColor.png"
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
val cacheUri = cacheFile.toUri().toString()
|
|
62
69
|
|
|
63
70
|
if (cacheFile.exists()) {
|
|
64
|
-
return
|
|
71
|
+
return cacheUri
|
|
65
72
|
}
|
|
66
73
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
74
|
+
val cacheParent = cacheDir.parentFile
|
|
75
|
+
|
|
76
|
+
if (cacheParent != null && cleanedCacheDirs.add(cacheParent.absolutePath)) {
|
|
77
|
+
scope.launch {
|
|
78
|
+
cacheParent.listFiles { it.isDirectory && it.name != fontHash }
|
|
79
|
+
?.forEach { it.deleteRecursively() }
|
|
80
|
+
}
|
|
70
81
|
}
|
|
71
82
|
|
|
72
83
|
cacheDir.mkdirs()
|
|
@@ -95,6 +106,6 @@ class MaterialSymbolModule(reactContext: ReactApplicationContext) :
|
|
|
95
106
|
bitmap.recycle()
|
|
96
107
|
}
|
|
97
108
|
|
|
98
|
-
return
|
|
109
|
+
return cacheUri
|
|
99
110
|
}
|
|
100
111
|
}
|
|
@@ -2,11 +2,12 @@ package org.reactnavigation
|
|
|
2
2
|
|
|
3
3
|
import android.content.Context
|
|
4
4
|
import android.graphics.Typeface
|
|
5
|
+
import java.util.concurrent.ConcurrentHashMap
|
|
5
6
|
|
|
6
7
|
data class MaterialSymbolTypefaceResult(val typeface: Typeface, val suffix: String)
|
|
7
8
|
|
|
8
9
|
object MaterialSymbolTypeface {
|
|
9
|
-
private val typefaces =
|
|
10
|
+
private val typefaces = ConcurrentHashMap<String, Typeface>()
|
|
10
11
|
private var availableFonts: Map<String, Set<Int>>? = null
|
|
11
12
|
|
|
12
13
|
fun get(context: Context, variant: String?, weight: Int?): MaterialSymbolTypefaceResult {
|
|
@@ -5,7 +5,6 @@ import { FONT_WEIGHTS } from "./constants.js";
|
|
|
5
5
|
import MaterialSymbolViewNativeComponent from './MaterialSymbolViewNativeComponent';
|
|
6
6
|
import NativeMaterialSymbolModule from "./NativeMaterialSymbolModule.js";
|
|
7
7
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
-
const imageSourceCache = new Map();
|
|
9
8
|
export function MaterialSymbol({
|
|
10
9
|
name,
|
|
11
10
|
weight,
|
|
@@ -37,22 +36,15 @@ MaterialSymbol.getImageSource = ({
|
|
|
37
36
|
if (processedColor == null) {
|
|
38
37
|
throw new Error(`Invalid color value: ${String(color)}`);
|
|
39
38
|
}
|
|
40
|
-
const scale = PixelRatio.get();
|
|
41
|
-
const cacheKey = `${name}:${variant}:${weight}:${size}:${scale}:${JSON.stringify(processedColor)}`;
|
|
42
|
-
const cached = imageSourceCache.get(cacheKey);
|
|
43
|
-
if (cached !== undefined) {
|
|
44
|
-
return cached;
|
|
45
|
-
}
|
|
46
39
|
const uri = NativeMaterialSymbolModule.getImageSource(name, variant, typeof weight === 'string' ? FONT_WEIGHTS[weight] : weight, size, {
|
|
47
40
|
value: processedColor
|
|
48
41
|
});
|
|
49
42
|
const source = {
|
|
50
43
|
uri,
|
|
51
|
-
scale,
|
|
44
|
+
scale: PixelRatio.get(),
|
|
52
45
|
width: size,
|
|
53
46
|
height: size
|
|
54
47
|
};
|
|
55
|
-
imageSourceCache.set(cacheKey, source);
|
|
56
48
|
return source;
|
|
57
49
|
};
|
|
58
50
|
//# sourceMappingURL=MaterialSymbol.android.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["PixelRatio","processColor","FONT_WEIGHTS","MaterialSymbolViewNativeComponent","NativeMaterialSymbolModule","jsx","_jsx","
|
|
1
|
+
{"version":3,"names":["PixelRatio","processColor","FONT_WEIGHTS","MaterialSymbolViewNativeComponent","NativeMaterialSymbolModule","jsx","_jsx","MaterialSymbol","name","weight","size","color","style","rest","width","height","getImageSource","variant","processedColor","Error","String","uri","value","source","scale","get"],"sourceRoot":"../../../src","sources":["native/MaterialSymbol.android.tsx"],"mappings":";;AAAA,SAEEA,UAAU,EACVC,YAAY,QAEP,cAAc;AAErB,SAASC,YAAY,QAAQ,gBAAa;AAC1C,OAAOC,iCAAiC,MAAM,qCAAqC;AACnF,OAAOC,0BAA0B,MAAM,iCAA8B;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAKtE,OAAO,SAASC,cAAcA,CAAC;EAC7BC,IAAI;EACJC,MAAM;EACNC,IAAI,GAAG,EAAE;EACTC,KAAK;EACLC,KAAK;EACL,GAAGC;AACgB,CAAC,EAAsB;EAC1C,oBACEP,IAAA,CAACH,iCAAiC;IAChCK,IAAI,EAAEA,IAAK;IACXC,MAAM,EAAE,OAAOA,MAAM,KAAK,QAAQ,GAAGP,YAAY,CAACO,MAAM,CAAC,GAAIA,MAAM,IAAI,CAAG;IAC1EC,IAAI,EAAEA,IAAK;IACXC,KAAK,EAAEA,KAAM;IACbC,KAAK,EAAE,CACL;MACEE,KAAK,EAAEJ,IAAI;MACXK,MAAM,EAAEL;IACV,CAAC,EACDE,KAAK,CACL;IAAA,GACEC;EAAI,CACT,CAAC;AAEN;AAEAN,cAAc,CAACS,cAAc,GAAG,CAAC;EAC/BR,IAAI;EACJS,OAAO;EACPR,MAAM;EACNC,IAAI,GAAG,EAAE;EACTC,KAAK,GAAG;AACa,CAAC,KAA0B;EAChD,MAAMO,cAAc,GAAGjB,YAAY,CAACU,KAAK,CAAC;EAE1C,IAAIO,cAAc,IAAI,IAAI,EAAE;IAC1B,MAAM,IAAIC,KAAK,CAAC,wBAAwBC,MAAM,CAACT,KAAK,CAAC,EAAE,CAAC;EAC1D;EAEA,MAAMU,GAAG,GAAGjB,0BAA0B,CAACY,cAAc,CACnDR,IAAI,EACJS,OAAO,EACP,OAAOR,MAAM,KAAK,QAAQ,GAAGP,YAAY,CAACO,MAAM,CAAC,GAAGA,MAAM,EAC1DC,IAAI,EACJ;IAAEY,KAAK,EAAEJ;EAAe,CAC1B,CAAC;EAED,MAAMK,MAA2B,GAAG;IAClCF,GAAG;IACHG,KAAK,EAAExB,UAAU,CAACyB,GAAG,CAAC,CAAC;IACvBX,KAAK,EAAEJ,IAAI;IACXK,MAAM,EAAEL;EACV,CAAC;EAED,OAAOa,MAAM;AACf,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MaterialSymbol.android.d.ts","sourceRoot":"","sources":["../../../../src/native/MaterialSymbol.android.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,mBAAmB,EAGxB,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AAKtB,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAErD,MAAM,MAAM,mBAAmB,GAAG,qBAAqB,GAAG,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"MaterialSymbol.android.d.ts","sourceRoot":"","sources":["../../../../src/native/MaterialSymbol.android.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,mBAAmB,EAGxB,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AAKtB,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAErD,MAAM,MAAM,mBAAmB,GAAG,qBAAqB,GAAG,SAAS,CAAC;AAEpE,wBAAgB,cAAc,CAAC,EAC7B,IAAI,EACJ,MAAM,EACN,IAAS,EACT,KAAK,EACL,KAAK,EACL,GAAG,IAAI,EACR,EAAE,mBAAmB,GAAG,KAAK,CAAC,YAAY,CAiB1C;yBAxBe,cAAc;kEAgC3B,qBAAqB,KAAG,mBAAmB"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-navigation/native",
|
|
3
3
|
"description": "React Native integration for React Navigation",
|
|
4
|
-
"version": "8.0.0-alpha.
|
|
4
|
+
"version": "8.0.0-alpha.17",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-native",
|
|
7
7
|
"react-navigation",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"clean": "del lib"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@react-navigation/core": "^8.0.0-alpha.
|
|
60
|
+
"@react-navigation/core": "^8.0.0-alpha.9",
|
|
61
61
|
"escape-string-regexp": "^4.0.0",
|
|
62
62
|
"fast-deep-equal": "^3.1.3",
|
|
63
63
|
"nanoid": "^3.3.11",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"react-native": "0.83.2",
|
|
76
76
|
"react-native-builder-bob": "^0.40.12",
|
|
77
77
|
"react-test-renderer": "19.2.0",
|
|
78
|
-
"typescript": "^
|
|
78
|
+
"typescript": "^6.0.2"
|
|
79
79
|
},
|
|
80
80
|
"peerDependencies": {
|
|
81
81
|
"react": ">= 19.2.0",
|
|
@@ -121,5 +121,5 @@
|
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
},
|
|
124
|
-
"gitHead": "
|
|
124
|
+
"gitHead": "2e3c1f2571a3fdfcb47245e963633cd34a42ccff"
|
|
125
125
|
}
|
|
@@ -12,8 +12,6 @@ import type { MaterialSymbolOptions } from './types';
|
|
|
12
12
|
|
|
13
13
|
export type MaterialSymbolProps = MaterialSymbolOptions & ViewProps;
|
|
14
14
|
|
|
15
|
-
const imageSourceCache = new Map<string, ImageSourcePropType>();
|
|
16
|
-
|
|
17
15
|
export function MaterialSymbol({
|
|
18
16
|
name,
|
|
19
17
|
weight,
|
|
@@ -53,15 +51,6 @@ MaterialSymbol.getImageSource = ({
|
|
|
53
51
|
throw new Error(`Invalid color value: ${String(color)}`);
|
|
54
52
|
}
|
|
55
53
|
|
|
56
|
-
const scale = PixelRatio.get();
|
|
57
|
-
|
|
58
|
-
const cacheKey = `${name}:${variant}:${weight}:${size}:${scale}:${JSON.stringify(processedColor)}`;
|
|
59
|
-
const cached = imageSourceCache.get(cacheKey);
|
|
60
|
-
|
|
61
|
-
if (cached !== undefined) {
|
|
62
|
-
return cached;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
54
|
const uri = NativeMaterialSymbolModule.getImageSource(
|
|
66
55
|
name,
|
|
67
56
|
variant,
|
|
@@ -72,12 +61,10 @@ MaterialSymbol.getImageSource = ({
|
|
|
72
61
|
|
|
73
62
|
const source: ImageSourcePropType = {
|
|
74
63
|
uri,
|
|
75
|
-
scale,
|
|
64
|
+
scale: PixelRatio.get(),
|
|
76
65
|
width: size,
|
|
77
66
|
height: size,
|
|
78
67
|
};
|
|
79
68
|
|
|
80
|
-
imageSourceCache.set(cacheKey, source);
|
|
81
|
-
|
|
82
69
|
return source;
|
|
83
70
|
};
|