@iternio/react-native-auto-play 0.1.5 → 0.1.6

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.
@@ -0,0 +1,18 @@
1
+ //
2
+ // NitroLinkingManager.h
3
+ // Pods
4
+ //
5
+ // Created by Manuel Auer on 11.12.25.
6
+ //
7
+
8
+ #import <Foundation/Foundation.h>
9
+
10
+ @interface NitroLinkingManager : NSObject
11
+
12
+ @property (nonatomic, strong) NSURL *launchURL;
13
+
14
+ + (instancetype)shared;
15
+ - (void)continueUserActivity:(NSUserActivity *)userActivity;
16
+ - (void)openURL:(UIOpenURLContext *)urlContext;
17
+
18
+ @end
@@ -0,0 +1,44 @@
1
+ //
2
+ // NitroLinkingManager.m
3
+ // Pods
4
+ //
5
+ // Created by Manuel Auer on 11.12.25.
6
+ //
7
+
8
+ #import "NitroLinkingManager.h"
9
+ #import "React/RCTLinkingManager.h"
10
+
11
+ @implementation NitroLinkingManager
12
+
13
+ + (instancetype)shared {
14
+ static NitroLinkingManager *sharedInstance = nil;
15
+ static dispatch_once_t onceToken;
16
+ dispatch_once(&onceToken, ^{
17
+ sharedInstance = [[self alloc] init];
18
+ });
19
+ return sharedInstance;
20
+ }
21
+
22
+ - (void)continueUserActivity:(NSUserActivity *)userActivity {
23
+ [RCTLinkingManager application:UIApplication.sharedApplication
24
+ continueUserActivity:userActivity
25
+ restorationHandler:^(NSArray *_Nullable _){
26
+ }];
27
+ }
28
+
29
+ - (void)openURL:(UIOpenURLContext *)urlContext {
30
+ NSURL *url = urlContext.URL;
31
+ NSDictionary<UIApplicationOpenURLOptionsKey, id> *options = @{
32
+ UIApplicationOpenURLOptionsSourceApplicationKey :
33
+ urlContext.options.sourceApplication
34
+ ?: @"",
35
+ UIApplicationOpenURLOptionsAnnotationKey : urlContext.options.annotation
36
+ ?: @""
37
+ };
38
+
39
+ [RCTLinkingManager application:UIApplication.sharedApplication
40
+ openURL:url
41
+ options:options];
42
+ }
43
+
44
+ @end
@@ -0,0 +1,39 @@
1
+ //
2
+ // RCTLinkingManager+Custom.mm
3
+ // Pods
4
+ // this overrides the original RCTLinkingManager getInitialURL to provide the url the app was started with from a scene delegate
5
+ //
6
+ // Created by Manuel Auer on 11.12.25.
7
+ //
8
+
9
+ #import "NitroLinkingManager.h"
10
+ #import <React/RCTLinkingManager.h>
11
+ #import <React/RCTBridge.h>
12
+ #import <React/RCTUtils.h>
13
+
14
+ @implementation RCTLinkingManager (Custom)
15
+
16
+ RCT_EXPORT_METHOD(getInitialURL:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
17
+ {
18
+ NSURL *initialURL = [NitroLinkingManager shared].launchURL;
19
+
20
+ if (initialURL) {
21
+ resolve(RCTNullIfNil(initialURL.absoluteString));
22
+ return;
23
+ }
24
+
25
+ // Fallback to the original implementation
26
+ if (self.bridge.launchOptions[UIApplicationLaunchOptionsURLKey]) {
27
+ initialURL = self.bridge.launchOptions[UIApplicationLaunchOptionsURLKey];
28
+ } else {
29
+ NSDictionary *userActivityDictionary =
30
+ self.bridge.launchOptions[UIApplicationLaunchOptionsUserActivityDictionaryKey];
31
+ if ([userActivityDictionary[UIApplicationLaunchOptionsUserActivityTypeKey] isEqual:NSUserActivityTypeBrowsingWeb]) {
32
+ initialURL = ((NSUserActivity *)userActivityDictionary[@"UIApplicationLaunchOptionsUserActivityKey"]).webpageURL;
33
+ }
34
+ }
35
+
36
+ resolve(RCTNullIfNil(initialURL.absoluteString));
37
+ }
38
+
39
+ @end
@@ -30,6 +30,36 @@ class WindowApplicationSceneDelegate: UIResponder, UIWindowSceneDelegate {
30
30
  window.makeKeyAndVisible()
31
31
 
32
32
  self.window = window
33
+
34
+ if let url = connectionOptions.urlContexts.first?.url {
35
+ // Linking API -> on app start
36
+ NitroLinkingManager.shared().launchURL = url
37
+ }
38
+
39
+ if let userActivity = connectionOptions.userActivities.first(where: {
40
+ userActivity in
41
+ userActivity.webpageURL != nil
42
+ }) {
43
+ // Universal Links -> on app start
44
+ NitroLinkingManager.shared().launchURL = userActivity.webpageURL
45
+ }
46
+ }
47
+
48
+ func scene(
49
+ _ scene: UIScene,
50
+ openURLContexts URLContexts: Set<UIOpenURLContext>
51
+ ) {
52
+ // Linking API -> app already running
53
+ guard let urlContext = URLContexts.first else { return }
54
+ NitroLinkingManager.shared().openURL(urlContext)
55
+ }
56
+
57
+ func scene(
58
+ _ scene: UIScene,
59
+ continue userActivity: NSUserActivity
60
+ ) {
61
+ // Universal Links -> app already running
62
+ NitroLinkingManager.shared().continue(userActivity)
33
63
  }
34
64
 
35
65
  func sceneDidBecomeActive(_ scene: UIScene) {
@@ -464,7 +464,7 @@ class MapTemplate: NSObject, AutoPlayTemplate, AutoPlayHeaderProviding,
464
464
  let selectedTrip = selectedTripId.flatMap { tripId in
465
465
  tripPreviews.first(where: { $0.id == tripId })
466
466
  }
467
-
467
+
468
468
  template.showTripPreviews(
469
469
  tripPreviews,
470
470
  selectedTrip: selectedTrip,
@@ -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,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');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iternio/react-native-auto-play",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Android Auto and Apple CarPlay for react-native",
5
5
  "main": "lib/index",
6
6
  "module": "lib/index",
@@ -1,8 +0,0 @@
1
- import type { HybridObject } from 'react-native-nitro-modules';
2
- import type { CleanupCallback } from '../types/Event';
3
- export interface VoiceInput extends HybridObject<{
4
- android: 'kotlin';
5
- ios: 'swift';
6
- }> {
7
- registerVoiceInputListener(callback: (voiceInputResult?: string, error?: string) => void): CleanupCallback;
8
- }
@@ -1 +0,0 @@
1
- export {};