@iternio/react-native-auto-play 0.1.4 → 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) {
@@ -41,6 +41,7 @@ class MapTemplate: NSObject, AutoPlayTemplate, AutoPlayHeaderProviding,
41
41
  var onTripStarted: ((_ tripId: String, _ routeId: String) -> Void)?
42
42
  var navigationSession: CPNavigationSession?
43
43
  var navigationAlert: NavigationAlertWrapper?
44
+ var currentTripId: String?
44
45
 
45
46
  var tripSelectorVisible = false
46
47
 
@@ -494,6 +495,7 @@ class MapTemplate: NSObject, AutoPlayTemplate, AutoPlayHeaderProviding,
494
495
  }
495
496
 
496
497
  func hideTripSelector() {
498
+ currentTripId = nil;
497
499
  template.hideTripPreviews()
498
500
 
499
501
  tripSelectorVisible = false
@@ -509,6 +511,13 @@ class MapTemplate: NSObject, AutoPlayTemplate, AutoPlayHeaderProviding,
509
511
  using routeChoice: CPRouteChoice
510
512
  ) {
511
513
  let tripId = trip.id
514
+
515
+ if (currentTripId != nil && currentTripId == tripId) {
516
+ return
517
+ }
518
+
519
+ currentTripId = trip.id
520
+
512
521
  let routeId = routeChoice.id
513
522
  self.onTripSelected?(tripId, routeId)
514
523
 
@@ -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.4",
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",