@iternio/react-native-auto-play 0.3.12 → 0.3.13

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 (33) hide show
  1. package/README.md +43 -1
  2. package/ReactNativeAutoPlay.podspec +0 -4
  3. package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/template/MapTemplate.kt +0 -4
  4. package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/template/Parser.kt +10 -1
  5. package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/utils/SymbolFont.kt +29 -30
  6. package/ios/utils/SymbolFont.swift +44 -44
  7. package/ios/utils/VoiceInputManager.swift +1 -1
  8. package/lib/index.d.ts +1 -0
  9. package/lib/index.js +1 -0
  10. package/lib/templates/MapTemplate.d.ts +4 -1
  11. package/lib/types/Image.d.ts +33 -4
  12. package/lib/types/Maneuver.d.ts +2 -10
  13. package/lib/utils/NitroImage.d.ts +23 -2
  14. package/lib/utils/NitroImage.js +57 -3
  15. package/nitrogen/generated/android/c++/JGlyphImage.hpp +6 -1
  16. package/nitrogen/generated/android/c++/JNitroImage.hpp +1 -1
  17. package/nitrogen/generated/android/c++/JVariant_GlyphImage_AssetImage_RemoteImage.hpp +1 -1
  18. package/nitrogen/generated/android/c++/JVariant_PreferredImageLane_ImageLane.hpp +1 -1
  19. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/GlyphImage.kt +5 -2
  20. package/nitrogen/generated/ios/c++/HybridCarPlayDashboardSpecSwift.hpp +1 -1
  21. package/nitrogen/generated/ios/swift/GlyphImage.swift +7 -2
  22. package/nitrogen/generated/shared/c++/GlyphImage.hpp +6 -1
  23. package/package.json +2 -3
  24. package/src/index.ts +1 -0
  25. package/src/templates/MapTemplate.ts +4 -1
  26. package/src/types/Image.ts +53 -18
  27. package/src/types/Maneuver.ts +3 -10
  28. package/src/utils/NitroImage.ts +66 -5
  29. package/android/src/main/res/font/materialsymbolsoutlined_regular.ttf +0 -0
  30. package/ios/Assets/MaterialSymbolsOutlined-Regular.ttf +0 -0
  31. package/lib/types/Glyphmap.d.ts +0 -4105
  32. package/lib/types/Glyphmap.js +0 -4105
  33. package/src/types/Glyphmap.ts +0 -4107
@@ -15,11 +15,11 @@
15
15
  #include "RemoteImage.hpp"
16
16
  #include <variant>
17
17
  #include "JGlyphImage.hpp"
18
+ #include <string>
18
19
  #include "NitroColor.hpp"
19
20
  #include "JNitroColor.hpp"
20
21
  #include <optional>
21
22
  #include "JAssetImage.hpp"
22
- #include <string>
23
23
  #include "JRemoteImage.hpp"
24
24
 
