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

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.
@@ -66,10 +66,6 @@ class MapTemplate(
66
66
  navigationManager.setNavigationManagerCallback(navigationManagerCallback)
67
67
  }
68
68
  }
69
-
70
- config.defaultGuidanceBackgroundColor?.let { nitroColor ->
71
- MapTemplate.cardBackgroundColor = Parser.parseColor(nitroColor)
72
- }
73
69
  }
74
70
 
75
71
  override fun parse(): Template {
@@ -598,11 +598,20 @@ object Parser {
598
598
  val image = result?.get()
599
599
  try {
600
600
  if (image is CloseableBitmap) {
601
- return image.underlyingBitmap.copy(Bitmap.Config.ARGB_8888, false)
601
+ // underlyingBitmap can be null when Fresco decodes to a CloseableBitmap
602
+ // whose backing bitmap has already been recycled or failed to allocate;
603
+ // copy() can also throw (e.g., OOM on very large remote images). Either
604
+ // way we return null so the caller falls back to a placeholder icon.
605
+ return image.underlyingBitmap?.copy(Bitmap.Config.ARGB_8888, false)
602
606
  } else if (image is CloseableXml) {
603
607
  val drawable = image.buildDrawable()
604
608
  return drawable?.toBitmap(width = image.width, height = image.height, Bitmap.Config.ARGB_8888)
605
609
  }
610
+ } catch (_: Exception) {
611
+ // Any decode/copy failure (OOM, recycled bitmap, invalid config, …) should
612
+ // not crash the car app — the image is optional decoration and the caller
613
+ // handles a null return with CarIcon.ALERT.
614
+ return null
606
615
  } finally {
607
616
  image?.close()
608
617
  result?.close()
@@ -90,7 +90,7 @@ class VoiceInputManager {
90
90
 
91
91
  // Activate the session first so inputNode reports the correct hardware format
92
92
  let session = AVAudioSession.sharedInstance()
93
- try session.setCategory(.playAndRecord, mode: .measurement, options: [.mixWithOthers])
93
+ try session.setCategory(.playAndRecord, mode: .measurement, options: [])
94
94
  try session.setActive(true)
95
95
 
96
96
  if let interfaceController {
@@ -0,0 +1,2 @@
1
+ import type { AutoPlay } from './specs/AutoPlay.nitro';
2
+ export declare const HybridAutoPlay: AutoPlay;
@@ -0,0 +1,2 @@
1
+ import { NitroModules } from 'react-native-nitro-modules';
2
+ export const HybridAutoPlay = NitroModules.createHybridObject('AutoPlay');
@@ -0,0 +1,7 @@
1
+ /**
2
+ * A hook to determine if the CarPlay/Android Auto screen is currently focused (visible).
3
+ *
4
+ * @param moduleName The name of the module to listen to.
5
+ * @returns `true` if the screen is focused, `false` otherwise.
6
+ */
7
+ export declare function useIsAutoPlayFocused(moduleName: string): boolean;
@@ -0,0 +1,20 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { HybridAutoPlay } from '..';
3
+ /**
4
+ * A hook to determine if the CarPlay/Android Auto screen is currently focused (visible).
5
+ *
6
+ * @param moduleName The name of the module to listen to.
7
+ * @returns `true` if the screen is focused, `false` otherwise.
8
+ */
9
+ export function useIsAutoPlayFocused(moduleName) {
10
+ const [isFocused, setIsFocused] = useState(false);
11
+ useEffect(() => {
12
+ const remove = HybridAutoPlay.addListenerRenderState(moduleName, (state) => {
13
+ setIsFocused(state === 'didAppear');
14
+ });
15
+ return () => {
16
+ remove();
17
+ };
18
+ }, [moduleName]);
19
+ return isFocused;
20
+ }
@@ -0,0 +1,12 @@
1
+ import type { VoiceInputOptions, VoiceInputResult } from '../types/Voice';
2
+ type StartVoiceInput = {
3
+ (options: VoiceInputOptions & Required<Pick<VoiceInputOptions, 'onChunk'>>): Promise<void>;
4
+ (options?: Omit<VoiceInputOptions, 'onChunk'>): Promise<VoiceInputResult>;
5
+ };
6
+ export declare const HybridVoice: {
7
+ hasVoiceInputPermission: () => boolean;
8
+ requestVoiceInputPermission: () => Promise<boolean>;
9
+ startVoiceInput: StartVoiceInput;
10
+ stopVoiceInput: () => void;
11
+ };
12
+ export {};
@@ -0,0 +1,13 @@
1
+ import { NitroModules } from 'react-native-nitro-modules';
2
+ const _native = NitroModules.createHybridObject('Voice');
3
+ const startVoiceInput = (async (options) => {
4
+ const { onChunk, silenceThresholdMs, maxDurationMs, listeningText, preferSpeechToText } = options ?? {};
5
+ const result = await _native.startVoiceInput(silenceThresholdMs, maxDurationMs, listeningText, preferSpeechToText, onChunk);
6
+ return onChunk !== undefined ? undefined : result;
7
+ });
8
+ export const HybridVoice = {
9
+ hasVoiceInputPermission: () => _native.hasVoiceInputPermission(),
10
+ requestVoiceInputPermission: () => _native.requestVoiceInputPermission(),
11
+ startVoiceInput,
12
+ stopVoiceInput: () => _native.stopVoiceInput(),
13
+ };
@@ -0,0 +1,2 @@
1
+ import type { AutoPlay as NitroAutoPlay } from './specs/AutoPlay.nitro';
2
+ export declare const HybridAutoPlay: NitroAutoPlay;
package/lib/hybrid.js ADDED
@@ -0,0 +1,2 @@
1
+ import { NitroModules } from 'react-native-nitro-modules';
2
+ export const HybridAutoPlay = NitroModules.createHybridObject('AutoPlay');
@@ -0,0 +1,11 @@
1
+ import type { HybridObject } from 'react-native-nitro-modules';
2
+ import type { NitroAutomotivePermissionRequestTemplateConfig } from '../templates/AutomotivePermissionRequestTemplate';
3
+ import type { NitroTemplateConfig } from './AutoPlay.nitro';
4
+ interface AutomotivePermissionRequestTemplateConfig extends NitroTemplateConfig, NitroAutomotivePermissionRequestTemplateConfig {
5
+ }
6
+ export interface AutomotivePermissionRequestTemplate extends HybridObject<{
7
+ android: 'kotlin';
8
+ }> {
9
+ createAutomotivePermissionRequestTemplate(config: AutomotivePermissionRequestTemplateConfig): void;
10
+ }
11
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ import type { HybridObject } from 'react-native-nitro-modules';
2
+ import type { NitroAutomotivePermissionRequestTemplateConfig } from '../templates/AutomotivePermissionRequestTemplate';
3
+ import type { NitroTemplateConfig } from './AutoPlay.nitro';
4
+ interface AutomotivePermissionRequestTemplateConfig extends NitroTemplateConfig, NitroAutomotivePermissionRequestTemplateConfig {
5
+ }
6
+ export interface AutomotivePermissionRequestTemplate extends HybridObject<{
7
+ android: 'kotlin';
8
+ }> {
9
+ createAutomotivePermissionRequestTemplate(config: AutomotivePermissionRequestTemplateConfig): void;
10
+ }
11
+ export {};
@@ -0,0 +1,51 @@
1
+ import type { HybridObject } from 'react-native-nitro-modules';
2
+ import type { VoiceInputChunk, VoiceInputResult } from '../types/Voice';
3
+ export interface Voice extends HybridObject<{
4
+ android: 'kotlin';
5
+ ios: 'swift';
6
+ }> {
7
+ /**
8
+ * Returns true if all permissions required for voice input are granted.
9
+ * On iOS: checks both microphone and speech recognition authorization.
10
+ * On Android: checks RECORD_AUDIO permission.
11
+ */
12
+ hasVoiceInputPermission(): boolean;
13
+ /**
14
+ * Request all permissions required for voice input.
15
+ * On iOS: requests microphone permission then speech recognition authorization.
16
+ * On Android: requests RECORD_AUDIO via car context when connected, otherwise
17
+ * via the React Native application context.
18
+ * Returns true only if all required permissions were granted.
19
+ */
20
+ requestVoiceInputPermission(): Promise<boolean>;
21
+ /**
22
+ * Start an in-app voice session.
23
+ *
24
+ * When preferSpeechToText is true:
25
+ * iOS — streams audio buffers into SFSpeechRecognizer during recording;
26
+ * onChunk fires with partial transcription results; resolves with
27
+ * { transcription } or falls back to { audio } if unavailable.
28
+ * Android — checks SpeechRecognizer availability upfront; if available it
29
+ * owns the mic and streams partial results via onChunk; if not
30
+ * available falls back to PCM recording.
31
+ *
32
+ * When preferSpeechToText is false (default):
33
+ * Both platforms record raw PCM; onChunk fires with audio chunks;
34
+ * resolves with { audio }.
35
+ *
36
+ * @param silenceThresholdMs ms of silence before auto-stop (default 1500)
37
+ * @param maxDurationMs hard cap on recording duration (default 10000)
38
+ * @param listeningText iOS only — text shown on CPVoiceControlTemplate
39
+ * @param preferSpeechToText request STT transcription instead of raw PCM
40
+ * @param onChunk optional streaming callback; when set the
41
+ * promise resolves with an empty VoiceInputResult
42
+ */
43
+ startVoiceInput(silenceThresholdMs?: number, maxDurationMs?: number, listeningText?: string, preferSpeechToText?: boolean, onChunk?: (chunk: VoiceInputChunk) => void): Promise<VoiceInputResult>;
44
+ /**
45
+ * Stop the active voice session early.
46
+ * For PCM mode: resolves startVoiceInput with audio captured so far.
47
+ * For STT mode: finalises the recognition request.
48
+ * No-op if no session is active.
49
+ */
50
+ stopVoiceInput(): void;
51
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ import type { CustomActionButtonAndroid } from '../types/Button';
2
+ import type { AutoText } from '../types/Text';
3
+ import { type NitroAction } from '../utils/NitroAction';
4
+ import { type HeaderActions, Template, type TemplateConfig } from './Template';
5
+ export interface NitroAutomotivePermissionRequestTemplateConfig extends TemplateConfig {
6
+ headerActions?: Array<NitroAction>;
7
+ title: AutoText;
8
+ actions: Array<NitroAction>;
9
+ }
10
+ export type AutomotivePermissionRequestTemplateConfig = Omit<NitroAutomotivePermissionRequestTemplateConfig, 'headerActions' | 'buttons'> & {
11
+ /**
12
+ * action buttons, usually at the the top right on Android and a top bar on iOS
13
+ */
14
+ headerActions?: HeaderActions<AutomotivePermissionRequestTemplate>;
15
+ actions: [CustomActionButtonAndroid<AutomotivePermissionRequestTemplate>] | [
16
+ CustomActionButtonAndroid<AutomotivePermissionRequestTemplate>,
17
+ CustomActionButtonAndroid<AutomotivePermissionRequestTemplate>
18
+ ];
19
+ };
20
+ export declare class AutomotivePermissionRequestTemplate extends Template<AutomotivePermissionRequestTemplateConfig, HeaderActions<AutomotivePermissionRequestTemplate>> {
21
+ private template;
22
+ constructor(config: AutomotivePermissionRequestTemplateConfig);
23
+ }
@@ -0,0 +1,18 @@
1
+ import { NitroModules } from 'react-native-nitro-modules';
2
+ import { NitroActionUtil } from '../utils/NitroAction';
3
+ import { Template, } from './Template';
4
+ const HybridAutomotivePermissionRequestTemplate = NitroModules.createHybridObject('AutomotivePermissionRequestTemplate');
5
+ export class AutomotivePermissionRequestTemplate extends Template {
6
+ template = this;
7
+ constructor(config) {
8
+ super(config);
9
+ const { headerActions, actions, ...rest } = config;
10
+ const nitroConfig = {
11
+ ...rest,
12
+ id: this.id,
13
+ headerActions: NitroActionUtil.convert(this.template, headerActions),
14
+ actions: NitroActionUtil.convert(this.template, actions),
15
+ };
16
+ HybridAutomotivePermissionRequestTemplate.createAutomotivePermissionRequestTemplate(nitroConfig);
17
+ }
18
+ }
@@ -96,7 +96,10 @@ export type MapTemplateConfig = Omit<NitroMapTemplateConfig, 'mapButtons' | 'hea
96
96
  */
97
97
  onAutoDriveEnabled?: (template: MapTemplate) => void;
98
98
  /**
99
- * Initial navigation maneuver background color. Mainly useful, when in CarPlay the default loading maneuver does not have the right color.
99
+ * Use this to set the default maneuver background color on iOS.
100
+ * Only used when starting navigation and not providing any maneuvers yet,
101
+ * visible on the system provided loading maneuver then.
102
+ * @namespace iOS
100
103
  */
101
104
  defaultGuidanceBackgroundColor?: ThemedColor | string;
102
105
  };
@@ -0,0 +1,15 @@
1
+ export interface VoiceInputChunk {
2
+ partial?: string;
3
+ audio?: ArrayBuffer;
4
+ }
5
+ export interface VoiceInputResult {
6
+ transcription?: string;
7
+ audio?: ArrayBuffer;
8
+ }
9
+ export interface VoiceInputOptions {
10
+ silenceThresholdMs?: number;
11
+ maxDurationMs?: number;
12
+ listeningText?: string;
13
+ preferSpeechToText?: boolean;
14
+ onChunk?: (chunk: VoiceInputChunk) => void;
15
+ }
@@ -0,0 +1 @@
1
+ export {};
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.14",
4
4
  "description": "Android Auto and Apple CarPlay for react-native",
5
5
  "main": "lib/index",
6
6
  "module": "lib/index",
@@ -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
  };