25
25
  namespace margelo::nitro::swe::iternio::reactnativeautoplay {
@@ -19,11 +19,11 @@
19
19
  #include "RemoteImage.hpp"
20
20
  #include "JNitroImage.hpp"
21
21
  #include "JGlyphImage.hpp"
22
+ #include <string>
22
23
  #include "NitroColor.hpp"
23
24
  #include "JNitroColor.hpp"
24
25
  #include <optional>
25
26
  #include "JAssetImage.hpp"
26
- #include <string>
27
27
  #include "JRemoteImage.hpp"
28
28
  #include <vector>
29
29
  #include "JImageLane.hpp"
@@ -22,6 +22,9 @@ data class GlyphImage(
22
22
  val glyph: Double,
23
23
  @DoNotStrip
24
24
  @Keep
25
+ val fontName: String,
26
+ @DoNotStrip
27
+ @Keep
25
28
  val color: NitroColor,
26
29
  @DoNotStrip
27
30
  @Keep
@@ -40,8 +43,8 @@ data class GlyphImage(
40
43
  @Keep
41
44
  @Suppress("unused")
42
45
  @JvmStatic
43
- private fun fromCpp(glyph: Double, color: NitroColor, backgroundColor: NitroColor, fontScale: Double?): GlyphImage {
44
- return GlyphImage(glyph, color, backgroundColor, fontScale)
46
+ private fun fromCpp(glyph: Double, fontName: String, color: NitroColor, backgroundColor: NitroColor, fontScale: Double?): GlyphImage {
47
+ return GlyphImage(glyph, fontName, color, backgroundColor, fontScale)
45
48
  }
46
49
  }
47
50
  }
@@ -36,9 +36,9 @@ namespace margelo::nitro::swe::iternio::reactnativeautoplay { enum class ColorSc
36
36
  #include "AssetImage.hpp"
37
37
  #include "RemoteImage.hpp"
38
38
  #include <variant>
39
+ #include <string>
39
40
  #include "NitroColor.hpp"
40
41
  #include <optional>
41
- #include <string>
42
42
  #include "ColorScheme.hpp"
43
43
 
44
44
  #include "ReactNativeAutoPlay-Swift-Cxx-Umbrella.hpp"
@@ -18,8 +18,8 @@ public extension GlyphImage {
18
18
  /**
19
19
  * Create a new instance of `GlyphImage`.
20
20
  */
21
- init(glyph: Double, color: NitroColor, backgroundColor: NitroColor, fontScale: Double?) {
22
- self.init(glyph, color, backgroundColor, { () -> bridge.std__optional_double_ in
21
+ init(glyph: Double, fontName: String, color: NitroColor, backgroundColor: NitroColor, fontScale: Double?) {
22
+ self.init(glyph, std.string(fontName), color, backgroundColor, { () -> bridge.std__optional_double_ in
23
23
  if let __unwrappedValue = fontScale {
24
24
  return bridge.create_std__optional_double_(__unwrappedValue)
25
25
  } else {
@@ -33,6 +33,11 @@ public extension GlyphImage {
33
33
  return self.__glyph
34
34
  }
35
35
 
36
+ @inline(__always)
37
+ var fontName: String {
38
+ return String(self.__fontName)
39
+ }
40
+
36
41
  @inline(__always)
37
42
  var color: NitroColor {
38
43
  return self.__color
@@ -31,6 +31,7 @@
31
31
  // Forward declaration of `NitroColor` to properly resolve imports.
32
32
  namespace margelo::nitro::swe::iternio::reactnativeautoplay { struct NitroColor; }
33
33
 
34
+ #include <string>
34
35
  #include "NitroColor.hpp"
35
36
  #include <optional>
36
37
 
@@ -42,13 +43,14 @@ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
42
43
  struct GlyphImage final {
43
44
  public:
44
45
  double glyph SWIFT_PRIVATE;
46
+ std::string fontName SWIFT_PRIVATE;
45
47
  NitroColor color SWIFT_PRIVATE;
46
48
  NitroColor backgroundColor SWIFT_PRIVATE;
47
49
  std::optional<double> fontScale SWIFT_PRIVATE;
48
50
 
49
51
  public:
50
52
  GlyphImage() = default;
51
- explicit GlyphImage(double glyph, NitroColor color, NitroColor backgroundColor, std::optional<double> fontScale): glyph(glyph), color(color), backgroundColor(backgroundColor), fontScale(fontScale) {}
53
+ explicit GlyphImage(double glyph, std::string fontName, NitroColor color, NitroColor backgroundColor, std::optional<double> fontScale): glyph(glyph), fontName(fontName), color(color), backgroundColor(backgroundColor), fontScale(fontScale) {}
52
54
 
53
55
  public:
54
56
  friend bool operator==(const GlyphImage& lhs, const GlyphImage& rhs) = default;
@@ -65,6 +67,7 @@ namespace margelo::nitro {
65
67
  jsi::Object obj = arg.asObject(runtime);
66
68
  return margelo::nitro::swe::iternio::reactnativeautoplay::GlyphImage(
67
69
  JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "glyph"))),
70
+ JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "fontName"))),
68
71
  JSIConverter<margelo::nitro::swe::iternio::reactnativeautoplay::NitroColor>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "color"))),
69
72
  JSIConverter<margelo::nitro::swe::iternio::reactnativeautoplay::NitroColor>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "backgroundColor"))),
70
73
  JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "fontScale")))
@@ -73,6 +76,7 @@ namespace margelo::nitro {
73
76
  static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::swe::iternio::reactnativeautoplay::GlyphImage& arg) {
74
77
  jsi::Object obj(runtime);
75
78
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "glyph"), JSIConverter<double>::toJSI(runtime, arg.glyph));
79
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "fontName"), JSIConverter<std::string>::toJSI(runtime, arg.fontName));
76
80
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "color"), JSIConverter<margelo::nitro::swe::iternio::reactnativeautoplay::NitroColor>::toJSI(runtime, arg.color));
77
81
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "backgroundColor"), JSIConverter<margelo::nitro::swe::iternio::reactnativeautoplay::NitroColor>::toJSI(runtime, arg.backgroundColor));
78
82
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "fontScale"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.fontScale));
@@ -87,6 +91,7 @@ namespace margelo::nitro {
87
91
  return false;
88
92
  }
89
93
  if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "glyph")))) return false;
94
+ if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "fontName")))) return false;
90
95
  if (!JSIConverter<margelo::nitro::swe::iternio::reactnativeautoplay::NitroColor>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "color")))) return false;
91
96
  if (!JSIConverter<margelo::nitro::swe::iternio::reactnativeautoplay::NitroColor>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "backgroundColor")))) return false;
92
97
  if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "fontScale")))) return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iternio/react-native-auto-play",
3
- "version": "0.3.12",
3
+ "version": "0.3.13",
4
4
  "description": "Android Auto and Apple CarPlay for react-native",
5
5
  "main": "lib/index",
6
6
  "module": "lib/index",
@@ -34,9 +34,8 @@
34
34
  "lint": "biome check src",
35
35
  "lint-ci": "biome ci src --reporter=summary",
36
36
  "typescript": "tsc",
37
- "generate:fonts": "node ./assets/symbolFont/bundleAsset.js",
38
37
  "specs": "nitrogen --logLevel=\"debug\"",
39
- "prepare": "yarn circular && tsc && nitrogen && npm run generate:fonts",
38
+ "prepare": "yarn circular && tsc && nitrogen",
40
39
  "swift:format": "swift-format format ./ios --in-place --recursive",
41
40
  "circular": "dpdm ./src/* --circular --exit-code circular:1 --no-tree --warning=false --transform"
42
41
  },
package/src/index.ts CHANGED
@@ -62,3 +62,4 @@ export type {
62
62
  } from './utils/NitroAlert';
63
63
  export type { ThemedColor } from './utils/NitroColor';
64
64
  export type { GridButton } from './utils/NitroGrid';
65
+ export { setIconFont } from './utils/NitroImage';
@@ -159,7 +159,10 @@ export type MapTemplateConfig = Omit<
159
159
  onAutoDriveEnabled?: (template: MapTemplate) => void;
160
160
 
161
161
  /**
162
- * Initial navigation maneuver background color. Mainly useful, when in CarPlay the default loading maneuver does not have the right color.
162
+ * Use this to set the default maneuver background color on iOS.
163
+ * Only used when starting navigation and not providing any maneuvers yet,
164
+ * visible on the system provided loading maneuver then.
165
+ * @namespace iOS
163
166
  */
164
167
  defaultGuidanceBackgroundColor?: ThemedColor | string;
165
168
  };
@@ -1,26 +1,61 @@
1
1
  import type { ImageSourcePropType } from 'react-native';
2
2
  import type { ThemedColor } from '../utils/NitroColor';
3
- import type { GlyphName } from './Glyphmap';
4
3
 
5
- export type AutoImage =
6
- | {
7
- name: GlyphName;
4
+ /**
5
+ * Augment this interface in your app to get type-safe glyph name autocompletion.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * // autoplay-glyphs.d.ts
10
+ * import type { GlyphName } from './assets/symbolFont/Glyphmap';
11
+ * declare module '@iternio/react-native-auto-play' {
12
+ * interface AutoPlayGlyphMap extends Record<GlyphName, number> {}
13
+ * }
14
+ * ```
15
+ */
16
+ // biome-ignore lint/suspicious/noEmptyInterface: must be an interface for declaration merging
17
+ export interface AutoPlayGlyphMap {}
8
18
 
9
- /**
10
- * Sets the icon dark and light mode color or a single color for both.
11
- * Defaults to white for dark mode and black for light mode if not specified.
12
- * Might not get applied everywhere like MapTemplate buttons on Android.
13
- */
14
- color?: ThemedColor | string;
19
+ /** Resolves to the augmented glyph name union, or falls back to `string` when not augmented. */
20
+ export type GlyphMapKey = keyof AutoPlayGlyphMap extends never
21
+ ? string
22
+ : Extract<keyof AutoPlayGlyphMap, string>;
15
23
 
16
- /**
17
- * Sets the background color for dark and light mode or a single color for both
18
- * Defaults to transparent if not specified.
19
- */
20
- backgroundColor?: ThemedColor | string;
21
- fontScale?: number;
22
- type: 'glyph';
23
- }
24
+ type GlyphStyleFields = {
25
+ /**
26
+ * Sets the icon dark and light mode color or a single color for both.
27
+ * Defaults to white for dark mode and black for light mode if not specified.
28
+ * Might not get applied everywhere like MapTemplate buttons on Android.
29
+ */
30
+ color?: ThemedColor | string;
31
+
32
+ /**
33
+ * Sets the background color for dark and light mode or a single color for both
34
+ * Defaults to transparent if not specified.
35
+ */
36
+ backgroundColor?: ThemedColor | string;
37
+ fontScale?: number;
38
+ };
39
+
40
+ /** Glyph by name — looked up in the glyph map registered via {@link setIconFont}. */
41
+ export type AutoGlyphByName = GlyphStyleFields & {
42
+ type: 'glyph';
43
+ /** Key in the glyph map passed to `setIconFont`. */
44
+ name: GlyphMapKey;
45
+ /** Optional override — if set, used instead of the map lookup. */
46
+ codepoint?: number;
47
+ };
48
+
49
+ /** Glyph by raw Unicode code point. */
50
+ export type AutoGlyphByCodepoint = GlyphStyleFields & {
51
+ type: 'glyph';
52
+ codepoint: number;
53
+ };
54
+
55
+ export type AutoGlyph = AutoGlyphByName | AutoGlyphByCodepoint;
56
+
57
+ export type AutoImage =
58
+ | AutoGlyph
24
59
  | {
25
60
  image: ImageSourcePropType;
26
61
  /**
@@ -1,6 +1,6 @@
1
1
  import type { ImageSourcePropType } from 'react-native';
2
2
  import type { ThemedColor } from '../utils/NitroColor';
3
- import type { GlyphName } from './Glyphmap';
3
+ import type { AutoGlyphByCodepoint, AutoGlyphByName } from './Image';
4
4
  import type { TravelEstimates } from './Trip';
5
5
 
6
6
  export enum ManeuverType {
@@ -174,15 +174,8 @@ export interface PreferredLane extends Lane {
174
174
  }
175
175
 
176
176
  export type ManeuverImage =
177
- | {
178
- name: GlyphName;
179
- /**
180
- * make sure to specify a color with a proper contrast ratio to cardBackgroundColor otherwise it might not get applied
181
- * defaults to white/black for dark/light mode
182
- */
183
- color?: ThemedColor | string;
184
- type: 'glyph';
185
- }
177
+ | Pick<AutoGlyphByName, 'type' | 'name' | 'codepoint' | 'color'>
178
+ | Pick<AutoGlyphByCodepoint, 'type' | 'codepoint' | 'color'>
186
179
  | {
187
180
  image: ImageSourcePropType;
188
181
  /**
@@ -1,8 +1,69 @@
1
1
  import { Image, type ImageResolvedAssetSource } from 'react-native';
2
- import { glyphMap } from '../types/Glyphmap';
3
2
  import type { AutoImage } from '../types/Image';
4
3
  import { type NitroColor, NitroColorUtil } from './NitroColor';
5
4
 
5
+ let _iconFont: string | undefined;
6
+ let _glyphMap: Record<string, number> | undefined;
7
+
8
+ /**
9
+ * Register the icon font and (optionally) a glyph map for name-based lookups.
10
+ * Must be called **once** before creating any templates. Subsequent calls are ignored.
11
+ *
12
+ * The font name maps directly to a native font asset:
13
+ * - **Android** — `res/font/<name>.ttf` (must be lowercase)
14
+ * - **iOS** — `<name>.ttf` in the app bundle (registered via CoreText automatically)
15
+ *
16
+ * For cross-platform compatibility use lowercase with underscores only.
17
+ *
18
+ * @param name Native font asset name (without extension).
19
+ * @param glyphMap Optional map of glyph names to Unicode code points.
20
+ * When provided, glyphs can use `{ type: 'glyph', name: 'icon_name' }`.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * import { glyphMap } from './assets/Glyphmap';
25
+ * setIconFont('material_symbols', glyphMap);
26
+ * ```
27
+ */
28
+ export function setIconFont(name: string, glyphMap?: Record<string, number>): void {
29
+ if (_iconFont != null) {
30
+ return;
31
+ }
32
+ _iconFont = name;
33
+ _glyphMap = glyphMap;
34
+ }
35
+
36
+ function getIconFont(): string {
37
+ if (_iconFont == null) {
38
+ throw new Error(
39
+ 'No icon font configured. Call setIconFont("your_font_name") before using glyph images.'
40
+ );
41
+ }
42
+ return _iconFont;
43
+ }
44
+
45
+ function resolveGlyph(image: Extract<AutoImage, { type: 'glyph' }>): number {
46
+ if ('name' in image && image.name !== undefined) {
47
+ if (image.codepoint !== undefined) {
48
+ return image.codepoint;
49
+ }
50
+ if (_glyphMap == null) {
51
+ throw new Error(
52
+ `Glyph name "${image.name}" used but no glyph map was provided to setIconFont().`
53
+ );
54
+ }
55
+ const cp = _glyphMap[image.name];
56
+ if (cp === undefined) {
57
+ throw new Error(`Glyph name "${image.name}" not found in the glyph map.`);
58
+ }
59
+ return cp;
60
+ }
61
+ if (image.codepoint !== undefined) {
62
+ return image.codepoint;
63
+ }
64
+ throw new Error('Glyph image must provide either `name` or `codepoint`.');
65
+ }
66
+
6
67
  interface AssetImage extends ImageResolvedAssetSource {
7
68
  color?: NitroColor;
8
69
  packager_asset: boolean;
@@ -10,6 +71,7 @@ interface AssetImage extends ImageResolvedAssetSource {
10
71
 
11
72
  interface GlyphImage {
12
73
  glyph: number;
74
+ fontName: string;
13
75
  color: NitroColor;
14
76
  backgroundColor: NitroColor;
15
77
  fontScale?: number;
@@ -22,8 +84,7 @@ interface RemoteImage {
22
84
  }
23
85
 
24
86
  /**
25
- * we need to map the ButtonImage.name from GlyphName to
26
- * the actual numeric value so we need a nitro specific type
87
+ * NitroModules-compatible image types passed to native.
27
88
  */
28
89
  export type NitroImage = GlyphImage | AssetImage | RemoteImage;
29
90
 
@@ -38,12 +99,12 @@ function convert(image?: AutoImage): NitroImage | undefined {
38
99
  const {
39
100
  color = { darkColor: 'white', lightColor: 'black' },
40
101
  fontScale,
41
- name,
42
102
  backgroundColor = 'transparent',
43
103
  } = image;
44
104
 
45
105
  return {
46
- glyph: glyphMap[name],
106
+ glyph: resolveGlyph(image),
107
+ fontName: getIconFont(),
47
108
  color: NitroColorUtil.convert(color),
48
109
  backgroundColor: NitroColorUtil.convert(backgroundColor),
49
110
  fontScale,